JavaScript: `navigator.userAgent' returns the Firefox default User-Agent, instead of what is given in the `User-Agent'-HTTP-Header.

RESOLVED DUPLICATE of bug 814379

Status

()

RESOLVED DUPLICATE of bug 814379
6 years ago
3 years ago

People

(Reporter: kimabrandt, Unassigned)

Tracking

15 Branch
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
User Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20100101 Firefox/15.0
Build ID: 20120824154833

Steps to reproduce:

I am using an addon to set a user-defined value for the `User-Agent'-HTTP-Header, which is sent to the server.


Actual results:

When a page is loaded and in JavaScript the `navigator.userAgent'-property is called, the Firefox default User-Agent is returned instead.


Expected results:

I was expecting the `navigator.userAgent'-property to return the same value as was sent to the server with the `User-Agent'-HTTP-Header.

Maybe this can be changed, but maybe there is a good reason - which I am not aware of - why this should not be changed!?

Updated

6 years ago
Status: UNCONFIRMED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 526209
Duplicate of this bug: 814379
This is a regression, this works in 10ESR
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: DUPLICATE → ---
Däo: 
Could this be a regression from your recent UA (override) changes ?
The changed UA is only applied after a restart but I failed to find a regression range with mozregression. That looks like this happens only with release builds or that I did something wrong.
(In reply to Matthias Versen (Matti) from comment #4)
> Däo: 
> Could this be a regression from your recent UA (override) changes ?

Possibly bug 800157, but then it doesn't make sense that this bug was reported with Firefox 15.
(In reply to Dão Gottwald [:dao] from comment #5)
 
> Possibly bug 800157, but then it doesn't make sense that this bug was
> reported with Firefox 15.

It seems i screwed up with the duping of bug 814379.
Should this issue be duped to 800157? 
@Dão Gottwald [:dao] : can you advise on this matter?
Flags: needinfo?(dao)
Component: Untriaged → DOM
Product: Firefox → Core
Status: REOPENED → RESOLVED
Last Resolved: 6 years ago3 years ago
Flags: needinfo?(dao)
Resolution: --- → DUPLICATE
Duplicate of bug: 814379
(Reporter)

Comment 9

3 years ago
Sorry to do this, but I'd like to reopen this bug :/ I'm not reopening it myself, since I'm not sure anymore it's really a bug!?

I should have explained exactly what my add-on is doing...

My add-on does not set the `general.useragent.override'-preference - as in bug 814379 - but sets HTTP request-headers (i.e. `User-Agent') by calling the `setRequestHeader'[1]-method on a HTTP channel. What I'm not sure about is: should a HTTP channel have an effect on the JavaScript `navigator.userAgent'-property, once a Web-page is loaded!?

Is there a better/proper way - beside any workarounds[2] - to do what I'm trying to archive?

[1] setRequestHeader() - https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIHttpChannel#setRequestHeader%28%29
[2] Pete's workaround - https://bugzilla.mozilla.org/show_bug.cgi?id=814379#c18
Apologies for pinging you again Dao. Kim's question clearly exceeds my UA knowledge at the moment.
Flags: needinfo?(dao)
(In reply to Kim A. Brandt from comment #9)
> Sorry to do this, but I'd like to reopen this bug :/ I'm not reopening it
> myself, since I'm not sure anymore it's really a bug!?
> 
> I should have explained exactly what my add-on is doing...
> 
> My add-on does not set the `general.useragent.override'-preference - as in
> bug 814379 - but sets HTTP request-headers (i.e. `User-Agent') by calling
> the `setRequestHeader'[1]-method on a HTTP channel. What I'm not sure about
> is: should a HTTP channel have an effect on the JavaScript
> `navigator.userAgent'-property, once a Web-page is loaded!?

No.

> Is there a better/proper way - beside any workarounds[2] - to do what I'm
> trying to archive?

What are you trying to achieve? Why are you not using general.useragent.override?
> [1] setRequestHeader() -
> https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/
> Interface/nsIHttpChannel#setRequestHeader%28%29
> [2] Pete's workaround -
> https://bugzilla.mozilla.org/show_bug.cgi?id=814379#c18
Flags: needinfo?(dao)
(Reporter)

Comment 12

3 years ago
(In reply to Dão Gottwald [:dao] from comment #11)
> ...
> > Is there a better/proper way - beside any workarounds[2] - to do what I'm
> > trying to archive?
> 
> What are you trying to achieve? Why are you not using
> general.useragent.override?
> ...

With my add-on I can set HTTP-headers for a single request; using regular-expressions in order to match an URL. This allows me to set headers for certain requests only. I would like to be able to set the `User-Agent'-header in this way, without having to set/override it globally (sets User-Agent for all requests).

Does this make sense, or am I the only one with such an use-case?
You should use UserAgentOverrides.jsm for that. See for instance the patch in bug 788422 or this code: http://hg.mozilla.org/mozilla-central/annotate/6fa2ab99f52f/mobile/android/chrome/content/browser.js#l3269
(Reporter)

Comment 14

3 years ago
(In reply to Dão Gottwald [:dao] from comment #13)
> You should use UserAgentOverrides.jsm for that. See for instance the patch
> ...

OK. I will use that. Thank you for the links.
You need to log in before you can comment on or make changes to this bug.