Skip to content

Commit 543582b

Browse files
authored
chore: expose channel name literals for types (#5922)
1 parent f70eaf4 commit 543582b

File tree

10 files changed

+45
-55
lines changed

10 files changed

+45
-55
lines changed

docs/src/api/class-browsertype.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,9 @@ Whether to run browser in headless mode. More details for
179179
[`option: devtools`] option is `true`.
180180

181181
### option: BrowserType.launch.channel
182-
- `channel` <[string]>
183-
184-
Chromium distribution channel, one of
185-
* chrome
186-
* chrome-beta
187-
* chrome-dev
188-
* chrome-canary
189-
* msedge
190-
* msedge-beta
191-
* msedge-dev
192-
* msedge-canary
182+
- `channel` <[BrowserChannel]<"chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary">>
183+
184+
Browser distribution channel.
193185

194186
### option: BrowserType.launch.executablePath
195187
- `executablePath` <[path]>
@@ -300,17 +292,9 @@ Whether to run browser in headless mode. More details for
300292
[`option: devtools`] option is `true`.
301293

302294
### option: BrowserType.launchPersistentContext.channel
303-
- `channel` <[string]>
304-
305-
Chromium distribution channel, one of
306-
* chrome
307-
* chrome-beta
308-
* chrome-dev
309-
* chrome-canary
310-
* msedge
311-
* msedge-beta
312-
* msedge-dev
313-
* msedge-canary
295+
- `channel` <[BrowserChannel]<"chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary">>
296+
297+
Browser distribution channel.
314298

315299
### option: BrowserType.launchPersistentContext.executablePath
316300
- `executablePath` <[path]>

src/cli/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async function launchContext(options: Options, headless: boolean): Promise<{ bro
211211
const browserType = lookupBrowserType(options);
212212
const launchOptions: LaunchOptions = { headless };
213213
if (options.channel)
214-
launchOptions.channel = options.channel;
214+
launchOptions.channel = options.channel as any;
215215

216216
const contextOptions: BrowserContextOptions =
217217
// Copy the device descriptor since we have to compare and modify the options.

src/protocol/channels.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export interface BrowserTypeChannel extends Channel {
217217
connectOverCDP(params: BrowserTypeConnectOverCDPParams, metadata?: Metadata): Promise<BrowserTypeConnectOverCDPResult>;
218218
}
219219
export type BrowserTypeLaunchParams = {
220-
channel?: string,
220+
channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary',
221221
executablePath?: string,
222222
args?: string[],
223223
ignoreAllDefaultArgs?: boolean,
@@ -241,7 +241,7 @@ export type BrowserTypeLaunchParams = {
241241
slowMo?: number,
242242
};
243243
export type BrowserTypeLaunchOptions = {
244-
channel?: string,
244+
channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary',
245245
executablePath?: string,
246246
args?: string[],
247247
ignoreAllDefaultArgs?: boolean,
@@ -268,7 +268,7 @@ export type BrowserTypeLaunchResult = {
268268
browser: BrowserChannel,
269269
};
270270
export type BrowserTypeLaunchPersistentContextParams = {
271-
channel?: string,
271+
channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary',
272272
userDataDir: string,
273273
sdkLanguage: string,
274274
executablePath?: string,
@@ -334,7 +334,7 @@ export type BrowserTypeLaunchPersistentContextParams = {
334334
},
335335
};
336336
export type BrowserTypeLaunchPersistentContextOptions = {
337-
channel?: string,
337+
channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary',
338338
executablePath?: string,
339339
args?: string[],
340340
ignoreAllDefaultArgs?: boolean,

src/protocol/protocol.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,17 @@ BrowserType:
300300

301301
launch:
302302
parameters:
303-
channel: string?
303+
channel:
304+
type: enum?
305+
literals:
306+
- chrome
307+
- chrome-beta
308+
- chrome-dev
309+
- chrome-canary
310+
- msedge
311+
- msedge-beta
312+
- msedge-dev
313+
- msedge-canary
304314
executablePath: string?
305315
args:
306316
type: array?
@@ -334,7 +344,17 @@ BrowserType:
334344

335345
launchPersistentContext:
336346
parameters:
337-
channel: string?
347+
channel:
348+
type: enum?
349+
literals:
350+
- chrome
351+
- chrome-beta
352+
- chrome-dev
353+
- chrome-canary
354+
- msedge
355+
- msedge-beta
356+
- msedge-dev
357+
- msedge-canary
338358
userDataDir: string
339359
sdkLanguage: string
340360
executablePath: string?

src/protocol/validator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
154154
contentScript: tOptional(tBoolean),
155155
});
156156
scheme.BrowserTypeLaunchParams = tObject({
157-
channel: tOptional(tString),
157+
channel: tOptional(tEnum(['chrome', 'chrome-beta', 'chrome-dev', 'chrome-canary', 'msedge', 'msedge-beta', 'msedge-dev', 'msedge-canary'])),
158158
executablePath: tOptional(tString),
159159
args: tOptional(tArray(tString)),
160160
ignoreAllDefaultArgs: tOptional(tBoolean),
@@ -178,7 +178,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
178178
slowMo: tOptional(tNumber),
179179
});
180180
scheme.BrowserTypeLaunchPersistentContextParams = tObject({
181-
channel: tOptional(tString),
181+
channel: tOptional(tEnum(['chrome', 'chrome-beta', 'chrome-dev', 'chrome-canary', 'msedge', 'msedge-beta', 'msedge-dev', 'msedge-canary'])),
182182
userDataDir: tString,
183183
sdkLanguage: tString,
184184
executablePath: tOptional(tString),

src/server/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export type PlaywrightOptions = {
3939
export type BrowserOptions = PlaywrightOptions & {
4040
name: string,
4141
isChromium: boolean,
42-
channel?: string,
42+
channel?: types.BrowserChannel,
4343
downloadsPath?: string,
4444
headful?: boolean,
4545
persistent?: types.BrowserContextOptions, // Undefined means no persistent context.

src/server/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ export type BrowserContextOptions = {
249249

250250
export type EnvArray = { name: string, value: string }[];
251251

252+
export type BrowserChannel = 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary';
253+
252254
type LaunchOptionsBase = {
253-
channel?: string,
255+
channel?: BrowserChannel,
254256
executablePath?: string,
255257
args?: string[],
256258
ignoreDefaultArgs?: string[],

test/fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fixtures.browserOptions.override(async ({ browserName, headful, slowMo, browserC
9494
if (executablePath)
9595
console.error(`Using executable at ${executablePath}`);
9696
await run({
97-
channel: browserChannel,
97+
channel: browserChannel as any,
9898
executablePath,
9999
handleSIGINT: false,
100100
slowMo,

test/playwright.fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fixtures.browserOptions.init(async ({ headful, slowMo, browserChannel }, run) =>
103103
handleSIGINT: false,
104104
slowMo,
105105
headless: !headful,
106-
channel: browserChannel,
106+
channel: browserChannel as any,
107107
});
108108
}, { scope: 'worker' });
109109

types/types.d.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6357,17 +6357,9 @@ export interface BrowserType<Browser> {
63576357
bypassCSP?: boolean;
63586358

63596359
/**
6360-
* Chromium distribution channel, one of
6361-
* - chrome
6362-
* - chrome-beta
6363-
* - chrome-dev
6364-
* - chrome-canary
6365-
* - msedge
6366-
* - msedge-beta
6367-
* - msedge-dev
6368-
* - msedge-canary
6360+
* Browser distribution channel.
63696361
*/
6370-
channel?: string;
6362+
channel?: "chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary";
63716363

63726364
/**
63736365
* Enable Chromium sandboxing. Defaults to `true`.
@@ -10659,17 +10651,9 @@ export interface LaunchOptions {
1065910651
args?: Array<string>;
1066010652

1066110653
/**
10662-
* Chromium distribution channel, one of
10663-
* - chrome
10664-
* - chrome-beta
10665-
* - chrome-dev
10666-
* - chrome-canary
10667-
* - msedge
10668-
* - msedge-beta
10669-
* - msedge-dev
10670-
* - msedge-canary
10654+
* Browser distribution channel.
1067110655
*/
10672-
channel?: string;
10656+
channel?: "chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary";
1067310657

1067410658
/**
1067510659
* Enable Chromium sandboxing. Defaults to `false`.

0 commit comments

Comments
 (0)