chore: make emulate media params be options (#5172)

This commit is contained in:
Pavel Feldman 2021-01-27 14:19:37 -08:00 committed by GitHub
parent 527286683f
commit ff6b2b1dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 43 deletions

View File

@ -1,5 +1,5 @@
# class: CDPSession
* langs: js, python
* langs: js,python
* extends: [EventEmitter]
The `CDPSession` instances are used to talk raw Chrome Devtools Protocol:

View File

@ -818,15 +818,17 @@ page.evaluate("matchMedia('(prefers-color-scheme: light)').matches")
page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches")
```
### param: Page.emulateMedia.params
* langs: js
- `params` <[Object]>
- `media` <[null]|"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. Omitting `media` or passing
`undefined` does not change the emulated value. Optional.
- `colorScheme` <[null]|"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature,
supported values are `'light'`, `'dark'`, `'no-preference'`. Passing `null` disables color scheme emulation.
Omitting `colorScheme` or passing `undefined` does not change the emulated value. Optional.
### option: Page.emulateMedia.media
- `media` <[null]|"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.
### option: Page.emulateMedia.colorScheme
- `colorScheme` <[null]|"light"|"dark"|"no-preference">
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing
`null` disables color scheme emulation.
## async method: Page.evaluate
- returns: <[Serializable]>

View File

@ -57,22 +57,6 @@ Script to be evaluated in all pages in the browser context. Optional.
### param: Page.selectOption.value = %%-python-select-options-value-%%
### param: Page.selectOption.label = %%-python-select-options-label-%%
### param: Page.emulateMedia.params
* langs: python
- `media` <[null]|"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. Omitting `media` or passing `undefined` does not change the emulated value.
Optional.
### param: Page.emulateMedia.params
* langs: python
- `colorScheme` <[null]|"light"|"dark"|"no-preference">
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing
`null` disables color scheme emulation. Omitting `colorScheme` or passing `undefined` does not change the emulated
value. Optional.
### option: Page.frame.name
* langs: python
- `name` <[string]>

View File

@ -420,11 +420,11 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
});
}
async emulateMedia(params: { media?: 'screen' | 'print' | null, colorScheme?: 'dark' | 'light' | 'no-preference' | null } = {}) {
async emulateMedia(options: { media?: 'screen' | 'print' | null, colorScheme?: 'dark' | 'light' | 'no-preference' | null } = {}) {
return this._wrapApiCall('page.emulateMedia', async () => {
await this._channel.emulateMedia({
media: params.media === null ? 'null' : params.media,
colorScheme: params.colorScheme === null ? 'null' : params.colorScheme,
media: options.media === null ? 'null' : options.media,
colorScheme: options.colorScheme === null ? 'null' : options.colorScheme,
});
});
}

27
types/types.d.ts vendored
View File

@ -1607,21 +1607,20 @@ export interface Page {
* // → false
* ```
*
* @param params
* @param options
*/
emulateMedia(params: {
/**
* Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null`
* disables CSS media emulation. Omitting `media` or passing `undefined` does not change the emulated value. Optional.
*/
media?: null|"screen"|"print";
emulateMedia(options?: {
/**
* Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing
* `null` disables color scheme emulation. Omitting `colorScheme` or passing `undefined` does not change the emulated
* value. Optional.
* `null` disables color scheme emulation.
*/
colorScheme?: null|"light"|"dark"|"no-preference";
/**
* Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null`
* disables CSS media emulation.
*/
media?: null|"screen"|"print";
}): Promise<void>;
/**
@ -2062,7 +2061,7 @@ export interface Page {
* > NOTE: Generating a pdf is currently only supported in Chromium headless.
*
* `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
* [page.emulateMedia(params)](https://playwright.dev/docs/api/class-page#pageemulatemediaparams) before calling
* [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) before calling
* `page.pdf()`:
*
* > NOTE: By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
@ -6264,7 +6263,7 @@ export interface BrowserType<Browser> {
/**
* Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
* [page.emulateMedia(params)](https://playwright.dev/docs/api/class-page#pageemulatemediaparams) for more details.
* [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) for more details.
* Defaults to '`light`'.
*/
colorScheme?: "light"|"dark"|"no-preference";
@ -7076,7 +7075,7 @@ export interface Browser extends EventEmitter {
/**
* Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
* [page.emulateMedia(params)](https://playwright.dev/docs/api/class-page#pageemulatemediaparams) for more details.
* [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) for more details.
* Defaults to '`light`'.
*/
colorScheme?: "light"|"dark"|"no-preference";
@ -9096,7 +9095,7 @@ export interface BrowserContextOptions {
/**
* Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
* [page.emulateMedia(params)](https://playwright.dev/docs/api/class-page#pageemulatemediaparams) for more details.
* [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) for more details.
* Defaults to '`light`'.
*/
colorScheme?: "light"|"dark"|"no-preference";