Closed Bug 814379 Opened 9 years ago Closed 8 years ago

Firefox 17 + User agent switcher. The JS "navigator.userAgent" property is broken (it never changes)

Categories

(Core :: DOM: Core & HTML, defect)

17 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla23

People

(Reporter: paulo.f.oliveira, Assigned: mitchell.mebane)

References

Details

(Keywords: regression)

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.14 Safari/537.17

Steps to reproduce:

After an upgrade to Firefox 17.0 (on Ubuntu)
I used the extension "User agent switcher" to change the user agent.


Actual results:

- The user agent reported to the webserver has changed.
- The JS "navigator.userAgent" property was NOT changed.


Expected results:

Both the user agent reported to the webserver and the JS "navigator.userAgent" property should have changed to the new user agent.

I tried with other extensions and none of them can change the  JS "navigator.userAgent" property

In Firefox 16 this worked without problems
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 787798
>In Firefox 16 this worked without problems
In that case it's not a dupe, sorry
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: DUPLICATE → ---
Same for me.
In the web app I am working on, we provide an extension that changes the "general.useragent.override" preference to set it to various mobile devices user agent strings.
When doing so, we get the same results:
- The user agent reported to the webserver has changed.
- The JS "navigator.userAgent" property was NOT changed.
It worked fine with FF16 and started to fail with FF17.
It still fails with FF18.
I just saw that this bug was only targeting the x86_64 linux platform.
On my side, I also get it on Windows.
This happens also on MacOSX.
After restarting the browser, the correct value is returned by (both) navigator.userAgent (and the HTTP header).
After modify preference "general.useragent.override"(some extension just provide a GUI to modify this). The http request header send to server is changed, but not the javascript object "navigator.userAgent", latter need to restart Firefox.

Firefox 20 on Window/Linux both have this problem. 

But inserting, when enable "general.useragent.site_specific_overrides", then add "general.useragent.override.google.com", both http header and "navigator.userAgent" changed immediately, no need to restart.
Component: Untriaged → DOM
Product: Firefox → Core
Possibly a regression from bug 800157.
Blocks: 800157
Keywords: regression
OS: Linux → All
Hardware: x86_64 → All
qawanted to confirm, bug 800157 sounds like it already fixed this
Keywords: qawanted
Some testing results

* 17.0b1 - working immediately after setting pref
* 17.0b2 - working only after restart
* 19.0.2 - working only after restart
* 20.0.1 - working only after restart
* 21.0b6 - working only after restart
* 22.0a2 20130503 - working immediately after setting pref

Tested by setting general.useragent.override, then opening the Web Console and typing navigator.useragent.

I guess User Agent Switcher will be broken until FF 22, because it resets general.useragent.override to default on restart.
Actually, I can't reproduce the Aurora 22 results.  Maybe I accidentally restarted the browser earlier during testing.

* 22.0a2 20130503 and 20130506  - working only after restart
Attached patch patch (obsolete) — Splinter Review
I managed to get Firefox building, and did some bisecting.  Looks like this is the breaking change:

http://hg.mozilla.org/mozilla-central/rev/9f28c28e988f

Looks like when navigator.userAgent is requested, and there is no site-specific override, the global UA is used.  However, this is stored in a const field, so it is never update.

I'm not familiar with Mercurial or the Firefox codebase, but the issue seemed simple enough, so I took a stab at a patch.  It fixes the issue for me.  Hopefully the formatting, etc. is at least halfway right.  :)
Comment on attachment 747404 [details] [diff] [review]
patch

Thanks Mitchell!
Attachment #747404 - Flags: review?(dao)
Comment on attachment 747404 [details] [diff] [review]
patch

>-const DEFAULT_UA = Cc["@mozilla.org/network/protocol;1?name=http"]
>-                     .getService(Ci.nsIHttpProtocolHandler)
>-                     .userAgent;
>+const HTTP_PROTO_HANDLER = Cc["@mozilla.org/network/protocol;1?name=http"]
>+                     .getService(Ci.nsIHttpProtocolHandler);

The last line should be indented with another eight spaces. r=me with that fixed. Thanks!
Attachment #747404 - Flags: review?(dao) → review+
Assignee: nobody → mitchell.mebane
Keywords: qawanted
Added 8 more spaces.

Is there a style guide for indentation when splitting over multiple lines?  I looked around a bit but didn't see anything.
Attachment #747404 - Attachment is obsolete: true
Attachment #747497 - Flags: review?(dao)
Attachment #747497 - Flags: review?(dao) → review+
(In reply to Mitchell Mebane from comment #14)
> Created attachment 747497 [details] [diff] [review]
> patch r2: fixed spacing
> 
> Added 8 more spaces.
> 
> Is there a style guide for indentation when splitting over multiple lines?

Not that I know of...
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/da4ef4dc056b
Status: REOPENED → RESOLVED
Closed: 9 years ago8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
While waiting for a fix... as a hack/workaround... I used an HTTPObserver to set a site specific override for every domain visited by the user (and used an event listener to clear up the resulting mess after the page is unloaded).

Its not nice, but it works.

observerService.addObserver(myHTTPObserver, "http-on-modify-request", false);

And in the observer code;

var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
prefsGUAP.setCharPref("override." + httpChannel.URI.host, myUserAgent );

Later in the page unload event listener;

prefsGUAP.deleteBranch("override.");

Looking forward to FF23, nice work Mitchell.
Blocks: 861470
Duplicate of this bug: 787798
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.