Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce "browsingContext.setUserAgent" command #602

Closed
wants to merge 1 commit into from

Conversation

thiagowfx
Copy link
Member

@thiagowfx thiagowfx commented Nov 14, 2023

Bug: #448


Preview | Diff

@thiagowfx thiagowfx force-pushed the thiagowfx/user-agent branch 3 times, most recently from 07eeb19 to e21aeb1 Compare November 14, 2023 21:15
@thiagowfx thiagowfx marked this pull request as ready for review November 14, 2023 21:15
@thiagowfx thiagowfx changed the title DRAFT: Introduce "browsingContext.setUserAgent" command Introduce "browsingContext.setUserAgent" command Nov 14, 2023
@OrKoN OrKoN removed request for whimboo and jgraham November 15, 2023 09:20
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved

1. If |user agent| is not null:

1. Set |context|'s [=user agent=] to |user agent|.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if that would give use desired side effects? I am not sure that is really per-context because it is listed under "System state and capabilities". Also, the default User Agent value is used in https://fetch.spec.whatwg.org/#default-user-agent-value directly. I am not sure if we can redefine it from the BiDi spec or if we need some hooks into other spec. Perhaps we can use https://w3c.github.io/webdriver-bidi/#patches for that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some experiments and the user agent seems to be individual per context.

For example, given a page with an iframe, changing the userAgent in the iframe does not change it in the top-level context. And vice-versa.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, what do you mean by changing? CDP implementation is per-context but I don't think this spec change would specify that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure what is the AI here. Should I just change the prose to mention fetch?

Or should we restrict it to top-level contexts only?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to restrict to the top-level context.

I am not sure if we can redefine it from the BiDi spec or if we need some hooks into other spec. Perhaps we can use https://w3c.github.io/webdriver-bidi/#patches for that?

I would try to define patches to the Fetch and HTML specs with hooks that would provide the fetch parameters' browsing context and the browser context of the navigator's window.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgraham what do you think of the approach proposed by @OrKoN? Should I look into it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So FWIW it looks like gecko does restrict to the top level context. Obviously that could be changed if there's a use case for it.

I think the patch that would make sense would be to have a UA override defined on a (top-level) navigable. Then when asked to get the user agent in a specific Window you get the corresponding navigable and then (depending on the semantics we want) either go directly to it's top-level traversable and check if that has an override set, or maybe walk the parent tree looking for something with an override set. If there's no override you fall back to the default.

I think that works for requests that are kicked off from navigations or scripts running in a window. I don't know what implementations currently do for scripts running in workers, especially service workers or shared workers which could be associated with > 1 (top-level) navigable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would find it hard to differentiate which override applies to all browsing contexts of a tab or just a specific one when we have more emulation. Maybe we should consider to only set it per top-level browsing context and that the setting bubbles down into frames as well? Here I don't see a reason why a frame should have a different user agent. Do you have an example for such a requirement?

@thiagowfx thiagowfx force-pushed the thiagowfx/user-agent branch from 5a6e8b3 to db7fc48 Compare November 17, 2023 14:25
@thiagowfx
Copy link
Member Author

thiagowfx commented Nov 21, 2023

Example patch: #538

@OrKoN OrKoN marked this pull request as draft November 27, 2023 16:05
@thiagowfx thiagowfx closed this Mar 13, 2024
@thiagowfx thiagowfx deleted the thiagowfx/user-agent branch March 13, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants