Bug 265575 - Web Inspector: When there is a UA override on Safari, choosing a UA override in Develop Menu is not working
Summary: Web Inspector: When there is a UA override on Safari, choosing a UA override ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: Safari 17
Hardware: All All
: P2 Normal
Assignee: Abrar Rahman Protyasha
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-11-30 05:50 PST by Karl Dubost
Modified: 2024-01-12 17:49 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Dubost 2023-11-30 05:50:24 PST
0. With STP 183
1. Go to a website with a UA override created for webcompat reason (the list is currently in Safari, Bug 263619 will make this list public at a point).
2. check the navigator.userAgent in the console. You should get the UA which has been forced
3. Choose Develop Menu -> User Agent and change it to a different UA
4. check the navigator.userAgent in the console.

Result:
The User Agent has not changed. It didn't overrule the UA override from Safari. 

Do the same thing after disabling Site Specific Hacks, and this is working.
Disabling Site Specific Hacks, in addition to disable the quirks, will also disable the UA overrides.
Comment 1 Radar WebKit Bug Importer 2023-11-30 05:50:32 PST
<rdar://problem/118981832>
Comment 2 Abrar Rahman Protyasha 2024-01-11 02:42:44 PST
Ah, I see what's happening here.

In `FrameLoader::userAgent()`, after we assign the UA string to a site-specific quirk, we don't consult the `WebLocalFrameLoaderClient` for the UA string anymore. Notice the `userAgent.isEmpty()` check, which is false if we have a site-specific quirk:

```
    // From FrameLoader::userAgent()
    if (userAgent.isEmpty())
        userAgent = m_client->userAgent(url);
```

`WebLocalFrameLoaderClient::userAgent` gives us the UA string set on the web page, which happens to be either the default UA string or a custom UA string (such as the UA override from Safari's develop menu).

So, it seems like we need to jiggle around our logic in `FrameLoader::userAgent()`, but I don't think we have enough fidelity to tell when we should be consulting the site-specific quirk and when we should instead be consulting `WebLocalFrameLoader::userAgent` because it will tell us a custom UA string set using the `WKPageSetCustomUserAgent` API (again, such as the UA override from Safari's develop menu).
Comment 3 Abrar Rahman Protyasha 2024-01-11 20:45:11 PST
Pull request: https://github.com/WebKit/WebKit/pull/22694
Comment 4 EWS 2024-01-12 17:49:35 PST
Committed 273001@main (65e9ef262a03): <https://commits.webkit.org/273001@main>

Reviewed commits have been landed. Closing PR #22694 and removing active labels.