mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
browser(firefox): introduce global proxy (#3335)
This will be used instead of messing up user preferences for proxy setup.
This commit is contained in:
parent
ddd483bdf0
commit
a225447653
@ -1,2 +1,2 @@
|
||||
1154
|
||||
Changed: lushnikov@chromium.org Thu Aug 6 10:22:22 PDT 2020
|
||||
1155
|
||||
Changed: lushnikov@chromium.org Fri Aug 7 15:25:51 PDT 2020
|
||||
|
||||
@ -297,7 +297,13 @@ class NetworkRequest {
|
||||
if (!pageNetwork)
|
||||
return false;
|
||||
const browserContext = pageNetwork._target.browserContext();
|
||||
const credentials = browserContext ? browserContext.httpCredentials : undefined;
|
||||
let credentials = null;
|
||||
if (authInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY) {
|
||||
const proxy = this._networkObserver._targetRegistry.getProxyInfo(aChannel);
|
||||
credentials = proxy ? {username: proxy.username, password: proxy.password} : null;
|
||||
} else {
|
||||
credentials = browserContext ? browserContext.httpCredentials : undefined;
|
||||
}
|
||||
if (!credentials)
|
||||
return false;
|
||||
authInfo.username = credentials.username;
|
||||
@ -569,17 +575,11 @@ class NetworkObserver {
|
||||
this._channelProxyFilter = {
|
||||
QueryInterface: ChromeUtils.generateQI([Ci.nsIProtocolProxyChannelFilter]),
|
||||
applyFilter: (channel, defaultProxyInfo, proxyFilter) => {
|
||||
const originAttributes = channel.loadInfo && channel.loadInfo.originAttributes;
|
||||
const browserContext = originAttributes ? this._targetRegistry.browserContextForUserContextId(originAttributes.userContextId) : null;
|
||||
const proxy = browserContext ? browserContext.proxy : null;
|
||||
const proxy = this._targetRegistry.getProxyInfo(channel);
|
||||
if (!proxy) {
|
||||
proxyFilter.onProxyFilterResult(defaultProxyInfo);
|
||||
return;
|
||||
}
|
||||
if (proxy.bypass.some(domain => channel.URI.host.endsWith(domain))) {
|
||||
proxyFilter.onProxyFilterResult(defaultProxyInfo);
|
||||
return;
|
||||
}
|
||||
proxyFilter.onProxyFilterResult(protocolProxyService.newProxyInfo(
|
||||
proxy.type,
|
||||
proxy.host,
|
||||
|
||||
@ -113,6 +113,8 @@ class TargetRegistry {
|
||||
this._browserToTarget = new Map();
|
||||
this._browserBrowsingContextToTarget = new Map();
|
||||
|
||||
this._browserProxy = null;
|
||||
|
||||
// Cleanup containers from previous runs (if any)
|
||||
for (const identity of ContextualIdentityService.getPublicIdentities()) {
|
||||
if (identity.name && identity.name.startsWith(IDENTITY_NAME)) {
|
||||
@ -241,6 +243,20 @@ class TargetRegistry {
|
||||
extHelperAppSvc.setDownloadInterceptor(new DownloadInterceptor(this));
|
||||
}
|
||||
|
||||
setBrowserProxy(proxy) {
|
||||
this._browserProxy = proxy;
|
||||
}
|
||||
|
||||
getProxyInfo(channel) {
|
||||
const originAttributes = channel.loadInfo && channel.loadInfo.originAttributes;
|
||||
const browserContext = originAttributes ? this.browserContextForUserContextId(originAttributes.userContextId) : null;
|
||||
// Prefer context proxy and fallback to browser-level proxy.
|
||||
const proxyInfo = (browserContext && browserContext._proxy) || this._browserProxy;
|
||||
if (!proxyInfo || proxyInfo.bypass.some(domainSuffix => channel.URI.host.endsWith(domainSuffix)))
|
||||
return null;
|
||||
return proxyInfo;
|
||||
}
|
||||
|
||||
defaultContext() {
|
||||
return this._defaultContext;
|
||||
}
|
||||
@ -473,8 +489,8 @@ class BrowserContext {
|
||||
this._permissions = new Map();
|
||||
this._registry._browserContextIdToBrowserContext.set(this.browserContextId, this);
|
||||
this._registry._userContextIdToBrowserContext.set(this.userContextId, this);
|
||||
this._proxy = null;
|
||||
this.removeOnDetach = removeOnDetach;
|
||||
this.proxy = undefined;
|
||||
this.extraHTTPHeaders = undefined;
|
||||
this.httpCredentials = undefined;
|
||||
this.requestInterceptionEnabled = undefined;
|
||||
@ -507,6 +523,10 @@ class BrowserContext {
|
||||
this._registry._userContextIdToBrowserContext.delete(this.userContextId);
|
||||
}
|
||||
|
||||
setProxy(proxy) {
|
||||
this._proxy = proxy;
|
||||
}
|
||||
|
||||
setIgnoreHTTPSErrors(ignoreHTTPSErrors) {
|
||||
if (this.ignoreHTTPSErrors === ignoreHTTPSErrors)
|
||||
return;
|
||||
|
||||
@ -151,8 +151,13 @@ class BrowserHandler {
|
||||
this._targetRegistry.browserContextForId(browserContextId).httpCredentials = nullToUndefined(credentials);
|
||||
}
|
||||
|
||||
async setProxy({browserContextId, type, host, port, bypass}) {
|
||||
this._targetRegistry.browserContextForId(browserContextId).proxy = { type, host, port, bypass };
|
||||
async setBrowserProxy({type, host, port, bypass, username, password}) {
|
||||
this._targetRegistry.setBrowserProxy({ type, host, port, bypass, username, password});
|
||||
}
|
||||
|
||||
async setContextProxy({browserContextId, type, host, port, bypass, username, password}) {
|
||||
const browserContext = this._targetRegistry.browserContextForId(browserContextId);
|
||||
browserContext.setProxy({ type, host, port, bypass, username, password });
|
||||
}
|
||||
|
||||
setRequestInterception({browserContextId, enabled}) {
|
||||
|
||||
@ -258,13 +258,25 @@ const Browser = {
|
||||
headers: t.Array(networkTypes.HTTPHeader),
|
||||
},
|
||||
},
|
||||
'setProxy': {
|
||||
'setBrowserProxy': {
|
||||
params: {
|
||||
type: t.Enum(['http', 'https', 'socks', 'socks4']),
|
||||
bypass: t.Array(t.String),
|
||||
host: t.String,
|
||||
port: t.Number,
|
||||
username: t.Optional(t.String),
|
||||
password: t.Optional(t.String),
|
||||
},
|
||||
},
|
||||
'setContextProxy': {
|
||||
params: {
|
||||
browserContextId: t.Optional(t.String),
|
||||
type: t.Enum(['http', 'https', 'socks', 'socks4']),
|
||||
bypass: t.Array(t.String),
|
||||
host: t.String,
|
||||
port: t.Number,
|
||||
username: t.Optional(t.String),
|
||||
password: t.Optional(t.String),
|
||||
},
|
||||
},
|
||||
'setHTTPCredentials': {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user