feat(rpc): move leftover extraHTTPHeaders to HeadersArray (#2980)
This commit is contained in:
parent
439e048a4c
commit
b890569afc
|
|
@ -18,6 +18,25 @@ import { EventEmitter } from 'events';
|
||||||
import * as types from '../types';
|
import * as types from '../types';
|
||||||
|
|
||||||
export type Binary = string;
|
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 {
|
export interface Channel extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
@ -41,11 +60,12 @@ export interface SelectorsChannel extends Channel {
|
||||||
export type SelectorsInitializer = {};
|
export type SelectorsInitializer = {};
|
||||||
|
|
||||||
|
|
||||||
|
export type LaunchPersistentContextOptions = { userDataDir: string } & types.LaunchOptions & BrowserContextOptions;
|
||||||
export interface BrowserTypeChannel extends Channel {
|
export interface BrowserTypeChannel extends Channel {
|
||||||
connect(params: types.ConnectOptions): Promise<{ browser: BrowserChannel }>;
|
connect(params: types.ConnectOptions): Promise<{ browser: BrowserChannel }>;
|
||||||
launch(params: types.LaunchOptions): Promise<{ browser: BrowserChannel }>;
|
launch(params: types.LaunchOptions): Promise<{ browser: BrowserChannel }>;
|
||||||
launchServer(params: types.LaunchServerOptions): Promise<{ server: BrowserServerChannel }>;
|
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 = {
|
export type BrowserTypeInitializer = {
|
||||||
executablePath: string,
|
executablePath: string,
|
||||||
|
|
@ -69,7 +89,7 @@ export interface BrowserChannel extends Channel {
|
||||||
on(event: 'close', callback: () => void): this;
|
on(event: 'close', callback: () => void): this;
|
||||||
|
|
||||||
close(): Promise<void>;
|
close(): Promise<void>;
|
||||||
newContext(params: types.BrowserContextOptions): Promise<{ context: BrowserContextChannel }>;
|
newContext(params: BrowserContextOptions): Promise<{ context: BrowserContextChannel }>;
|
||||||
|
|
||||||
crNewBrowserCDPSession(): Promise<{ session: CDPSessionChannel }>;
|
crNewBrowserCDPSession(): Promise<{ session: CDPSessionChannel }>;
|
||||||
crStartTracing(params: { page?: PageChannel, path?: string, screenshots?: boolean, categories?: string[] }): Promise<void>;
|
crStartTracing(params: { page?: PageChannel, path?: string, screenshots?: boolean, categories?: string[] }): Promise<void>;
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as types from '../../types';
|
import * as types from '../../types';
|
||||||
import { BrowserChannel, BrowserInitializer } from '../channels';
|
import { BrowserChannel, BrowserInitializer, BrowserContextOptions } from '../channels';
|
||||||
import { BrowserContext } from './browserContext';
|
import { BrowserContext } from './browserContext';
|
||||||
import { Page } from './page';
|
import { Page } from './page';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
import { Events } from '../../events';
|
import { Events } from '../../events';
|
||||||
import { LoggerSink } from '../../loggerSink';
|
import { LoggerSink } from '../../loggerSink';
|
||||||
import { BrowserType } from './browserType';
|
import { BrowserType } from './browserType';
|
||||||
|
import { headersObjectToArray } from '../serializers';
|
||||||
|
|
||||||
export class Browser extends ChannelOwner<BrowserChannel, BrowserInitializer> {
|
export class Browser extends ChannelOwner<BrowserChannel, BrowserInitializer> {
|
||||||
readonly _contexts = new Set<BrowserContext>();
|
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> {
|
async newContext(options: types.BrowserContextOptions & { logger?: LoggerSink } = {}): Promise<BrowserContext> {
|
||||||
const logger = options.logger;
|
const logger = options.logger;
|
||||||
options = { ...options, logger: undefined };
|
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);
|
this._contexts.add(context);
|
||||||
context._logger = logger || this._logger;
|
context._logger = logger || this._logger;
|
||||||
return context;
|
return context;
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as types from '../../types';
|
import * as types from '../../types';
|
||||||
import { BrowserTypeChannel, BrowserTypeInitializer } from '../channels';
|
import { BrowserTypeChannel, BrowserTypeInitializer, LaunchPersistentContextOptions } from '../channels';
|
||||||
import { Browser } from './browser';
|
import { Browser } from './browser';
|
||||||
import { BrowserContext } from './browserContext';
|
import { BrowserContext } from './browserContext';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
import { BrowserServer } from './browserServer';
|
import { BrowserServer } from './browserServer';
|
||||||
import { LoggerSink } from '../../loggerSink';
|
import { LoggerSink } from '../../loggerSink';
|
||||||
|
import { headersObjectToArray } from '../serializers';
|
||||||
|
|
||||||
export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeInitializer> {
|
export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeInitializer> {
|
||||||
|
|
||||||
|
|
@ -62,7 +63,12 @@ export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeIni
|
||||||
const logger = options.logger;
|
const logger = options.logger;
|
||||||
options = { ...options, logger: undefined };
|
options = { ...options, logger: undefined };
|
||||||
return this._wrapApiCall('browserType.launchPersistentContext', async () => {
|
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);
|
const context = BrowserContext.from(result.context);
|
||||||
context._logger = logger;
|
context._logger = logger;
|
||||||
return context;
|
return context;
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@
|
||||||
import { Browser, BrowserBase } from '../../browser';
|
import { Browser, BrowserBase } from '../../browser';
|
||||||
import { BrowserContextBase } from '../../browserContext';
|
import { BrowserContextBase } from '../../browserContext';
|
||||||
import { Events } from '../../events';
|
import { Events } from '../../events';
|
||||||
import * as types from '../../types';
|
import { BrowserChannel, BrowserContextChannel, BrowserInitializer, CDPSessionChannel, Binary, BrowserContextOptions } from '../channels';
|
||||||
import { BrowserChannel, BrowserContextChannel, BrowserInitializer, CDPSessionChannel, Binary } from '../channels';
|
|
||||||
import { BrowserContextDispatcher } from './browserContextDispatcher';
|
import { BrowserContextDispatcher } from './browserContextDispatcher';
|
||||||
import { CDPSessionDispatcher } from './cdpSessionDispatcher';
|
import { CDPSessionDispatcher } from './cdpSessionDispatcher';
|
||||||
import { Dispatcher, DispatcherScope } from './dispatcher';
|
import { Dispatcher, DispatcherScope } from './dispatcher';
|
||||||
import { CRBrowser } from '../../chromium/crBrowser';
|
import { CRBrowser } from '../../chromium/crBrowser';
|
||||||
import { PageDispatcher } from './pageDispatcher';
|
import { PageDispatcher } from './pageDispatcher';
|
||||||
|
import { headersArrayToObject } from '../serializers';
|
||||||
|
|
||||||
export class BrowserDispatcher extends Dispatcher<Browser, BrowserInitializer> implements BrowserChannel {
|
export class BrowserDispatcher extends Dispatcher<Browser, BrowserInitializer> implements BrowserChannel {
|
||||||
constructor(scope: DispatcherScope, browser: BrowserBase) {
|
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 }> {
|
async newContext(params: BrowserContextOptions): Promise<{ context: BrowserContextChannel }> {
|
||||||
return { context: new BrowserContextDispatcher(this._scope, await this._object.newContext(params) as BrowserContextBase) };
|
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> {
|
async close(): Promise<void> {
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,12 @@ import { BrowserBase } from '../../browser';
|
||||||
import { BrowserTypeBase, BrowserType } from '../../server/browserType';
|
import { BrowserTypeBase, BrowserType } from '../../server/browserType';
|
||||||
import * as types from '../../types';
|
import * as types from '../../types';
|
||||||
import { BrowserDispatcher } from './browserDispatcher';
|
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 { Dispatcher, DispatcherScope } from './dispatcher';
|
||||||
import { BrowserContextBase } from '../../browserContext';
|
import { BrowserContextBase } from '../../browserContext';
|
||||||
import { BrowserContextDispatcher } from './browserContextDispatcher';
|
import { BrowserContextDispatcher } from './browserContextDispatcher';
|
||||||
import { BrowserServerDispatcher } from './browserServerDispatcher';
|
import { BrowserServerDispatcher } from './browserServerDispatcher';
|
||||||
|
import { headersArrayToObject } from '../serializers';
|
||||||
|
|
||||||
export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeInitializer> implements BrowserTypeChannel {
|
export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeInitializer> implements BrowserTypeChannel {
|
||||||
constructor(scope: DispatcherScope, browserType: BrowserTypeBase) {
|
constructor(scope: DispatcherScope, browserType: BrowserTypeBase) {
|
||||||
|
|
@ -37,8 +38,12 @@ export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeIn
|
||||||
return { browser: new BrowserDispatcher(this._scope, browser as BrowserBase) };
|
return { browser: new BrowserDispatcher(this._scope, browser as BrowserBase) };
|
||||||
}
|
}
|
||||||
|
|
||||||
async launchPersistentContext(params: { userDataDir: string } & types.LaunchOptions & types.BrowserContextOptions): Promise<{ context: BrowserContextChannel }> {
|
async launchPersistentContext(params: LaunchPersistentContextOptions): Promise<{ context: BrowserContextChannel }> {
|
||||||
const browserContext = await this._object.launchPersistentContext(params.userDataDir, params);
|
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) };
|
return { context: new BrowserContextDispatcher(this._scope, browserContext as BrowserContextBase) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue