From a2b48f2654c3cfda28336b595ebd5ea36901a34b Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 30 Sep 2024 16:53:33 +0200 Subject: [PATCH] fix(emulate media): document "no-preference" as deprecated --- docs/src/api/class-page.md | 17 ++++------------- docs/src/api/params.md | 4 ++-- docs/src/emulation.md | 2 +- docs/src/test-use-options-js.md | 2 +- packages/playwright-core/types/types.d.ts | 16 +++++++--------- packages/playwright/types/test.d.ts | 2 +- 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md index 60512f51ca70d..b3a9897bb0e5d 100644 --- a/docs/src/api/class-page.md +++ b/docs/src/api/class-page.md @@ -1217,8 +1217,6 @@ await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches); // → true await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches); // → false -await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches); -// → false ``` ```java @@ -1227,8 +1225,6 @@ page.evaluate("() => matchMedia('(prefers-color-scheme: dark)').matches"); // → true page.evaluate("() => matchMedia('(prefers-color-scheme: light)').matches"); // → false -page.evaluate("() => matchMedia('(prefers-color-scheme: no-preference)').matches"); -// → false ``` ```python async @@ -1237,8 +1233,6 @@ await page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches") # → True await page.evaluate("matchMedia('(prefers-color-scheme: light)').matches") # → False -await page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches") -# → False ``` ```python sync @@ -1247,7 +1241,6 @@ page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches") # → True page.evaluate("matchMedia('(prefers-color-scheme: light)').matches") # → False -page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches") ``` ```csharp @@ -1256,8 +1249,6 @@ await page.EvaluateAsync("matchMedia('(prefers-color-scheme: dark)').matches"); // → true await page.EvaluateAsync("matchMedia('(prefers-color-scheme: light)').matches"); // → false -await page.EvaluateAsync("matchMedia('(prefers-color-scheme: no-preference)').matches"); -// → false ``` ### option: Page.emulateMedia.media @@ -1281,16 +1272,16 @@ Passing `'Null'` disables CSS media emulation. * langs: js, java - `colorScheme` > -Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing -`null` disables color scheme emulation. +Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. Passing +`null` disables color scheme emulation. `'no-preference'` is deprecated. ### option: Page.emulateMedia.colorScheme * since: v1.9 * langs: csharp, python - `colorScheme` <[ColorScheme]<"light"|"dark"|"no-preference"|"null">> -Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing -`'Null'` disables color scheme emulation. +Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. Passing +`'Null'` disables color scheme emulation. `'no-preference'` is deprecated. ### option: Page.emulateMedia.reducedMotion * since: v1.12 diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 1f9c03d77af35..45ae9b5142aaa 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -639,14 +639,14 @@ If no origin is specified, the username and password are sent to any servers upo * langs: js, java - `colorScheme` > -Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See +Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See [`method: Page.emulateMedia`] for more details. Passing `null` resets emulation to system defaults. Defaults to `'light'`. ## context-option-colorscheme-csharp-python * langs: csharp, python - `colorScheme` <[ColorScheme]<"light"|"dark"|"no-preference"|"null">> -Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See +Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See [`method: Page.emulateMedia`] for more details. Passing `'null'` resets emulation to system defaults. Defaults to `'light'`. ## context-option-reducedMotion diff --git a/docs/src/emulation.md b/docs/src/emulation.md index d1f7bc3400186..375c82471b9d8 100644 --- a/docs/src/emulation.md +++ b/docs/src/emulation.md @@ -558,7 +558,7 @@ await context.SetGeolocationAsync(new Geolocation() { Longitude = 48.858455, Lat **Note** you can only change geolocation for all pages in the context. ## Color Scheme and Media -Emulate the users `"colorScheme"`. Supported values are 'light', 'dark', 'no-preference'. You can also emulate the media type with [`method: Page.emulateMedia`]. +Emulate the users `"colorScheme"`. Supported values are 'light' and 'dark'. You can also emulate the media type with [`method: Page.emulateMedia`]. ```js title="playwright.config.ts" import { defineConfig } from '@playwright/test'; diff --git a/docs/src/test-use-options-js.md b/docs/src/test-use-options-js.md index c8c93c7cee537..6e1da0a228ce1 100644 --- a/docs/src/test-use-options-js.md +++ b/docs/src/test-use-options-js.md @@ -64,7 +64,7 @@ export default defineConfig({ | Option | Description | | :- | :- | -| [`property: TestOptions.colorScheme`] | [Emulates](./emulation.md#color-scheme-and-media) `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'` | +| [`property: TestOptions.colorScheme`] | [Emulates](./emulation.md#color-scheme-and-media) `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'` | | [`property: TestOptions.geolocation`] | Context [geolocation](./emulation.md#geolocation). | | [`property: TestOptions.locale`] | [Emulates](./emulation.md#locale--timezone) the user locale, for example `en-GB`, `de-DE`, etc. | | [`property: TestOptions.permissions`] | A list of [permissions](./emulation.md#permissions) to grant to all pages in the context. | diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 1f165c3d93fdb..2954591998524 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -2553,16 +2553,14 @@ export interface Page { * // → true * await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches); * // → false - * await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches); - * // → false * ``` * * @param options */ emulateMedia(options?: { /** - * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. - * Passing `null` disables color scheme emulation. + * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. Passing `null` + * disables color scheme emulation. `'no-preference'` is deprecated. */ colorScheme?: null|"light"|"dark"|"no-preference"; @@ -9761,7 +9759,7 @@ export interface Browser { }>; /** - * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See + * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) for more details. * Passing `null` resets emulation to system defaults. Defaults to `'light'`. */ @@ -14726,7 +14724,7 @@ export interface BrowserType { }>; /** - * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See + * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) for more details. * Passing `null` resets emulation to system defaults. Defaults to `'light'`. */ @@ -16522,7 +16520,7 @@ export interface AndroidDevice { bypassCSP?: boolean; /** - * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See + * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) for more details. * Passing `null` resets emulation to system defaults. Defaults to `'light'`. */ @@ -18998,7 +18996,7 @@ export interface Electron { bypassCSP?: boolean; /** - * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See + * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) for more details. * Passing `null` resets emulation to system defaults. Defaults to `'light'`. */ @@ -21820,7 +21818,7 @@ export interface BrowserContextOptions { }>; /** - * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See + * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) for more details. * Passing `null` resets emulation to system defaults. Defaults to `'light'`. */ diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 400d7cbcf3eef..e55ceffc05524 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -5225,7 +5225,7 @@ export interface PlaywrightTestOptions { */ bypassCSP: boolean; /** - * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See + * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'` and `'dark'`. See * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) for more details. * Passing `null` resets emulation to system defaults. Defaults to `'light'`. *