Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(firefox): make interception, locale and geolocation work on browser context level (#1472)
Dmitry Gozman6e8895fa0807
diff --git a/package.json b/package.jsonindex 66b19d49cb..95ac9a236b 100644--- a/package.json+++ b/package.json@@ -9,7 +9,7 @@"main": "index.js","playwright": {"chromium_revision": "751710",- "firefox_revision": "1047",+ "firefox_revision": "1048","webkit_revision": "1182"},"scripts": {diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.tsindex 8e80a0db0e..de283870e8 100644--- a/src/firefox/ffBrowser.ts+++ b/src/firefox/ffBrowser.ts@@ -94,6 +94,7 @@ export class FFBrowser extends platform.EventEmitter implements Browser {bypassCSP: options.bypassCSP,javaScriptDisabled: options.javaScriptEnabled === false ? true : undefined,viewport,+ locale: options.locale,removeOnDetach: true});// TODO: move ignoreHTTPSErrors to browser context level.@@ -174,6 +175,8 @@ export class FFBrowserContext extends BrowserContextBase {await this.setOffline(this._options.offline);if (this._options.httpCredentials)await this.setHTTPCredentials(this._options.httpCredentials);+ if (this._options.geolocation)+ await this.setGeolocation(this._options.geolocation);}_ffPages(): FFPage[] {@@ -249,8 +252,7 @@ export class FFBrowserContext extends BrowserContextBase {if (geolocation)geolocation = verifyGeolocation(geolocation);this._options.geolocation = geolocation || undefined;- for (const page of this.pages())- await (page._delegate as FFPage)._setGeolocation(geolocation);+ await this._browser._connection.send('Browser.setGeolocationOverride', { browserContextId: this._browserContextId || undefined, geolocation });}async setExtraHTTPHeaders(headers: network.Headers): Promise<void> {@@ -292,8 +294,8 @@ export class FFBrowserContext extends BrowserContextBase {async route(url: types.URLMatch, handler: network.RouteHandler): Promise<void> {this._routes.push({ url, handler });- throw new Error('Not implemented');- // TODO: update interception on the context if this is a first route.+ if (this._routes.length === 1)+ await this._browser._connection.send('Browser.setRequestInterception', { browserContextId: this._browserContextId || undefined, enabled: true });}async close() {diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.tsindex 3c6af7f768..c95c30eba8 100644--- a/src/firefox/ffPage.ts+++ b/src/firefox/ffPage.ts@@ -86,8 +86,6 @@ export class FFPage implements PageDelegate {}async _initialize() {- const geolocation = this._browserContext._options.geolocation;- const language = this._browserContext._options.locale;try {await Promise.all([// TODO: we should get rid of this call to resolve before any early events arrive, e.g. dialogs.@@ -95,8 +93,6 @@ export class FFPage implements PageDelegate {script: '',worldName: UTILITY_WORLD_NAME,}),- geolocation ? this._setGeolocation(geolocation) : Promise.resolve(),- language ? this._session.send('Page.setLanguageOverride', { language }) : Promise.resolve(),new Promise(f => this._session.once('Page.ready', f)),]);this._pageCallback(this._page);@@ -485,10 +481,6 @@ export class FFPage implements PageDelegate {throw new Error('Frame has been detached.');return result.handle;}-- async _setGeolocation(geolocation: types.Geolocation | null) {- await this._session.send('Page.setGeolocationOverride', geolocation || {});- }}function toRemoteObject(handle: dom.ElementHandle): Protocol.Runtime.RemoteObject {diff --git a/test/assets/formatted-number.html b/test/assets/formatted-number.htmlindex 93fd057a47..75e63207d2 100644--- a/test/assets/formatted-number.html+++ b/test/assets/formatted-number.html@@ -1,3 +1,4 @@<script>window.result = (1000000.50).toLocaleString().replace(/\s/g, ' ');+window.initialNavigatorLanguage = navigator.language;</script>diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.jsindex 45ae9cdff9..5b0523eadd 100644--- a/test/browsercontext.spec.js+++ b/test/browsercontext.spec.js@@ -367,7 +367,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF});});- describe.fail(FFOX)('BrowserContext.route', () => {+ describe('BrowserContext.route', () => {it('should intercept', async({browser, server}) => {const context = await browser.newContext();let intercepted = false;diff --git a/test/emulation.spec.js b/test/emulation.spec.jsindex eb0f64485b..4fcbf7aa51 100644--- a/test/emulation.spec.js+++ b/test/emulation.spec.js@@ -342,7 +342,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FFawait context.close();}});- it.fail(CHROMIUM || FFOX)('should apply to popups', async({browser, server}) => {+ it.fail(CHROMIUM || FFOX)('should format number in popups', async({browser, server}) => {const context = await browser.newContext({ locale: 'fr-CH' });const page = await context.newPage();await page.goto(server.EMPTY_PAGE);@@ -356,6 +356,19 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FFexpect(result).toBe('1 000 000,5');await context.close();});+ it.fail(CHROMIUM)('should affect navigator.language in popups', async({browser, server}) => {+ const context = await browser.newContext({ locale: 'fr-CH' });+ const page = await context.newPage();+ await page.goto(server.EMPTY_PAGE);+ const [popup] = await Promise.all([+ page.waitForEvent('popup'),+ page.evaluate(url => window._popup = window.open(url), server.PREFIX + '/formatted-number.html'),+ ]);+ await popup.waitForLoadState({ waitUntil: 'domcontentloaded' });+ const result = await popup.evaluate(() => window.initialNavigatorLanguage);+ expect(result).toBe('fr-CH');+ await context.close();+ });});describe('focus', function() {diff --git a/test/geolocation.spec.js b/test/geolocation.spec.jsindex f177bb9ac2..654ce4f878 100644--- a/test/geolocation.spec.js+++ b/test/geolocation.spec.js@@ -112,7 +112,7 @@ module.exports.describe = function ({ testRunner, expect, FFOX, WEBKIT }) {expect(allMessages).toContain('lat=20 lng=30');expect(allMessages).toContain('lat=40 lng=50');});- it.fail(FFOX)('should use context options for popup', async({page, context, server}) => {+ it('should use context options for popup', async({page, context, server}) => {await context.grantPermissions(['geolocation']);await context.setGeolocation({ longitude: 10, latitude: 10 });const [popup] = await Promise.all([diff --git a/test/popup.spec.js b/test/popup.spec.jsindex 30bbfd8698..dddc567afd 100644--- a/test/popup.spec.js+++ b/test/popup.spec.js@@ -39,7 +39,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WEexpect(userAgent).toBe('hey');expect(request.headers['user-agent']).toBe('hey');});- it.fail(FFOX)('should respect routes from browser context', async function({browser, server}) {+ it('should respect routes from browser context', async function({browser, server}) {const context = await browser.newContext();const page = await context.newPage();await page.goto(server.EMPTY_PAGE);