Bug 188009 - navigator.userAgent may return outdated value after webView.customUserAgent is set
Summary: navigator.userAgent may return outdated value after webView.customUserAgent i...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks: 185952
  Show dependency treegraph
 
Reported: 2018-07-25 10:57 PDT by Chris Dumez
Modified: 2018-07-25 13:33 PDT (History)
7 users (show)

See Also:


Attachments
Patch (16.24 KB, patch)
2018-07-25 11:06 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (16.29 KB, patch)
2018-07-25 12:05 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2018-07-25 10:57:59 PDT
navigator.userAgent may return outdated value after webView.customUserAgent is set, due to its cached not getting invalidated.
Comment 1 Chris Dumez 2018-07-25 10:58:13 PDT
<rdar://problem/42566456>
Comment 2 Chris Dumez 2018-07-25 11:06:03 PDT
Created attachment 345768 [details]
Patch
Comment 3 Geoffrey Garen 2018-07-25 11:44:26 PDT
Comment on attachment 345768 [details]
Patch

Prior to <https://trac.webkit.org/changeset/232159/webkit>, was the UI client able to change navigator.userAgent while the page was live? I'm not sure it's important or desirable to be able to change navigator.userAgent while the page is live. It's specified as a readonly attribute, and a website might do something really weird if feature detection returned different results half-way through webpage rendering.
Comment 4 Chris Dumez 2018-07-25 11:59:58 PDT
(In reply to Geoffrey Garen from comment #3)
> Comment on attachment 345768 [details]
> Patch
> 
> Prior to <https://trac.webkit.org/changeset/232159/webkit>, was the UI
> client able to change navigator.userAgent while the page was live?

Yes, since there was no caching whatsoever.

> I'm not
> sure it's important or desirable to be able to change navigator.userAgent
> while the page is live. It's specified as a readonly attribute, and a
> website might do something really weird if feature detection returned
> different results half-way through webpage rendering.

I am not sure how important this is either but this is a recent behavior change compared to shipping and I have a radar about it. Clearly, the developer who filed the radar see this as a regression.
Comment 5 Chris Dumez 2018-07-25 12:04:48 PDT
(In reply to Chris Dumez from comment #4)
> (In reply to Geoffrey Garen from comment #3)
> > Comment on attachment 345768 [details]
> > Patch
> > 
> > Prior to <https://trac.webkit.org/changeset/232159/webkit>, was the UI
> > client able to change navigator.userAgent while the page was live?
> 
> Yes, since there was no caching whatsoever.
> 
> > I'm not
> > sure it's important or desirable to be able to change navigator.userAgent
> > while the page is live. It's specified as a readonly attribute, and a
> > website might do something really weird if feature detection returned
> > different results half-way through webpage rendering.
> 
> I am not sure how important this is either but this is a recent behavior
> change compared to shipping and I have a radar about it. Clearly, the
> developer who filed the radar see this as a regression.

My first instinct was also not to fix it since I am not convinced there is a great use-case for changing the user agent after the page has loaded. That said, the radar was sent to me so I fixed it. It is not a lot of code and I have already written it, I do not see much harm in landing it.
Comment 6 Chris Dumez 2018-07-25 12:05:55 PDT
Created attachment 345772 [details]
Patch
Comment 7 Chris Dumez 2018-07-25 12:07:10 PDT
(In reply to Chris Dumez from comment #5)
> (In reply to Chris Dumez from comment #4)
> > (In reply to Geoffrey Garen from comment #3)
> > > Comment on attachment 345768 [details]
> > > Patch
> > > 
> > > Prior to <https://trac.webkit.org/changeset/232159/webkit>, was the UI
> > > client able to change navigator.userAgent while the page was live?
> > 
> > Yes, since there was no caching whatsoever.
> > 
> > > I'm not
> > > sure it's important or desirable to be able to change navigator.userAgent
> > > while the page is live. It's specified as a readonly attribute, and a
> > > website might do something really weird if feature detection returned
> > > different results half-way through webpage rendering.
> > 
> > I am not sure how important this is either but this is a recent behavior
> > change compared to shipping and I have a radar about it. Clearly, the
> > developer who filed the radar see this as a regression.
> 
> My first instinct was also not to fix it since I am not convinced there is a
> great use-case for changing the user agent after the page has loaded. That
> said, the radar was sent to me so I fixed it. It is not a lot of code and I
> have already written it, I do not see much harm in landing it.

Note that would also impact changing the user-agent via the Develop menu (navigator.userAgent would not change until reloading).
Comment 8 WebKit Commit Bot 2018-07-25 13:33:24 PDT
Comment on attachment 345772 [details]
Patch

Clearing flags on attachment: 345772

Committed r234211: <https://trac.webkit.org/changeset/234211>
Comment 9 WebKit Commit Bot 2018-07-25 13:33:26 PDT
All reviewed patches have been landed.  Closing bug.