Closed Bug 1596136 Opened 5 years ago Closed 5 years ago

"Emulation.setUserAgentOverride" should only affect the current target

Categories

(Remote Protocol :: CDP, enhancement, P1)

enhancement

Tracking

(firefox74 fixed)

RESOLVED FIXED
Firefox 74
Tracking Status
firefox74 --- fixed

People

(Reporter: whimboo, Assigned: whimboo)

References

(Depends on 1 open bug, Blocks 2 open bugs)

Details

(Whiteboard: [puppeteer-beta-mvp])

Attachments

(2 files)

With bug 1595697 the Emulation.setUserAgentOverride implementation currently doesn't only affect the active session, but Firefox globally.

To bound the method to the current session only, network events have to be listened for, and modifications to the request header have to be made. Given that most of those aren't exist yet this work needs to be done at a later time.

Depends on: 1595706, 1595710

We should wait with this bug until all the dependencies have been implemented.

I just noticed that Juggler used the following implementation:

 async setUserAgent({userAgent}) {
    const docShell = this._frameTree.mainFrame().docShell();
    docShell.customUserAgent = userAgent;
  }

Which basically is:
https://searchfox.org/mozilla-central/rev/690e903ef689a4eca335b96bd903580394864a1c/docshell/base/nsIDocShell.idl#181-184

It means that the custom user agent gets reset with the next navigation, right? We would have to check how Chrome behaves here.

Good find.

This is also what DevTools uses and from a cursory look over their code they set it each time the docshell is loaded.

In that case we would need an internal property to hold the user agent override string, and then also apply it when the docshell is loaded. Do you have a link to their code? Which kind of event are they listen for?

Device emulation works based on the docshell. As such I have to get this fixed before I can start working on bug 1544417.

A WiP is already working.

Assignee: nobody → hskupin
Status: NEW → ASSIGNED
Priority: P3 → P1
Whiteboard: [puppeteer-beta-reserve]
Whiteboard: [puppeteer-beta-reserve] → [puppeteer-beta-mvp]

Please note that the summary of this bug might be wrong. Setting a custom user agent might only affect the currently active target, and not the whole session. This is something which I will have to check next. I will update the bug as necessary.

Depends on: 1605722

Basically it is not the session which should be affected by setting the user agent, but the current target only. Different sessions actually share the same target scope, which means the set user agent.

Summary: "Emulation.setUserAgentOverride" should only affect the current session → "Emulation.setUserAgentOverride" should only affect the current target
Blocks: 1544417

Actually I don't think that we should make this change until bug 1605243 has been fixed.

Depends on: 1605243
Assignee: hskupin → nobody
Status: ASSIGNED → NEW
Priority: P1 → P3
Whiteboard: [puppeteer-beta-mvp]
Assignee: nobody → hskupin
Attachment #9117601 - Attachment description: Bug 1596136 - [remote] Make openTab() and openWindow() globally shared methods for browser chrome tests. r=#remote! → Bug 1596136 - [remote] Remove openTab() and openWindow() helpers from target tests head.js. r=#remote!
Status: NEW → ASSIGNED
Attachment #9117602 - Attachment description: Bug 1596136 - [remote] "Emulation.setUserAgentOverride" should only affect the current session. r=#remote! → Bug 1596136 - [remote] "Emulation.setUserAgentOverride" should only affect the current target. r=#remote!
Priority: P3 → P1
Whiteboard: [puppeteer-beta-mvp]
Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a1d781ba0aa9 [remote] Remove openTab() and openWindow() helpers from target tests head.js. r=remote-protocol-reviewers,ato https://hg.mozilla.org/integration/autoland/rev/7472a5f9c6c0 [remote] "Emulation.setUserAgentOverride" should only affect the current target. r=remote-protocol-reviewers,ato
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 74
Component: CDP: Emulation → CDP
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: