playwright-core
Advanced tools
Comparing version 0.11.1-next.1584749942244 to 0.11.1-next.1584759824996
@@ -232,4 +232,2 @@ "use strict"; | ||
await this.grantPermissions(this._options.permissions); | ||
if (this._options.geolocation) | ||
await this.setGeolocation(this._options.geolocation); | ||
if (this._options.offline) | ||
@@ -236,0 +234,0 @@ await this.setOffline(this._options.offline); |
@@ -149,6 +149,4 @@ "use strict"; | ||
await this.grantPermissions(this._options.permissions); | ||
if (this._options.geolocation) | ||
await this.setGeolocation(this._options.geolocation); | ||
if (this._options.extraHTTPHeaders) | ||
await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders); | ||
if (this._options.extraHTTPHeaders || this._options.locale) | ||
await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || {}); | ||
if (this._options.offline) | ||
@@ -219,7 +217,14 @@ await this.setOffline(this._options.offline); | ||
async setGeolocation(geolocation) { | ||
throw new Error('Geolocation emulation is not supported in Firefox'); | ||
if (geolocation) | ||
geolocation = browserContext_1.verifyGeolocation(geolocation); | ||
this._options.geolocation = geolocation || undefined; | ||
for (const page of this.pages()) | ||
await page._delegate._setGeolocation(geolocation); | ||
} | ||
async setExtraHTTPHeaders(headers) { | ||
this._options.extraHTTPHeaders = network.verifyHeaders(headers); | ||
await this._browser._connection.send('Browser.setExtraHTTPHeaders', { browserContextId: this._browserContextId || undefined, headers: ffNetworkManager_1.headersArray(this._options.extraHTTPHeaders) }); | ||
const allHeaders = { ...this._options.extraHTTPHeaders }; | ||
if (this._options.locale) | ||
allHeaders['Accept-Language'] = this._options.locale; | ||
await this._browser._connection.send('Browser.setExtraHTTPHeaders', { browserContextId: this._browserContextId || undefined, headers: ffNetworkManager_1.headersArray(allHeaders) }); | ||
} | ||
@@ -226,0 +231,0 @@ async setOffline(offline) { |
@@ -72,2 +72,4 @@ "use strict"; | ||
async _initialize() { | ||
const geolocation = this._browserContext._options.geolocation; | ||
const language = this._browserContext._options.locale; | ||
try { | ||
@@ -80,2 +82,4 @@ await Promise.all([ | ||
}), | ||
geolocation ? this._setGeolocation(geolocation) : Promise.resolve(), | ||
language ? this._session.send('Page.setLanguageOverride', { language }) : Promise.resolve(), | ||
new Promise(f => this._session.once('Page.ready', f)), | ||
@@ -414,2 +418,5 @@ ]); | ||
} | ||
async _setGeolocation(geolocation) { | ||
await this._session.send('Page.setGeolocationOverride', geolocation || {}); | ||
} | ||
} | ||
@@ -416,0 +423,0 @@ exports.FFPage = FFPage; |
@@ -225,15 +225,6 @@ "use strict"; | ||
async _doGrantPermissions(origin, permissions) { | ||
const webPermissionToProtocol = new Map([ | ||
['geolocation', 'geolocation'], | ||
]); | ||
const filtered = permissions.map(permission => { | ||
const protocolPermission = webPermissionToProtocol.get(permission); | ||
if (!protocolPermission) | ||
throw new Error('Unknown permission: ' + permission); | ||
return protocolPermission; | ||
}); | ||
await this._browser._browserSession.send('Playwright.grantPermissions', { origin, browserContextId: this._browserContextId, permissions: filtered }); | ||
await Promise.all(this.pages().map(page => page._delegate._grantPermissions(origin, permissions))); | ||
} | ||
async _doClearPermissions() { | ||
await this._browser._browserSession.send('Playwright.resetPermissions', { browserContextId: this._browserContextId }); | ||
await Promise.all(this.pages().map(page => page._delegate._clearPermissions())); | ||
} | ||
@@ -240,0 +231,0 @@ async setGeolocation(geolocation) { |
@@ -78,2 +78,6 @@ "use strict"; | ||
promises.push(this.updateHttpCredentials()); | ||
if (this._browserContext._permissions.size) { | ||
for (const [key, value] of this._browserContext._permissions) | ||
this._grantPermissions(key, value); | ||
} | ||
await Promise.all(promises); | ||
@@ -722,2 +726,17 @@ } | ||
} | ||
async _grantPermissions(origin, permissions) { | ||
const webPermissionToProtocol = new Map([ | ||
['geolocation', 'geolocation'], | ||
]); | ||
const filtered = permissions.map(permission => { | ||
const protocolPermission = webPermissionToProtocol.get(permission); | ||
if (!protocolPermission) | ||
throw new Error('Unknown permission: ' + permission); | ||
return protocolPermission; | ||
}); | ||
await this._pageProxySession.send('Emulation.grantPermissions', { origin, permissions: filtered }); | ||
} | ||
async _clearPermissions() { | ||
await this._pageProxySession.send('Emulation.resetPermissions', {}); | ||
} | ||
} | ||
@@ -724,0 +743,0 @@ exports.WKPage = WKPage; |
{ | ||
"name": "playwright-core", | ||
"version": "0.11.1-next.1584749942244", | ||
"version": "0.11.1-next.1584759824996", | ||
"description": "A high-level API to automate web browsers", | ||
@@ -12,4 +12,4 @@ "repository": "github:Microsoft/playwright", | ||
"chromium_revision": "751710", | ||
"firefox_revision": "1043", | ||
"webkit_revision": "1180" | ||
"firefox_revision": "1045", | ||
"webkit_revision": "1182" | ||
}, | ||
@@ -16,0 +16,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
1917086
46841