browser(firefox): move user agent emulation to browser side (#4016)
References #3995
This commit is contained in:
parent
ab2714ed29
commit
974358442d
|
|
@ -1,2 +1,2 @@
|
|||
1176
|
||||
Changed: lushnikov@chromium.org Wed Sep 30 03:06:09 MDT 2020
|
||||
1177
|
||||
Changed: lushnikov@chromium.org Wed Sep 30 03:11:29 MDT 2020
|
||||
|
|
|
|||
|
|
@ -175,6 +175,7 @@ class TargetRegistry {
|
|||
if (!browserContext)
|
||||
throw new Error(`Internal error: cannot find context for userContextId=${userContextId}`);
|
||||
const target = new PageTarget(this, window, tab, browserContext, openerTarget);
|
||||
target.updateUserAgent();
|
||||
if (!hasExplicitSize)
|
||||
target.updateViewportSize();
|
||||
};
|
||||
|
|
@ -393,6 +394,10 @@ class PageTarget {
|
|||
return this._browserContext;
|
||||
}
|
||||
|
||||
updateUserAgent() {
|
||||
this._linkedBrowser.browsingContext.customUserAgent = this._browserContext.defaultUserAgent;
|
||||
}
|
||||
|
||||
async updateViewportSize() {
|
||||
// Viewport size is defined by three arguments:
|
||||
// 1. default size. Could be explicit if set as part of `window.open` call, e.g.
|
||||
|
|
@ -513,6 +518,7 @@ class BrowserContext {
|
|||
this.ignoreHTTPSErrors = undefined;
|
||||
this.downloadOptions = undefined;
|
||||
this.defaultViewportSize = undefined;
|
||||
this.defaultUserAgent = null;
|
||||
this.screencastOptions = undefined;
|
||||
this.scriptsToEvaluateOnNewDocument = [];
|
||||
this.bindings = [];
|
||||
|
|
@ -559,6 +565,12 @@ class BrowserContext {
|
|||
}
|
||||
}
|
||||
|
||||
async setDefaultUserAgent(userAgent) {
|
||||
this.defaultUserAgent = userAgent;
|
||||
for (const page of this.pages)
|
||||
page.updateUserAgent();
|
||||
}
|
||||
|
||||
async setDefaultViewport(viewport) {
|
||||
this.defaultViewportSize = viewport ? viewport.viewportSize : undefined;
|
||||
const promises = Array.from(this.pages).map(page => page.updateViewportSize());
|
||||
|
|
|
|||
|
|
@ -59,10 +59,6 @@ const applySetting = {
|
|||
Ci.nsIDocShell.ONLINE_OVERRIDE_ONLINE : Ci.nsIDocShell.ONLINE_OVERRIDE_OFFLINE;
|
||||
},
|
||||
|
||||
userAgent: (userAgent) => {
|
||||
docShell.browsingContext.customUserAgent = userAgent;
|
||||
},
|
||||
|
||||
bypassCSP: (bypassCSP) => {
|
||||
docShell.bypassCSPEnabled = bypassCSP;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ class BrowserHandler {
|
|||
}
|
||||
|
||||
async setUserAgentOverride({browserContextId, userAgent}) {
|
||||
await this._targetRegistry.browserContextForId(browserContextId).applySetting('userAgent', nullToUndefined(userAgent));
|
||||
await this._targetRegistry.browserContextForId(browserContextId).setDefaultUserAgent(userAgent);
|
||||
}
|
||||
|
||||
async setBypassCSP({browserContextId, bypassCSP}) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue