-
Notifications
You must be signed in to change notification settings - Fork 367
[WebDriver BiDi] emulate user-agent
string
#1851
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
[WebDriver BiDi] emulate user-agent
string
#1851
Conversation
user-agent
string
Specification for `emulation.setUserAgentOverride` command. * Introduce a new hook "WebDriver BiDi emulated User-Agent". * Fetch spec update required, as the default `User-Agent` headers is set BEFORE the "[WebDriver BiDi before request sent](https://w3c.github.io/webdriver-bidi/#webdriver-bidi-before-request-sent)" is invoked, so there is no way to distinguish between the user explicitly set the `User-Agent` vs the [default `User-Agent` value](https://fetch.spec.whatwg.org/#default-user-agent-value) was used. Use the hook in Fetch spec: whatwg/fetch#1851 * HTML spec update required to return the proper `User-Agent` as the result of the `navigator.userAgent`. Use the hook in HTML spec: whatwg/html#11576
@noamr PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unofficial LGTM
63b1d36
to
042c341
Compare
Support for user-agent emulations.
Co-authored-by: Anne van Kesteren <[email protected]>
# Conflicts: # fetch.bs
29769d0
to
b677da0
Compare
da890bd
to
4076b59
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had these comments, but you just refactored it further. I'm not sure I like removing the default User-Agent value concept entirely. Is that really what we want?
I now also wonder at what point implementations ask WebDriver for this value as it seems unlikely to happen in het network layer, where the User-Agent value is currently appended.
This reverts commit 4076b59.
Co-authored-by: Anne van Kesteren <[email protected]>
Co-authored-by: Anne van Kesteren <[email protected]>
@annevk Ok, I reverted the last change where I merged the "environment default |
So this looks good, but what about the timing of this call? Presumably it happens earlier, but maybe we can decide not to worry about that for now? Hmm. |
@annevk in Chromium, we rely on |
I think that does mean there are some issues with this setup. In that if you hit a couple of redirects and you call that method repeatedly, the User-Agent header would not change in value, but per this specification as written it ought to change. To fix that and some race issues we'd have to grab the current User-Agent header before we go in parallel and use it for the entire duration of the fetch. I'm okay with not doing that for now, but I'm curious what other people think about what level of accuracy we need here. Maybe @jgraham is willing to chime in. |
The WebDriver BiDi "WebDriver BiDi emulated User-Agent" hook returns the emulated user context based on pre-configured emulations per top-level navigable, so it is not expected to be changed during navigations or redirects. Even though the JS environments will be changed, it would not influence the return result. BiDi uses the environment only to associate the request with the navigable. |
I see. So you are you saying it's set before navigation starts and can't be changed after? |
Theoretically the user can change the emulation during navigation, but otherwise it is persistent per top-level navigable. I cannot imagine a real-world automation scenario when the user needs to change emulation during navigation and expect persistent results. |
You can change it in the middle of a fetch, so I think it's true that redirects could see different user agent headers (you could also do the same thing with request interception). In general I don't think people are expected to change this often for existing traversables; the typical use case is "set the user agent when creating a top-level traversable and use it for the entire lifetime of that traversable". So I think I agree that in principle caching the value at the start of a redirect loop is the right thing to do, but in practice it's likely to be a rare edge case. |
Since WebDriver interoperability is quite a bit less crucial than web platform interoperability I'll go ahead and merge this. Let's revamp if people end up hitting this in the wild after all. |
Thanks a lot! |
Corresponding Fetch PR: whatwg/fetch#1851.
Support for user-agent emulations. Required for WebDriver BiDi: https://www.w3.org/TR/webdriver-bidi/#command-emulation-setUserAgentOverride (w3c/webdriver-bidi#448).
Introduce "environment default
User-Agent
value" to reference it from the HTML specification.emulation.setUserAgentOverride
command web-platform-tests/wpt#54810emulation.setUserAgentOverride
GoogleChromeLabs/chromium-bidi#3661(See WHATWG Working Mode: Changes for more details.)
Preview | Diff