chore: expose channel name literals for types (#5922)

This commit is contained in:
Pavel Feldman 2021-03-24 04:21:03 +08:00 committed by GitHub
parent f70eaf4ff3
commit 543582b4ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 43 additions and 53 deletions

View File

@ -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]>
- `channel` <[BrowserChannel]<"chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary">>
Chromium distribution channel, one of
* 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]>
- `channel` <[BrowserChannel]<"chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary">>
Chromium distribution channel, one of
* chrome
* chrome-beta
* chrome-dev
* chrome-canary
* msedge
* msedge-beta
* msedge-dev
* msedge-canary
Browser distribution channel.
### option: BrowserType.launchPersistentContext.executablePath
- `executablePath` <[path]>

View File

@ -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.

View File

@ -217,7 +217,7 @@ export interface BrowserTypeChannel extends Channel {
connectOverCDP(params: BrowserTypeConnectOverCDPParams, metadata?: Metadata): Promise<BrowserTypeConnectOverCDPResult>;
}
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,

View File

@ -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?

View File

@ -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),

View File

@ -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.

View File

@ -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[],

View File

@ -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,

View File

@ -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' });

24
types/types.d.ts vendored
View File

@ -6357,17 +6357,9 @@ export interface BrowserType<Browser> {
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<string>;
/**
* 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`.