Skip to content

Commit

Permalink
chore: make emulate media params be options (#5172)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Jan 27, 2021
1 parent 5272866 commit ff6b2b1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/src/api/class-cdpsession.md
@@ -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:
Expand Down
20 changes: 11 additions & 9 deletions docs/src/api/class-page.md
Expand Up @@ -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]>
Expand Down
16 changes: 0 additions & 16 deletions docs/src/api/python.md
Expand Up @@ -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]>
Expand Down
6 changes: 3 additions & 3 deletions src/client/page.ts
Expand Up @@ -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,
});
});
}
Expand Down
25 changes: 12 additions & 13 deletions types/types.d.ts
Expand Up @@ -1607,21 +1607,20 @@ export interface Page {
* // → false
* ```
*
* @param params
* @param options
*/
emulateMedia(params: {
emulateMedia(options?: {
/**
* 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.
* Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing
* `null` disables color scheme emulation.
*/
media?: null|"screen"|"print";
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.
* Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null`
* disables CSS media emulation.
*/
colorScheme?: null|"light"|"dark"|"no-preference";
media?: null|"screen"|"print";
}): Promise<void>;

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit ff6b2b1

Please sign in to comment.