From 543582b4ca29fcb6c246d4283e0abbe3d4f7270c Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 24 Mar 2021 04:21:03 +0800 Subject: [PATCH] chore: expose channel name literals for types (#5922) --- docs/src/api/class-browsertype.md | 28 ++++++---------------------- src/cli/cli.ts | 2 +- src/protocol/channels.ts | 8 ++++---- src/protocol/protocol.yml | 24 ++++++++++++++++++++++-- src/protocol/validator.ts | 4 ++-- src/server/browser.ts | 2 +- src/server/types.ts | 4 +++- test/fixtures.ts | 2 +- test/playwright.fixtures.ts | 2 +- types/types.d.ts | 24 ++++-------------------- 10 files changed, 45 insertions(+), 55 deletions(-) diff --git a/docs/src/api/class-browsertype.md b/docs/src/api/class-browsertype.md index 499fdb5721bd8..8acb3e9453e87 100644 --- a/docs/src/api/class-browsertype.md +++ b/docs/src/api/class-browsertype.md @@ -179,17 +179,9 @@ Whether to run browser in headless mode. More details for [`option: devtools`] option is `true`. ### option: BrowserType.launch.channel -- `channel` <[string]> - -Chromium distribution channel, one of -* chrome -* chrome-beta -* chrome-dev -* chrome-canary -* msedge -* msedge-beta -* msedge-dev -* msedge-canary +- `channel` <[BrowserChannel]<"chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary">> + +Browser distribution channel. ### option: BrowserType.launch.executablePath - `executablePath` <[path]> @@ -300,17 +292,9 @@ Whether to run browser in headless mode. More details for [`option: devtools`] option is `true`. ### option: BrowserType.launchPersistentContext.channel -- `channel` <[string]> - -Chromium distribution channel, one of -* chrome -* chrome-beta -* chrome-dev -* chrome-canary -* msedge -* msedge-beta -* msedge-dev -* msedge-canary +- `channel` <[BrowserChannel]<"chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary">> + +Browser distribution channel. ### option: BrowserType.launchPersistentContext.executablePath - `executablePath` <[path]> diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 95e9b37e72d70..66a778b50050b 100755 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -211,7 +211,7 @@ async function launchContext(options: Options, headless: boolean): Promise<{ bro const browserType = lookupBrowserType(options); const launchOptions: LaunchOptions = { headless }; if (options.channel) - launchOptions.channel = options.channel; + launchOptions.channel = options.channel as any; const contextOptions: BrowserContextOptions = // Copy the device descriptor since we have to compare and modify the options. diff --git a/src/protocol/channels.ts b/src/protocol/channels.ts index 71e097975e6ed..dfdd7cc2bd2ec 100644 --- a/src/protocol/channels.ts +++ b/src/protocol/channels.ts @@ -217,7 +217,7 @@ export interface BrowserTypeChannel extends Channel { connectOverCDP(params: BrowserTypeConnectOverCDPParams, metadata?: Metadata): Promise; } export type BrowserTypeLaunchParams = { - channel?: string, + channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary', executablePath?: string, args?: string[], ignoreAllDefaultArgs?: boolean, @@ -241,7 +241,7 @@ export type BrowserTypeLaunchParams = { slowMo?: number, }; export type BrowserTypeLaunchOptions = { - channel?: string, + channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary', executablePath?: string, args?: string[], ignoreAllDefaultArgs?: boolean, @@ -268,7 +268,7 @@ export type BrowserTypeLaunchResult = { browser: BrowserChannel, }; export type BrowserTypeLaunchPersistentContextParams = { - channel?: string, + channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary', userDataDir: string, sdkLanguage: string, executablePath?: string, @@ -334,7 +334,7 @@ export type BrowserTypeLaunchPersistentContextParams = { }, }; export type BrowserTypeLaunchPersistentContextOptions = { - channel?: string, + channel?: 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary', executablePath?: string, args?: string[], ignoreAllDefaultArgs?: boolean, diff --git a/src/protocol/protocol.yml b/src/protocol/protocol.yml index 10cb67349bb40..022e586395fc0 100644 --- a/src/protocol/protocol.yml +++ b/src/protocol/protocol.yml @@ -300,7 +300,17 @@ BrowserType: launch: parameters: - channel: string? + channel: + type: enum? + literals: + - chrome + - chrome-beta + - chrome-dev + - chrome-canary + - msedge + - msedge-beta + - msedge-dev + - msedge-canary executablePath: string? args: type: array? @@ -334,7 +344,17 @@ BrowserType: launchPersistentContext: parameters: - channel: string? + channel: + type: enum? + literals: + - chrome + - chrome-beta + - chrome-dev + - chrome-canary + - msedge + - msedge-beta + - msedge-dev + - msedge-canary userDataDir: string sdkLanguage: string executablePath: string? diff --git a/src/protocol/validator.ts b/src/protocol/validator.ts index 634a89e894033..f45740d441479 100644 --- a/src/protocol/validator.ts +++ b/src/protocol/validator.ts @@ -154,7 +154,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme { contentScript: tOptional(tBoolean), }); scheme.BrowserTypeLaunchParams = tObject({ - channel: tOptional(tString), + channel: tOptional(tEnum(['chrome', 'chrome-beta', 'chrome-dev', 'chrome-canary', 'msedge', 'msedge-beta', 'msedge-dev', 'msedge-canary'])), executablePath: tOptional(tString), args: tOptional(tArray(tString)), ignoreAllDefaultArgs: tOptional(tBoolean), @@ -178,7 +178,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme { slowMo: tOptional(tNumber), }); scheme.BrowserTypeLaunchPersistentContextParams = tObject({ - channel: tOptional(tString), + channel: tOptional(tEnum(['chrome', 'chrome-beta', 'chrome-dev', 'chrome-canary', 'msedge', 'msedge-beta', 'msedge-dev', 'msedge-canary'])), userDataDir: tString, sdkLanguage: tString, executablePath: tOptional(tString), diff --git a/src/server/browser.ts b/src/server/browser.ts index faebc1674c019..f3effe352d85e 100644 --- a/src/server/browser.ts +++ b/src/server/browser.ts @@ -39,7 +39,7 @@ export type PlaywrightOptions = { export type BrowserOptions = PlaywrightOptions & { name: string, isChromium: boolean, - channel?: string, + channel?: types.BrowserChannel, downloadsPath?: string, headful?: boolean, persistent?: types.BrowserContextOptions, // Undefined means no persistent context. diff --git a/src/server/types.ts b/src/server/types.ts index 7e00b8d2533a6..bba4f8e725dec 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -249,8 +249,10 @@ export type BrowserContextOptions = { export type EnvArray = { name: string, value: string }[]; +export type BrowserChannel = 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary'; + type LaunchOptionsBase = { - channel?: string, + channel?: BrowserChannel, executablePath?: string, args?: string[], ignoreDefaultArgs?: string[], diff --git a/test/fixtures.ts b/test/fixtures.ts index 026c3145e8682..1c14ed629b47c 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -94,7 +94,7 @@ fixtures.browserOptions.override(async ({ browserName, headful, slowMo, browserC if (executablePath) console.error(`Using executable at ${executablePath}`); await run({ - channel: browserChannel, + channel: browserChannel as any, executablePath, handleSIGINT: false, slowMo, diff --git a/test/playwright.fixtures.ts b/test/playwright.fixtures.ts index 7b2bcdcbd7c62..cc214d87d2eb4 100644 --- a/test/playwright.fixtures.ts +++ b/test/playwright.fixtures.ts @@ -103,7 +103,7 @@ fixtures.browserOptions.init(async ({ headful, slowMo, browserChannel }, run) => handleSIGINT: false, slowMo, headless: !headful, - channel: browserChannel, + channel: browserChannel as any, }); }, { scope: 'worker' }); diff --git a/types/types.d.ts b/types/types.d.ts index 7db7ddc08bbf4..8d3196bb0a22c 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -6357,17 +6357,9 @@ export interface BrowserType { bypassCSP?: boolean; /** - * Chromium distribution channel, one of - * - chrome - * - chrome-beta - * - chrome-dev - * - chrome-canary - * - msedge - * - msedge-beta - * - msedge-dev - * - msedge-canary + * Browser distribution channel. */ - channel?: string; + channel?: "chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary"; /** * Enable Chromium sandboxing. Defaults to `true`. @@ -10659,17 +10651,9 @@ export interface LaunchOptions { args?: Array; /** - * Chromium distribution channel, one of - * - chrome - * - chrome-beta - * - chrome-dev - * - chrome-canary - * - msedge - * - msedge-beta - * - msedge-dev - * - msedge-canary + * Browser distribution channel. */ - channel?: string; + channel?: "chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary"; /** * Enable Chromium sandboxing. Defaults to `false`.