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
feat(firefox): ensure that new pages get browser context userAgent option (#872)
Dmitry Gozmanc33a12d8f0cf
diff --git a/package.json b/package.jsonindex f429302957..2a6db56d23 100644--- a/package.json+++ b/package.json@@ -9,7 +9,7 @@"main": "index.js","playwright": {"chromium_revision": "737027",- "firefox_revision": "1021",+ "firefox_revision": "1025","webkit_revision": "1134"},"scripts": {diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.tsindex a67df172d2..86f1dd5777 100644--- a/src/firefox/ffBrowser.ts+++ b/src/firefox/ffBrowser.ts@@ -56,6 +56,7 @@ export class FFBrowser extends platform.EventEmitter implements Browser {helper.addEventListener(this._connection, 'Target.targetCreated', this._onTargetCreated.bind(this)),helper.addEventListener(this._connection, 'Target.targetDestroyed', this._onTargetDestroyed.bind(this)),helper.addEventListener(this._connection, 'Target.targetInfoChanged', this._onTargetInfoChanged.bind(this)),+ helper.addEventListener(this._connection, 'Target.attachedToTarget', this._onAttachedToTarget.bind(this)),];}@@ -64,7 +65,9 @@ export class FFBrowser extends platform.EventEmitter implements Browser {}async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {- const {browserContextId} = await this._connection.send('Target.createBrowserContext');+ const {browserContextId} = await this._connection.send('Target.createBrowserContext', {+ userAgent: options.userAgent+ });// TODO: move ignoreHTTPSErrors to browser context level.if (options.ignoreHTTPSErrors)await this._connection.send('Browser.setIgnoreHTTPSErrors', { enabled: true });@@ -143,6 +146,13 @@ export class FFBrowser extends platform.EventEmitter implements Browser {target._url = url;}+ _onAttachedToTarget(payload: Protocol.Target.attachedToTargetPayload) {+ const {targetId, type} = payload.targetInfo;+ const target = this._targets.get(targetId)!;+ if (type === 'page')+ target.page();+ }+async close() {await Promise.all(this.browserContexts().map(context => context.close()));helper.removeEventListeners(this._eventListeners);diff --git a/src/firefox/ffConnection.ts b/src/firefox/ffConnection.tsindex a6da12347e..8ccb0f1c97 100644--- a/src/firefox/ffConnection.ts+++ b/src/firefox/ffConnection.ts@@ -99,7 +99,7 @@ export class FFConnection extends platform.EventEmitter {const sessionId = object.params.sessionId;const session = new FFSession(this, object.params.targetInfo.type, sessionId, message => this._rawSend({...message, sessionId}));this._sessions.set(sessionId, session);- } else if (object.method === 'Browser.detachedFromTarget') {+ } else if (object.method === 'Target.detachedFromTarget') {const session = this._sessions.get(object.params.sessionId);if (session) {session._onClosed();diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.tsindex 0860e76f79..12666b6a4d 100644--- a/src/firefox/ffPage.ts+++ b/src/firefox/ffPage.ts@@ -89,8 +89,6 @@ export class FFPage implements PageDelegate {promises.push(this._session.send('Page.setBypassCSP', { enabled: true }));if (options.javaScriptEnabled === false)promises.push(this._session.send('Page.setJavascriptEnabled', { enabled: false }));- if (options.userAgent)- promises.push(this._session.send('Page.setUserAgent', { userAgent: options.userAgent }));await Promise.all(promises);}diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.jsindex b046b2c3ba..3eecf0aa22 100644--- a/test/browsercontext.spec.js+++ b/test/browsercontext.spec.js@@ -31,6 +31,19 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WEawait context.close();expect(browser.browserContexts().length).toBe(0);});+ it.skip(CHROMIUM)('popup should inherit user agent', async function({newContext, server}) {+ const context = await newContext({+ userAgent: 'hey'+ });+ const page = await context.newPage();+ await page.goto(server.EMPTY_PAGE);+ const evaluatePromise = page.evaluate(url => window.open(url), server.PREFIX + '/dummy.html');+ const popupPromise = page.waitForEvent('popup');+ const request = await server.waitForRequest('/dummy.html');+ await evaluatePromise;+ await popupPromise;+ expect(request.headers['user-agent']).toBe('hey');+ });it('window.open should use parent tab context', async function({newContext, server}) {const context = await newContext();const page = await context.newPage();