diff --git a/experimental/puppeteer-firefox/lib/Page.js b/experimental/puppeteer-firefox/lib/Page.js index 91a35b93..0ff24682 100644 --- a/experimental/puppeteer-firefox/lib/Page.js +++ b/experimental/puppeteer-firefox/lib/Page.js @@ -88,6 +88,23 @@ class Page extends EventEmitter { this._viewport = null; } + /** + * @param {string} userAgent + */ + async setUserAgent(userAgent) { + await this._session.send('Page.setUserAgent', {userAgent}); + } + + /** + * @param {{viewport: !Puppeteer.Viewport, userAgent: string}} options + */ + async emulate(options) { + await Promise.all([ + this.setViewport(options.viewport), + this.setUserAgent(options.userAgent), + ]); + } + /** * @return {BrowserContext} */ diff --git a/experimental/puppeteer-firefox/package.json b/experimental/puppeteer-firefox/package.json index a45db348..00afacc6 100644 --- a/experimental/puppeteer-firefox/package.json +++ b/experimental/puppeteer-firefox/package.json @@ -9,7 +9,7 @@ "node": ">=8.9.4" }, "puppeteer": { - "firefox_revision": "9702d3d2dd86550e385fadec66eb28a5ff2b1322" + "firefox_revision": "ba500612786aac157fa44e6b4d04c852f51ea35c" }, "scripts": { "install": "node install.js", diff --git a/test/emulation.spec.js b/test/emulation.spec.js index 71b4704a..a2ce575f 100644 --- a/test/emulation.spec.js +++ b/test/emulation.spec.js @@ -82,12 +82,12 @@ module.exports.addTests = function({testRunner, expect, product}) { }); }); - describe_fails_ffox('Page.emulate', function() { + describe('Page.emulate', function() { it('should work', async({page, server}) => { await page.goto(server.PREFIX + '/mobile.html'); await page.emulate(iPhone); expect(await page.evaluate(() => window.innerWidth)).toBe(375); - expect(await page.evaluate(() => navigator.userAgent)).toContain('Safari'); + expect(await page.evaluate(() => navigator.userAgent)).toContain('iPhone'); }); it('should support clicking', async({page, server}) => { await page.emulate(iPhone); diff --git a/test/page.spec.js b/test/page.spec.js index 59717612..114af156 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -628,21 +628,30 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device }); }); - describe_fails_ffox('Page.setUserAgent', function() { + describe('Page.setUserAgent', function() { it('should work', async({page, server}) => { expect(await page.evaluate(() => navigator.userAgent)).toContain('Mozilla'); - page.setUserAgent('foobar'); + await page.setUserAgent('foobar'); const [request] = await Promise.all([ server.waitForRequest('/empty.html'), page.goto(server.EMPTY_PAGE), ]); expect(request.headers['user-agent']).toBe('foobar'); }); + it('should work for subframes', async({page, server}) => { + expect(await page.evaluate(() => navigator.userAgent)).toContain('Mozilla'); + await page.setUserAgent('foobar'); + const [request] = await Promise.all([ + server.waitForRequest('/empty.html'), + utils.attachFrame(page, 'frame1', server.EMPTY_PAGE), + ]); + expect(request.headers['user-agent']).toBe('foobar'); + }); it('should emulate device user-agent', async({page, server}) => { await page.goto(server.PREFIX + '/mobile.html'); - expect(await page.evaluate(() => navigator.userAgent)).toContain('Chrome'); + expect(await page.evaluate(() => navigator.userAgent)).not.toContain('iPhone'); await page.setUserAgent(iPhone.userAgent); - expect(await page.evaluate(() => navigator.userAgent)).toContain('Safari'); + expect(await page.evaluate(() => navigator.userAgent)).toContain('iPhone'); }); });