Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(rpc): move leftover extraHTTPHeaders to HeadersArray (#2980)
Dmitry Gozmanb890569afc18
diff --git a/src/rpc/channels.ts b/src/rpc/channels.tsindex f8d62f39df..cdf9cbfd6e 100644--- a/src/rpc/channels.ts+++ b/src/rpc/channels.ts@@ -18,6 +18,25 @@ import { EventEmitter } from 'events';import * as types from '../types';export type Binary = string;+export type BrowserContextOptions = {+ viewport?: types.Size | null,+ ignoreHTTPSErrors?: boolean,+ javaScriptEnabled?: boolean,+ bypassCSP?: boolean,+ userAgent?: string,+ locale?: string,+ timezoneId?: string,+ geolocation?: types.Geolocation,+ permissions?: string[],+ extraHTTPHeaders?: types.HeadersArray,+ offline?: boolean,+ httpCredentials?: types.Credentials,+ deviceScaleFactor?: number,+ isMobile?: boolean,+ hasTouch?: boolean,+ colorScheme?: types.ColorScheme,+ acceptDownloads?: boolean,+};export interface Channel extends EventEmitter {}@@ -41,11 +60,12 @@ export interface SelectorsChannel extends Channel {export type SelectorsInitializer = {};+export type LaunchPersistentContextOptions = { userDataDir: string } & types.LaunchOptions & BrowserContextOptions;export interface BrowserTypeChannel extends Channel {connect(params: types.ConnectOptions): Promise<{ browser: BrowserChannel }>;launch(params: types.LaunchOptions): Promise<{ browser: BrowserChannel }>;launchServer(params: types.LaunchServerOptions): Promise<{ server: BrowserServerChannel }>;- launchPersistentContext(params: { userDataDir: string } & types.LaunchOptions & types.BrowserContextOptions): Promise<{ context: BrowserContextChannel }>;+ launchPersistentContext(params: LaunchPersistentContextOptions): Promise<{ context: BrowserContextChannel }>;}export type BrowserTypeInitializer = {executablePath: string,@@ -69,7 +89,7 @@ export interface BrowserChannel extends Channel {on(event: 'close', callback: () => void): this;close(): Promise<void>;- newContext(params: types.BrowserContextOptions): Promise<{ context: BrowserContextChannel }>;+ newContext(params: BrowserContextOptions): Promise<{ context: BrowserContextChannel }>;crNewBrowserCDPSession(): Promise<{ session: CDPSessionChannel }>;crStartTracing(params: { page?: PageChannel, path?: string, screenshots?: boolean, categories?: string[] }): Promise<void>;diff --git a/src/rpc/client/browser.ts b/src/rpc/client/browser.tsindex 5dedf0634d..0c41df7f95 100644--- a/src/rpc/client/browser.ts+++ b/src/rpc/client/browser.ts@@ -15,13 +15,14 @@*/import * as types from '../../types';-import { BrowserChannel, BrowserInitializer } from '../channels';+import { BrowserChannel, BrowserInitializer, BrowserContextOptions } from '../channels';import { BrowserContext } from './browserContext';import { Page } from './page';import { ChannelOwner } from './channelOwner';import { Events } from '../../events';import { LoggerSink } from '../../loggerSink';import { BrowserType } from './browserType';+import { headersObjectToArray } from '../serializers';export class Browser extends ChannelOwner<BrowserChannel, BrowserInitializer> {readonly _contexts = new Set<BrowserContext>();@@ -53,7 +54,11 @@ export class Browser extends ChannelOwner<BrowserChannel, BrowserInitializer> {async newContext(options: types.BrowserContextOptions & { logger?: LoggerSink } = {}): Promise<BrowserContext> {const logger = options.logger;options = { ...options, logger: undefined };- const context = BrowserContext.from((await this._channel.newContext(options)).context);+ const contextOptions: BrowserContextOptions = {+ ...options,+ extraHTTPHeaders: options.extraHTTPHeaders ? headersObjectToArray(options.extraHTTPHeaders) : undefined,+ };+ const context = BrowserContext.from((await this._channel.newContext(contextOptions)).context);this._contexts.add(context);context._logger = logger || this._logger;return context;diff --git a/src/rpc/client/browserType.ts b/src/rpc/client/browserType.tsindex b4fe0db220..0f403b199e 100644--- a/src/rpc/client/browserType.ts+++ b/src/rpc/client/browserType.ts@@ -15,12 +15,13 @@*/import * as types from '../../types';-import { BrowserTypeChannel, BrowserTypeInitializer } from '../channels';+import { BrowserTypeChannel, BrowserTypeInitializer, LaunchPersistentContextOptions } from '../channels';import { Browser } from './browser';import { BrowserContext } from './browserContext';import { ChannelOwner } from './channelOwner';import { BrowserServer } from './browserServer';import { LoggerSink } from '../../loggerSink';+import { headersObjectToArray } from '../serializers';export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeInitializer> {@@ -62,7 +63,12 @@ export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeIniconst logger = options.logger;options = { ...options, logger: undefined };return this._wrapApiCall('browserType.launchPersistentContext', async () => {- const result = await this._channel.launchPersistentContext({ userDataDir, ...options });+ const persistentOptions: LaunchPersistentContextOptions = {+ ...options,+ extraHTTPHeaders: options.extraHTTPHeaders ? headersObjectToArray(options.extraHTTPHeaders) : undefined,+ userDataDir,+ };+ const result = await this._channel.launchPersistentContext(persistentOptions);const context = BrowserContext.from(result.context);context._logger = logger;return context;diff --git a/src/rpc/server/browserDispatcher.ts b/src/rpc/server/browserDispatcher.tsindex 6729c67793..f8cfa1b3a0 100644--- a/src/rpc/server/browserDispatcher.ts+++ b/src/rpc/server/browserDispatcher.ts@@ -17,13 +17,13 @@import { Browser, BrowserBase } from '../../browser';import { BrowserContextBase } from '../../browserContext';import { Events } from '../../events';-import * as types from '../../types';-import { BrowserChannel, BrowserContextChannel, BrowserInitializer, CDPSessionChannel, Binary } from '../channels';+import { BrowserChannel, BrowserContextChannel, BrowserInitializer, CDPSessionChannel, Binary, BrowserContextOptions } from '../channels';import { BrowserContextDispatcher } from './browserContextDispatcher';import { CDPSessionDispatcher } from './cdpSessionDispatcher';import { Dispatcher, DispatcherScope } from './dispatcher';import { CRBrowser } from '../../chromium/crBrowser';import { PageDispatcher } from './pageDispatcher';+import { headersArrayToObject } from '../serializers';export class BrowserDispatcher extends Dispatcher<Browser, BrowserInitializer> implements BrowserChannel {constructor(scope: DispatcherScope, browser: BrowserBase) {@@ -34,8 +34,12 @@ export class BrowserDispatcher extends Dispatcher<Browser, BrowserInitializer> i});}- async newContext(params: types.BrowserContextOptions): Promise<{ context: BrowserContextChannel }> {- return { context: new BrowserContextDispatcher(this._scope, await this._object.newContext(params) as BrowserContextBase) };+ async newContext(params: BrowserContextOptions): Promise<{ context: BrowserContextChannel }> {+ const options = {+ ...params,+ extraHTTPHeaders: params.extraHTTPHeaders ? headersArrayToObject(params.extraHTTPHeaders) : undefined,+ };+ return { context: new BrowserContextDispatcher(this._scope, await this._object.newContext(options) as BrowserContextBase) };}async close(): Promise<void> {diff --git a/src/rpc/server/browserTypeDispatcher.ts b/src/rpc/server/browserTypeDispatcher.tsindex b9baca8e20..78839448c1 100644--- a/src/rpc/server/browserTypeDispatcher.ts+++ b/src/rpc/server/browserTypeDispatcher.ts@@ -18,11 +18,12 @@ import { BrowserBase } from '../../browser';import { BrowserTypeBase, BrowserType } from '../../server/browserType';import * as types from '../../types';import { BrowserDispatcher } from './browserDispatcher';-import { BrowserChannel, BrowserTypeChannel, BrowserContextChannel, BrowserTypeInitializer, BrowserServerChannel } from '../channels';+import { BrowserChannel, BrowserTypeChannel, BrowserContextChannel, BrowserTypeInitializer, BrowserServerChannel, LaunchPersistentContextOptions } from '../channels';import { Dispatcher, DispatcherScope } from './dispatcher';import { BrowserContextBase } from '../../browserContext';import { BrowserContextDispatcher } from './browserContextDispatcher';import { BrowserServerDispatcher } from './browserServerDispatcher';+import { headersArrayToObject } from '../serializers';export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeInitializer> implements BrowserTypeChannel {constructor(scope: DispatcherScope, browserType: BrowserTypeBase) {@@ -37,8 +38,12 @@ export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeInreturn { browser: new BrowserDispatcher(this._scope, browser as BrowserBase) };}- async launchPersistentContext(params: { userDataDir: string } & types.LaunchOptions & types.BrowserContextOptions): Promise<{ context: BrowserContextChannel }> {- const browserContext = await this._object.launchPersistentContext(params.userDataDir, params);+ async launchPersistentContext(params: LaunchPersistentContextOptions): Promise<{ context: BrowserContextChannel }> {+ const options = {+ ...params,+ extraHTTPHeaders: params.extraHTTPHeaders ? headersArrayToObject(params.extraHTTPHeaders) : undefined,+ };+ const browserContext = await this._object.launchPersistentContext(params.userDataDir, options);return { context: new BrowserContextDispatcher(this._scope, browserContext as BrowserContextBase) };}