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(media): remove media emulation from browser context options (#377)
Pavel Feldman38e79f12ece0
diff --git a/docs/api.md b/docs/api.mdindex 07c1f802dd..abe581c555 100644--- a/docs/api.md+++ b/docs/api.md@@ -2015,7 +2015,7 @@ Shortcut for [page.mainFrame().dblclick(selector[, options])](#framedblclicksele#### page.emulateMedia(options)- `options` <[Object]>- - `type` <"screen"|"print"> Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables CSS media emulation.+ - `media` <"screen"|"print"> Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables CSS media emulation.- `colorScheme` <"dark"|"light"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`.- returns: <[Promise]>@@ -2025,7 +2025,7 @@ await page.evaluate(() => matchMedia('screen').matches));await page.evaluate(() => matchMedia('print').matches));// → true-await page.emulateMedia({ type: 'print' });+await page.emulateMedia({ media: 'print' });await page.evaluate(() => matchMedia('screen').matches));// → falseawait page.evaluate(() => matchMedia('print').matches));diff --git a/src/browserContext.ts b/src/browserContext.tsindex 386624c229..067f77dc24 100644--- a/src/browserContext.ts+++ b/src/browserContext.ts@@ -39,8 +39,6 @@ export type BrowserContextOptions = {ignoreHTTPSErrors?: boolean,javaScriptEnabled?: boolean,bypassCSP?: boolean,- mediaType?: types.MediaType,- colorScheme?: types.ColorScheme,userAgent?: string,timezoneId?: string,geolocation?: types.Geolocationdiff --git a/src/chromium/crPage.ts b/src/chromium/crPage.tsindex 650d295ce5..ad7bf1442d 100644--- a/src/chromium/crPage.ts+++ b/src/chromium/crPage.ts@@ -104,10 +104,6 @@ export class CRPage implements PageDelegate {promises.push(this._client.send('Emulation.setScriptExecutionDisabled', { value: true }));if (options.userAgent)this._networkManager.setUserAgent(options.userAgent);- if (options.mediaType || options.colorScheme) {- const features = options.colorScheme ? [{ name: 'prefers-color-scheme', value: options.colorScheme }] : [];- promises.push(this._client.send('Emulation.setEmulatedMedia', { media: options.mediaType || '', features }));- }if (options.timezoneId)promises.push(emulateTimezone(this._client, options.timezoneId));if (options.geolocation)diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.tsindex 56b392e58d..d4e56d76a9 100644--- a/src/firefox/ffPage.ts+++ b/src/firefox/ffPage.ts@@ -82,8 +82,6 @@ export class FFPage implements PageDelegate {promises.push(this._session.send('Page.setJavascriptEnabled', { enabled: false }));if (options.userAgent)promises.push(this._session.send('Page.setUserAgent', { userAgent: options.userAgent }));- if (options.mediaType || options.colorScheme)- promises.push(this._session.send('Page.setEmulatedMedia', { type: options.mediaType, colorScheme: options.colorScheme }));await Promise.all(promises);}diff --git a/src/page.ts b/src/page.tsindex cdf89d56d5..bacad7ac9d 100644--- a/src/page.ts+++ b/src/page.ts@@ -113,8 +113,8 @@ export class Page extends EventEmitter {this._browserContext = browserContext;this._state = {viewport: browserContext._options.viewport || null,- mediaType: browserContext._options.mediaType || null,- colorScheme: browserContext._options.colorScheme || null,+ mediaType: null,+ colorScheme: null,extraHTTPHeaders: null,cacheEnabled: null,interceptNetwork: null,@@ -370,11 +370,11 @@ export class Page extends EventEmitter {return waitPromise;}- async emulateMedia(options: { type?: types.MediaType, colorScheme?: types.ColorScheme }) {- assert(!options.type || types.mediaTypes.has(options.type), 'Unsupported media type: ' + options.type);+ async emulateMedia(options: { media?: types.MediaType, colorScheme?: types.ColorScheme }) {+ assert(!options.media || types.mediaTypes.has(options.media), 'Unsupported media: ' + options.media);assert(!options.colorScheme || types.colorSchemes.has(options.colorScheme), 'Unsupported color scheme: ' + options.colorScheme);- if (options.type !== undefined)- this._state.mediaType = options.type;+ if (options.media !== undefined)+ this._state.mediaType = options.media;if (options.colorScheme !== undefined)this._state.colorScheme = options.colorScheme;await this._delegate.setEmulateMedia(this._state.mediaType, this._state.colorScheme);diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.jsindex f7675b4554..e86a45c022 100644--- a/test/browsercontext.spec.js+++ b/test/browsercontext.spec.js@@ -100,11 +100,6 @@ module.exports.describe = function({testRunner, expect, playwright, CHROME, WEBKexpect(await page.evaluate('window.innerWidth')).toBe(456);expect(await page.evaluate('window.innerHeight')).toBe(789);});- it.skip(WEBKIT)('should propagate default mediaType and colorScheme to the page', async({ newPage }) => {- const page = await newPage({ mediaType: 'print', colorScheme: 'dark' });- expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);- expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches)).toBe(true);- });it('should take fullPage screenshots when default viewport is null', async({server, newPage}) => {const page = await newPage({ viewport: null });await page.goto(server.PREFIX + '/grid.html');diff --git a/test/emulation.spec.js b/test/emulation.spec.jsindex 798f3a2eb7..3a872240c3 100644--- a/test/emulation.spec.js+++ b/test/emulation.spec.js@@ -117,20 +117,20 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMEit('should work', async({page, server}) => {expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(true);expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);- await page.emulateMedia({ type: 'print' });+ await page.emulateMedia({ media: 'print' });expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(false);expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);await page.emulateMedia({});expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(false);expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);- await page.emulateMedia({ type: '' });+ await page.emulateMedia({ media: '' });expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(true);expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);});it('should throw in case of bad type argument', async({page, server}) => {let error = null;- await page.emulateMedia({ type: 'bad' }).catch(e => error = e);- expect(error.message).toBe('Unsupported media type: bad');+ await page.emulateMedia({ media: 'bad' }).catch(e => error = e);+ expect(error.message).toBe('Unsupported media: bad');});});diff --git a/test/page.spec.js b/test/page.spec.jsindex b2cd83f196..ea1a43dfe3 100644--- a/test/page.spec.js+++ b/test/page.spec.js@@ -172,7 +172,7 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FFexpect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(false);});- it.skip(WEBKIT || FFOX)('should not treat navigations as new popups', async({page, server}) => {+ it.skip(FFOX)('should not treat navigations as new popups', async({page, server}) => {await page.goto(server.EMPTY_PAGE);await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');const [popup] = await Promise.all([