Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fbd2160cf1ac822dbc75d1ba82c3d72ee5a814b6
      
https://github.com/WebKit/WebKit/commit/fbd2160cf1ac822dbc75d1ba82c3d72ee5a814b6
  Author: Chris Dumez <[email protected]>
  Date:   2026-06-09 (Tue, 09 Jun 2026)

  Changed paths:
    M 
Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/CustomUserAgent.mm

  Log Message:
  -----------
  SharedWorker's navigator.userAgent ignores per-navigation _customUserAgent
https://bugs.webkit.org/show_bug.cgi?id=316637

Reviewed by Youenn Fablet.

WebSharedWorkerContextManagerConnection::launchSharedWorker() applied an
inverted user-agent fallback:
```
      if (!initializationData.userAgent.isEmpty())
          initializationData.userAgent = m_userAgent;
```

The intent (matching the parallel logic in WebSWContextManagerConnection's
installServiceWorker, which uses `if (effectiveUserAgent.isNull())`) is to
fall back to the host's m_userAgent only when the value supplied by the
network process is empty. The condition was negated, so a non-empty
page-supplied UA was overwritten by the host's default, while an empty UA
was left empty.

The page-level WKWebView.customUserAgent path masks the bug because
WebProcessPool::updateRemoteWorkerUserAgent pushes that UA to every remote-
worker host via Messages::WebSharedWorkerContextManagerConnection::SetUserAgent,
keeping the host's m_userAgent in sync with the page UA so the buggy
assignment becomes a no-op. The bug is observable through any UA path that
does NOT round-trip through WebPageProxy::setUserAgent — most notably
WKWebpagePreferences._customUserAgent (per-navigation), which is stored on
the page's DocumentLoader and flows into WorkerScriptLoader::
userAgentForSharedWorker() but never updates the host process. In that
configuration the SharedWorker's navigator.userAgent reported the host's
standard UA instead of the per-navigation override.

Invert the condition so initializationData.userAgent is preserved when
non-empty and only filled in from m_userAgent when empty.

* Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp:
(WebKit::WebSharedWorkerContextManagerConnection::launchSharedWorker):
Fall back to m_userAgent only when initializationData.userAgent is empty.

* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/CustomUserAgent.mm:
(TEST(CustomUserAgent, SharedWorkerNavigatorUserAgent)):
Add a regression test that uses WKWebpagePreferences._customUserAgent so
the page UA diverges from the host's m_userAgent, and asserts that a
SharedWorker created from that page observes the per-navigation UA via
navigator.userAgent.

Canonical link: https://commits.webkit.org/314858@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to