Skip to content

emulation.setUserAgentOverride #947

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sadym-chromium
Copy link
Contributor

@sadym-chromium sadym-chromium commented Jul 7, 2025

Initial draft of emulation.setUserAgentOverride command. Requires defining a list of related navigables for the "default User-Agent value" caller.


Preview | Diff

index.bs Outdated
WebDriver-BiDi [=remote end=] must have an implementation that runs the following
steps:

Issue: get |related navigables|.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found 2 usages of the "default User-Agent value":

  1. Set a header for network request.
  2. NavigatorId's "appVersion" and "userAgent".

We need to fins a way to specify what "related navigables" means in those cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we could propose an update to the fetch and html specs? I think there is a way how find related navigable for an HTTP request (like in interception) and for a document, does it work here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think we should attempt creating patches for the HTML and Fetch spec. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference the algorithm we use to map request to navigable is https://www.w3.org/TR/webdriver-bidi/#get-navigable-for-request

To hook from the fetch spec, you can look at the fetch PR at https://whatpr.org/fetch/1540.html#concept-http-fetch (we still haven't landed this so it makes a bit hard to follow the BiDi/fetch integration)

Copy link
Contributor Author

@sadym-chromium sadym-chromium Jul 11, 2025

Choose a reason for hiding this comment

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

I tried another approach

Initial draft of `emulation.setUserAgentOverride` command. Requires defining a list of related navigables for the "default User-Agent value" caller.
@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setUserAgentOverride branch from e22449c to 989153d Compare July 7, 2025 16:04
Comment on lines +6195 to +6212
1. If [=default User-Agent value=] was accessed during execution of the
[=HTTP-network-or-cache fetch=] algorithm with |fetchParams|:

1. Let |request| be |fetchParams|’s [=request=].

1. If |request|'s [=request/client=] is not null, let |related navigables|
be the result of [=get related navigables=] with |request|'s
[=request/client=].

1. If [=default User-Agent value=] was accessed from [=NavigatorID=] interface:

1. Let |realm| be [=current Realm Record=].

1. Let |environment settings| be the [=environment settings object=] whose
[=realm execution context=]'s Realm component is |realm|.

1. Let |related navigables| be the result of [=get related navigables=] given
|environment settings|.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WDYT about this approach? @OrKoN @juliandescottes @jgraham ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@juliandescottes @jgraham WDYT about this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

From a maintenance perspective, I prefer adding hooks in the relevant specs because otherwise the other specs might change and break the relationship with BiDi unintentionally.

From the point of view of someone trying to read and implement the specification, you still need to jump between the two specifications to understand the behavior. Possibly even harder to follow because you need to identify all the spots in the other spec which access [=default User-Agent value=], which sounds painful.

The main added value of this approach is that we don't have to update other specs, but apart from that hooks seem preferable to me. Is there something which makes it more difficult for the NavigatorID case? For fetch we already have pending hooks in whatwg/fetch#1540 so for consistency it also seems better to stick to hooks.

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.

3 participants