Skip to content

Introduce "browsingContext.setUserAgent" command #602

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
text: shared worker; url: workers.html#shared-workers
text: system visibility state; url: document-sequences.html#system-visibility-state
text: traversable navigable; url:document-sequences.html#traversable-navigable
text: visible; url: document-sequences.html#system-visibility-state
text: traverse the history by a delta; url: browsing-the-web.html#traverse-the-history-by-a-delta
text: user agent; url: system-state.html#dom-navigator-useragent
text: visible; url: document-sequences.html#system-visibility-state
text: window open steps; url: window-object.html#window-open-steps
text: worker event loop; url: webappapis.html#worker-event-loop-2
text: worklet global scopes; url:worklets.html#concept-document-worklet-global-scopes
Expand Down Expand Up @@ -1922,6 +1923,7 @@ BrowsingContextCommand = (
browsingContext.Navigate //
browsingContext.Print //
browsingContext.Reload //
browsingContext.SetUserAgent //
browsingContext.SetViewport //
browsingContext.TraverseHistory
)
Expand Down Expand Up @@ -3448,6 +3450,58 @@ The [=remote end steps=] with |command parameters| are:

</div>

#### The browsingContext.setUserAgent Command #### {#command-browsingContext-setUserAgent}

The <dfn export for=commands>browsingContext.setUserAgent</dfn> command sets the
{{NavigatorID/userAgent}} string for a browsing context.

<dl>
<dt>Command Type</dt>
<dd>
<pre class="cddl remote-cddl">
browsingContext.SetUserAgent = (
method: "browsingContext.setUserAgent",
params: browsingContext.SetUserAgentParameters
)

browsingContext.SetUserAgentParameters = {
context: browsingContext.BrowsingContext,
userAgent: text / null,
}
</pre>
</dd>
<dt>Result Type</dt>
<dd>
<pre class="cddl">
EmptyResult
</pre>
</dd>
</dl>

<div algorithm="remote end steps for browsingContext.setUserAgent">

The [=remote end steps=] with |command parameters| are:

1. Let |context id| be the value of the <code>context</code> field of |command
parameters|.

1. Let |context| be the result of [=trying=] to [=get a browsing context=] with
|context id|.

1. Let |user agent| be the value of the <code>userAgent</code> field of |command
parameters| if present, or null otherwise.

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?


1. Otherwise, set |context|'s {{NavigatorID/userAgent}} to the
implementation-defined [=default `user-agent` value=].

1. Return [=success=] with data null.

</div>

#### The browsingContext.setViewport Command #### {#command-browsingContext-setViewport}

The <dfn export for=commands>browsingContext.setViewport</dfn> command specific viewport characteristics (e.g. viewport width and viewport height) on the given top-level browsing context.
Expand Down