Skip to content

Commit 93056ed

Browse files
authored
chore(rpc): more protocol nits (#3246)
1 parent 421f6f4 commit 93056ed

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

docs/api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Indicates that the browser is connected.
217217
- `httpCredentials` <[Object]> Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
218218
- `username` <[string]>
219219
- `password` <[string]>
220-
- `colorScheme` <"dark"|"light"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
220+
- `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
221221
- `logger` <[Logger]> Logger sink for Playwright logging.
222222
- returns: <[Promise]<[BrowserContext]>>
223223

@@ -259,7 +259,7 @@ Creates a new browser context. It won't share cookies/cache with other browser c
259259
- `httpCredentials` <[Object]> Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
260260
- `username` <[string]>
261261
- `password` <[string]>
262-
- `colorScheme` <"dark"|"light"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
262+
- `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
263263
- `logger` <[Logger]> Logger sink for Playwright logging.
264264
- returns: <[Promise]<[Page]>>
265265

@@ -1145,8 +1145,8 @@ await page.dispatchEvent('#source', 'dragstart', { dataTransfer });
11451145

11461146
#### page.emulateMedia(options)
11471147
- `options` <[Object]>
1148-
- `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. Omitting `media` or passing `undefined` does not change the emulated value.
1149-
- `colorScheme` <?"dark"|"light"|"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.
1148+
- `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.
1149+
- `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.
11501150
- returns: <[Promise]>
11511151

11521152
```js
@@ -4074,7 +4074,7 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
40744074
- `httpCredentials` <[Object]> Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
40754075
- `username` <[string]>
40764076
- `password` <[string]>
4077-
- `colorScheme` <"dark"|"light"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
4077+
- `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
40784078
- returns: <[Promise]<[BrowserContext]>> Promise that resolves to the persistent browser context instance.
40794079

40804080
Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing this context will automatically close the browser.

src/rpc/channels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export type BrowserTypeLaunchPersistentContextParams = {
317317
deviceScaleFactor?: number,
318318
isMobile?: boolean,
319319
hasTouch?: boolean,
320-
colorScheme?: 'dark' | 'light' | 'no-preference',
320+
colorScheme?: 'light' | 'dark' | 'no-preference',
321321
acceptDownloads?: boolean,
322322
};
323323
export type BrowserTypeLaunchPersistentContextOptions = {
@@ -372,7 +372,7 @@ export type BrowserTypeLaunchPersistentContextOptions = {
372372
deviceScaleFactor?: number,
373373
isMobile?: boolean,
374374
hasTouch?: boolean,
375-
colorScheme?: 'dark' | 'light' | 'no-preference',
375+
colorScheme?: 'light' | 'dark' | 'no-preference',
376376
acceptDownloads?: boolean,
377377
};
378378
export type BrowserTypeLaunchPersistentContextResult = {

src/rpc/protocol.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ BrowserType:
329329
colorScheme:
330330
type: enum?
331331
literals:
332-
- dark
333332
- light
333+
- dark
334334
- no-preference
335335
acceptDownloads: boolean?
336336
returns:

src/rpc/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
208208
deviceScaleFactor: tOptional(tNumber),
209209
isMobile: tOptional(tBoolean),
210210
hasTouch: tOptional(tBoolean),
211-
colorScheme: tOptional(tEnum(['dark', 'light', 'no-preference'])),
211+
colorScheme: tOptional(tEnum(['light', 'dark', 'no-preference'])),
212212
acceptDownloads: tOptional(tBoolean),
213213
});
214214
scheme.BrowserServerCloseParams = tOptional(tObject({}));

utils/doclint/dumpTypes.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const playwright = require('../../');
18+
const path = require('path');
19+
const Source = require('./Source');
20+
const mdBuilder = require('./check_public_api/MDBuilder');
21+
const PROJECT_DIR = path.join(__dirname, '..', '..');
22+
23+
(async () => {
24+
const api = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'api.md'));
25+
const browser = await playwright.chromium.launch();
26+
const page = await browser.newPage();
27+
const { documentation } = await mdBuilder(page, [api]);
28+
const result = serialize(documentation);
29+
console.log(JSON.stringify(result, undefined, 2));
30+
await browser.close();
31+
})()
32+
33+
function serialize(documentation) {
34+
const result = {};
35+
for (const clazz of documentation.classesArray)
36+
result[clazz.name] = serializeClass(clazz);
37+
return result;
38+
}
39+
40+
function serializeClass(clazz) {
41+
const result = { name: clazz.name };
42+
result.members = {};
43+
for (const member of clazz.membersArray)
44+
result.members[member.name] = serializeMember(member);
45+
return result;
46+
}
47+
48+
function serializeMember(member) {
49+
const result = { ...member };
50+
delete result.args;
51+
delete result.argsArray;
52+
result.args = {};
53+
for (const arg of member.argsArray)
54+
result.args[arg.name] = serializeProperty(arg);
55+
if (member.type)
56+
result.type = serializeType(member.type)
57+
return result;
58+
}
59+
60+
function serializeProperty(arg) {
61+
const result = { ...arg };
62+
delete result.args;
63+
delete result.argsArray;
64+
if (arg.type)
65+
result.type = serializeType(arg.type)
66+
return result;
67+
}
68+
69+
function serializeType(type) {
70+
const result = { ...type };
71+
if (type.properties) {
72+
result.properties = {};
73+
for (const prop of type.properties)
74+
result.properties[prop.name] = serializeProperty(prop);
75+
}
76+
return result;
77+
}

0 commit comments

Comments
 (0)