Page MenuHomePhabricator

Bug 2052932 - [webdriver-bidi] `emulation.setLocaleOverride` does not override `Accept-Language` header for in `Worker` for `fetch` and `WebSocket`
ClosedPublic

Authored by dcrousso on Jul 6 2026, 6:14 PM.
Referenced Files
Unknown Object (File)
Fri, Nov 13, 9:55 AM
Unknown Object (File)
Oct 10 2026, 4:13 AM
Unknown Object (File)
Oct 1 2026, 7:34 PM
Unknown Object (File)
Sep 28 2026, 11:32 AM
Unknown Object (File)
Sep 10 2026, 5:05 AM
Unknown Object (File)
Aug 31 2026, 8:58 PM
Unknown Object (File)
Aug 23 2026, 3:02 AM
Unknown Object (File)
Aug 18 2026, 5:37 AM

Details

Summary

Bug 1995691 made emulation.setLocaleOverride override the Accept-Language request header, but only for document-initiated requests.
Bug 2015655 made the locale override apply to the JS realm and navigator.language in Worker and SharedWorker but it did not touch the Accept-Language header or WebSocket path.

HttpBaseChannel::Init already applies the override centrally (via AddStandardRequestHeaders) from the loading BrowsingContext's locale override, but Worker requests have no loading BrowsingContext so it never fired for them. Init now falls back to the associated BrowsingContext when the loading one is null.

For that fallback to work, the associated BrowsingContext has to be on the LoadInfo before the channel runs Init:

  • fetch() now threads the associated BrowsingContext id through channel creation so it is set while the LoadInfo is constructed, instead of afterwards once the channel (and its request headers) already exist.
  • The WebSocket handshake now reuses the WebSocket's own LoadInfo (which already carries the association) via a new nsIIOService::newChannelFromURIWithProxyFlagsAndLoadInfo, rather than synthesizing a fresh LoadInfo that dropped it.

Leaning on the central path lets both manual Accept-Language SetRequestHeader blocks go away, and also covers Worker XMLHttpRequest for free.

Diff Detail

Event Timeline

phab-bot published this revision for review.Jul 6 2026, 6:14 PM
phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.
kershaw requested changes to this revision.Jul 7 2026, 9:13 AM
kershaw added a subscriber: kershaw.

Could we lean on the existing path here instead of setting Accept-Language by hand in two more places? We already apply the override in HttpBaseChannel::Init via AddStandardRequestHeaders, reading mLoadInfo->GetBrowsingContext()->Top()->GetLanguageOverride(). It just does not fire for workers because their loadInfo has no loading BrowsingContext.

Two small changes should cover this centrally:

  • In HttpBaseChannel::Init, fall back to GetAssociatedBrowsingContext() when GetBrowsingContext() is null.
  • Set AssociatedBrowsingContextID when constructing worker loadInfo, before the channel is created. Right now FetchDriver sets it at line 666, after NS_NewChannel has already run Init, so Init cannot see it. The same applies to the WebSocket handshake channel.

That would let us remove both manual SetRequestHeader("Accept-Language", ...) blocks, while also covering worker XHR and anything else for free.

This revision now requires changes to proceed.Jul 7 2026, 9:13 AM
dcrousso retitled this revision from Bug 1938048 - `emulation.setLocaleOverride` does not override `Accept-Language` header for in `Worker` for `fetch` and `WebSocket` to Bug 2052932 - `emulation.setLocaleOverride` does not override `Accept-Language` header for in `Worker` for `fetch` and `WebSocket`.Jul 7 2026, 3:58 PM
dcrousso changed the Bugzilla Bug ID from 1938048 to 2052932.
dcrousso updated this revision to Diff 1317485.
dcrousso edited the summary of this revision. (Show Details)
whimboo added inline comments.
dom/websocket/WebSocket.cpp
1954

Should we actually silently discard the return value here? If it fails, the locale override won't apply for worker WebSocket connections with no indication of failure. Should MOZ_ALWAYS_SUCCEEDS be used here as well similar to your addition in nsIOService.cpp?

netwerk/base/nsIOService.h
185

The new optional aAssociatedBrowsingContextID parameter is appended after the output parameter result. Is that ok?

testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/locale.py
615

I wonder if we should parameterize the test and as well test the XMLHttpRequest feature.

Also beside the test for a dedicated worker it would be good to test as well for a shared worker and as well a service worker?

Testing the WebSocket path is probably harder and might require a new server-side handler.

jdescottes added inline comments.
testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/locale.py
615

For other worker related tests we consistently check with a "new worker" and with and existing one.

Can we do the same here, or is the implementation not handling already created workers?

jdescottes added a project: testing-approved.
jdescottes edited reviewers, added: whimboo; removed: Sasha.

The tests look good to me, thanks for working on this!
I will keep a review flag for @whimboo so that he can check the updated version as well (but from what I can tell everything looks good on that end as well!)

whimboo added 1 blocking reviewer(s): kershaw.

Looks fine to me, Thanks.

Given that there were some network code related changes with the last update as well, I would like to see that @kershaw is taking a look at this patch again.

This revision is now accepted and ready to land.Jul 13 2026, 8:23 AM
whimboo retitled this revision from Bug 2052932 - `emulation.setLocaleOverride` does not override `Accept-Language` header for in `Worker` for `fetch` and `WebSocket` to Bug 2052932 - [webdriver-bidi] `emulation.setLocaleOverride` does not override `Accept-Language` header for in `Worker` for `fetch` and `WebSocket`.Jul 13 2026, 8:26 PM

When I was trying to edit the revision for the summary I accidentally clicked the AI review link. As I see that the revision hasn't been pushed to Lando yet, lets wait for the review to be finished. Maybe it still find something important - if not I can push to Lando when I'm back tomorrow.

Ok, looks like that I may not have exactly clicked the AI review link. Lets get the patch landed. Thanks!