Skip to content

Commit

Permalink
chore: expose channel name literals for types (#5922)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Mar 23, 2021
1 parent f70eaf4 commit 543582b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 55 deletions.
28 changes: 6 additions & 22 deletions docs/src/api/class-browsertype.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
Expand Down Expand Up @@ -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]>
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/protocol/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 22 additions & 2 deletions src/protocol/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/playwright.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down
24 changes: 4 additions & 20 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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`.
Expand Down

0 comments on commit 543582b

Please sign in to comment.