Closed Bug 1511281 Opened 11 months ago Closed 10 months ago

GeckoView `User-Agent` API is not respected for all HTTP requests (only root-level document's)

Categories

(Core :: Networking, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla66
Tracking Status
firefox66 --- fixed

People

(Reporter: cvan, Assigned: rbarker)

References

(Blocks 1 open bug, )

Details

(Whiteboard: [webxr] [webvr][necko-triaged])

Attachments

(1 file)

Background:
Bug 1454444 added a GeckoView API to change the User-Agent.
Bug 1484391 added an option for a "Mobile VR" UA.
Bug 1507369 allows the ability to set a custom UA.

1. From an Oculus Go VR headset, open Firefox Reality (v1.1).
2. Enable Remote Debugging in Firefox Reality: `Settings > Developer Options > Enable Remote Debuging` (in the tray menu at the bottom of the chrome UI)
4. Launch any web page, for example: https://webxr.sh/
5. From desktop Firefox, launch the WebIDE to inspect the Network traffic: `Tools > Web Developer > WebIDE > USB Devices > Firefox Custom on Android (Pacific) > Tabs > webxr.sh`
6. When the Developer Tools opens for the active tab, click the `Network` tab.
7. From the `Network` tab, click on the main document, and scroll to the bottom to see the list of `Request Headers`.
8. Notice the main document has `User-Agent: Mozilla/5.0 (Android 7.1.2; Mobile VR; rv:65.0) Gecko/65.0 Firefox/65.0`.
9. From the `Network` tab, click on a different network request (such as `style.css`), and notice the UA is GeckoView's default: `User-Agent: Mozilla/5.0 (Android 7.1.2; Mobile; rv:65.0) Gecko/65.0 Firefox/65.0`

Current result:
GeckoView sets the custom `User-Agent` HTTP request header for only the root document's.

Expected result:
GeckoView sets the same custom `User-Agent` HTTP request headers for every request, not only the root document's.

Context:
This affects Firefox Reality's ability to properly address sites with WebCompat issues (e.g., ones we are actively addressing with YouTube, for example). If this is fixed, such issues as this https://github.com/MozillaReality/FirefoxReality/issues/870, will be fixed.
Whiteboard: [webxr] → [webxr] [webvr]
I did some investigation and I'm not sure this is a GeckoView issue. We are using the "http-on-useragent-request" observer similar to how UA override is done for desktop in UserAgentOverrides.jsm. I logged how often the observer is invoked for a youtube page and we only received four callbacks for a page that had possibly 100 resource requests. Using the WebIDE I was able to confirm that the requested resources were still using the standard mobile UA. If "http-on-useragent-request" is working as expected then GeckoView will need some other mechanism for overriding the UA for all resources on a page and not just the root document.
Dragana do you know who could help diagnose this issue? (see comment 1)
Flags: needinfo?(dd.mozilla)
(In reply to David Bolter [:davidb] (NeedInfo me for attention) from comment #2)
> Dragana do you know who could help diagnose this issue? (see comment 1)

Valentin, can you take a look?
Flags: needinfo?(dd.mozilla) → needinfo?(valentin.gosu)
It seems like this has always been broken.
I tracked the issue down this line [1]
I touched it in bug 1262326, but it was added in bug 1148544. The way it should work is the top level request will also set the UA override on the loadgroup, so we don't have to call into UserAgentOverrides.jsm again (expensive JS, also the jsm isn't loaded in the content process).
But the problem is that for subresources, we always already have a UA set, because we add the default one in nsHttpHandler::AddStandardRequestHeaders

[1] https://searchfox.org/mozilla-central/rev/3fdc51e66c9487b39220ad58dcee275fca070ccd/netwerk/protocol/http/nsHttpChannel.cpp#8871
Assignee: nobody → valentin.gosu
Component: GeckoView → Networking
Flags: needinfo?(valentin.gosu)
Priority: -- → P2
Product: Firefox for Android → Core
Whiteboard: [webxr] [webvr] → [webxr] [webvr][necko-triaged]
Randall, a few questions about the use case here:
I'm considering rewriting UserAgentOverrides.jsm in C++ to avoid the performance hit when sending the "http-on-useragent-request" all the time. But I'm interested in your specific use case in GeckoViewSettings.jsm
If you want the UA to be set on all requests, you might as well set the general.useragent.override pref, and it will be set on all requests without any perf hit, and without listening for any observer events.
Flags: needinfo?(rbarker)
For GeckoView, we need the UA override to be GeckoSession specific. Setting the general.useragent.override would not work since it would affect all GeckoSessions. The specific use case for UA override in Firefox Reality is to override the UA for a given site and ensure all resource requests for that page have the same UA override. An additional requirement we have discovered while investigating this issue is being able to override an iframe UA. Specifically as it relates to embedded YouTube videos. But at this time I don't believe GeckoView has an API that would allow us to handle this. It would be great if we could find a way not to require JS callbacks to handle UA overrides because we have found thus far that we need to use UA override frequently for webcompat issues in the Firefox Reality browser.
Flags: needinfo?(rbarker)
(In reply to Randall Barker [:rbarker] from comment #7)
> For GeckoView, we need the UA override to be GeckoSession specific. Setting
There's also nsIDocShell.customUserAgent - even if used from JS, it would be much more efficient than using the "http-on-useragent-request" notification.
But I'm not sure how a GeckoSession maps to a docshell.

(In reply to Randall Barker [:rbarker] from comment #7)
> discovered while investigating this issue is being able to override an
> iframe UA. Specifically as it relates to embedded YouTube videos.

Does it currently work for an iframe? Because IsNonSubresourceRequest should return true for iframes.
See comment 8
Flags: needinfo?(rbarker)
I'm looking at using nsIDocShell.customUserAgent now.
Flags: needinfo?(rbarker)
Randall, I've moved the work of rewriting UserAgentOverride to bug 1513574. Let's use this bug to solve the GeckoView problem.
Assignee: valentin.gosu → rbarker
I must be doing something wrong. Setting the nsIDocShell.customUserAgent doesn't seem to override the UA. No matter what it is set to, the UA is always the default mobile UA.
Attachment #9029078 - Attachment description: Bug 1511281 - Update GeckoView to use http-on-modify-request observer for user agent override → Bug 1511281 - Update GeckoView user agent override to use docShell.customUserAgent
Pushed by rbarker@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/e5079e6a5c13
Update GeckoView user agent override to use docShell.customUserAgent r=snorp
https://hg.mozilla.org/mozilla-central/rev/e5079e6a5c13
Status: NEW → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla66
You need to log in before you can comment on or make changes to this bug.