chore: merge Browser{Context,}Base into Browser{Context,} (#3524)
This commit is contained in:
		
							parent
							
								
									56da4bb027
								
							
						
					
					
						commit
						745dc339a6
					
				| 
						 | 
				
			
			@ -15,7 +15,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
import * as types from './types';
 | 
			
		||||
import { BrowserContext, BrowserContextBase } from './browserContext';
 | 
			
		||||
import { BrowserContext } from './browserContext';
 | 
			
		||||
import { Page } from './page';
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
import { Download } from './download';
 | 
			
		||||
| 
						 | 
				
			
			@ -39,19 +39,10 @@ export type BrowserOptions = types.UIOptions & {
 | 
			
		|||
  proxy?: ProxySettings,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export interface Browser extends EventEmitter {
 | 
			
		||||
  newContext(options?: types.BrowserContextOptions): Promise<BrowserContext>;
 | 
			
		||||
  contexts(): BrowserContext[];
 | 
			
		||||
  newPage(options?: types.BrowserContextOptions): Promise<Page>;
 | 
			
		||||
  isConnected(): boolean;
 | 
			
		||||
  close(): Promise<void>;
 | 
			
		||||
  version(): string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export abstract class BrowserBase extends EventEmitter implements Browser {
 | 
			
		||||
export abstract class Browser extends EventEmitter {
 | 
			
		||||
  readonly _options: BrowserOptions;
 | 
			
		||||
  private _downloads = new Map<string, Download>();
 | 
			
		||||
  _defaultContext: BrowserContextBase | null = null;
 | 
			
		||||
  _defaultContext: BrowserContext | null = null;
 | 
			
		||||
  private _startedClosing = false;
 | 
			
		||||
 | 
			
		||||
  constructor(options: BrowserOptions) {
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +84,7 @@ export abstract class BrowserBase extends EventEmitter implements Browser {
 | 
			
		|||
 | 
			
		||||
  _didClose() {
 | 
			
		||||
    for (const context of this.contexts())
 | 
			
		||||
      (context as BrowserContextBase)._browserClosed();
 | 
			
		||||
      context._browserClosed();
 | 
			
		||||
    if (this._defaultContext)
 | 
			
		||||
      this._defaultContext._browserClosed();
 | 
			
		||||
    this.emit(Events.Browser.Disconnected);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,32 +23,12 @@ import * as frames from './frames';
 | 
			
		|||
import * as types from './types';
 | 
			
		||||
import { Events } from './events';
 | 
			
		||||
import { Download } from './download';
 | 
			
		||||
import { BrowserBase } from './browser';
 | 
			
		||||
import { Browser } from './browser';
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
import { Progress } from './progress';
 | 
			
		||||
import { DebugController } from './debug/debugController';
 | 
			
		||||
 | 
			
		||||
export interface BrowserContext extends EventEmitter {
 | 
			
		||||
  setDefaultNavigationTimeout(timeout: number): void;
 | 
			
		||||
  setDefaultTimeout(timeout: number): void;
 | 
			
		||||
  pages(): Page[];
 | 
			
		||||
  newPage(): Promise<Page>;
 | 
			
		||||
  cookies(urls?: string | string[]): Promise<types.NetworkCookie[]>;
 | 
			
		||||
  addCookies(cookies: types.SetNetworkCookieParam[]): Promise<void>;
 | 
			
		||||
  clearCookies(): Promise<void>;
 | 
			
		||||
  grantPermissions(permissions: string[], options?: { origin?: string }): Promise<void>;
 | 
			
		||||
  clearPermissions(): Promise<void>;
 | 
			
		||||
  setGeolocation(geolocation?: types.Geolocation): Promise<void>;
 | 
			
		||||
  setExtraHTTPHeaders(headers: types.HeadersArray): Promise<void>;
 | 
			
		||||
  setOffline(offline: boolean): Promise<void>;
 | 
			
		||||
  setHTTPCredentials(httpCredentials?: types.Credentials): Promise<void>;
 | 
			
		||||
  addInitScript(script: Function | string | { path?: string, content?: string }, arg?: any): Promise<void>;
 | 
			
		||||
  exposeBinding(name: string, playwrightBinding: frames.FunctionWithSource): Promise<void>;
 | 
			
		||||
  _setRequestInterceptor(handler: network.RouteHandler | undefined): Promise<void>;
 | 
			
		||||
  close(): Promise<void>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export abstract class BrowserContextBase extends EventEmitter implements BrowserContext {
 | 
			
		||||
export abstract class BrowserContext extends EventEmitter {
 | 
			
		||||
  readonly _timeoutSettings = new TimeoutSettings();
 | 
			
		||||
  readonly _pageBindings = new Map<string, PageBinding>();
 | 
			
		||||
  readonly _options: types.BrowserContextOptions;
 | 
			
		||||
| 
						 | 
				
			
			@ -59,11 +39,11 @@ export abstract class BrowserContextBase extends EventEmitter implements Browser
 | 
			
		|||
  private _closePromiseFulfill: ((error: Error) => void) | undefined;
 | 
			
		||||
  readonly _permissions = new Map<string, string[]>();
 | 
			
		||||
  readonly _downloads = new Set<Download>();
 | 
			
		||||
  readonly _browserBase: BrowserBase;
 | 
			
		||||
  readonly _browser: Browser;
 | 
			
		||||
 | 
			
		||||
  constructor(browserBase: BrowserBase, options: types.BrowserContextOptions, isPersistentContext: boolean) {
 | 
			
		||||
  constructor(browser: Browser, options: types.BrowserContextOptions, isPersistentContext: boolean) {
 | 
			
		||||
    super();
 | 
			
		||||
    this._browserBase = browserBase;
 | 
			
		||||
    this._browser = browser;
 | 
			
		||||
    this._options = options;
 | 
			
		||||
    this._isPersistentContext = isPersistentContext;
 | 
			
		||||
    this._closePromise = new Promise(fulfill => this._closePromiseFulfill = fulfill);
 | 
			
		||||
| 
						 | 
				
			
			@ -183,7 +163,7 @@ export abstract class BrowserContextBase extends EventEmitter implements Browser
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  protected _authenticateProxyViaHeader() {
 | 
			
		||||
    const proxy = this._browserBase._options.proxy || { username: undefined, password: undefined };
 | 
			
		||||
    const proxy = this._browser._options.proxy || { username: undefined, password: undefined };
 | 
			
		||||
    const { username, password } = proxy;
 | 
			
		||||
    if (username) {
 | 
			
		||||
      this._options.httpCredentials = { username, password: password! };
 | 
			
		||||
| 
						 | 
				
			
			@ -196,7 +176,7 @@ export abstract class BrowserContextBase extends EventEmitter implements Browser
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  protected _authenticateProxyViaCredentials() {
 | 
			
		||||
    const proxy = this._browserBase._options.proxy;
 | 
			
		||||
    const proxy = this._browser._options.proxy;
 | 
			
		||||
    if (!proxy)
 | 
			
		||||
      return;
 | 
			
		||||
    const { username, password } = proxy;
 | 
			
		||||
| 
						 | 
				
			
			@ -213,7 +193,7 @@ export abstract class BrowserContextBase extends EventEmitter implements Browser
 | 
			
		|||
    if (this._isPersistentContext) {
 | 
			
		||||
      // Default context is only created in 'persistent' mode and closing it should close
 | 
			
		||||
      // the browser.
 | 
			
		||||
      await this._browserBase.close();
 | 
			
		||||
      await this._browser.close();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    if (this._closedStatus === 'open') {
 | 
			
		||||
| 
						 | 
				
			
			@ -226,7 +206,7 @@ export abstract class BrowserContextBase extends EventEmitter implements Browser
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function assertBrowserContextIsNotOwned(context: BrowserContextBase) {
 | 
			
		||||
export function assertBrowserContextIsNotOwned(context: BrowserContext) {
 | 
			
		||||
  for (const page of context.pages()) {
 | 
			
		||||
    if (page._ownedContext)
 | 
			
		||||
      throw new Error('Please use browser.newContext() for multi-page scripts that share the context.');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,8 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { BrowserBase, BrowserOptions } from '../browser';
 | 
			
		||||
import { assertBrowserContextIsNotOwned, BrowserContext, BrowserContextBase, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
 | 
			
		||||
import { Browser, BrowserOptions } from '../browser';
 | 
			
		||||
import { assertBrowserContextIsNotOwned, BrowserContext, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
 | 
			
		||||
import { Events as CommonEvents } from '../events';
 | 
			
		||||
import { assert } from '../helper';
 | 
			
		||||
import * as network from '../network';
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ import { Protocol } from './protocol';
 | 
			
		|||
import { CRExecutionContext } from './crExecutionContext';
 | 
			
		||||
import { CRDevTools } from './crDevTools';
 | 
			
		||||
 | 
			
		||||
export class CRBrowser extends BrowserBase {
 | 
			
		||||
export class CRBrowser extends Browser {
 | 
			
		||||
  readonly _connection: CRConnection;
 | 
			
		||||
  _session: CRSession;
 | 
			
		||||
  private _clientRootSessionPromise: Promise<CRSession> | null = null;
 | 
			
		||||
| 
						 | 
				
			
			@ -279,7 +279,7 @@ class CRServiceWorker extends Worker {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class CRBrowserContext extends BrowserContextBase {
 | 
			
		||||
export class CRBrowserContext extends BrowserContext {
 | 
			
		||||
  readonly _browser: CRBrowser;
 | 
			
		||||
  readonly _browserContextId: string | null;
 | 
			
		||||
  readonly _evaluateOnNewDocumentSources: string[];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { BrowserContextBase } from '../browserContext';
 | 
			
		||||
import { BrowserContext } from '../browserContext';
 | 
			
		||||
import { Events } from '../events';
 | 
			
		||||
import * as frames from '../frames';
 | 
			
		||||
import * as js from '../javascript';
 | 
			
		||||
| 
						 | 
				
			
			@ -22,7 +22,7 @@ import { Page } from '../page';
 | 
			
		|||
import DebugScript from './injected/debugScript';
 | 
			
		||||
 | 
			
		||||
export class DebugController {
 | 
			
		||||
  constructor(context: BrowserContextBase) {
 | 
			
		||||
  constructor(context: BrowserContext) {
 | 
			
		||||
    context.on(Events.BrowserContext.Page, (page: Page) => {
 | 
			
		||||
      for (const frame of page.frames())
 | 
			
		||||
        this.ensureInstalledInFrame(frame);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,8 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { BrowserBase, BrowserOptions } from '../browser';
 | 
			
		||||
import { assertBrowserContextIsNotOwned, BrowserContext, BrowserContextBase, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
 | 
			
		||||
import { Browser, BrowserOptions } from '../browser';
 | 
			
		||||
import { assertBrowserContextIsNotOwned, BrowserContext, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
 | 
			
		||||
import { Events } from '../events';
 | 
			
		||||
import { assert, helper, RegisteredListener } from '../helper';
 | 
			
		||||
import * as network from '../network';
 | 
			
		||||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ import { ConnectionEvents, FFConnection } from './ffConnection';
 | 
			
		|||
import { FFPage } from './ffPage';
 | 
			
		||||
import { Protocol } from './protocol';
 | 
			
		||||
 | 
			
		||||
export class FFBrowser extends BrowserBase {
 | 
			
		||||
export class FFBrowser extends Browser {
 | 
			
		||||
  _connection: FFConnection;
 | 
			
		||||
  readonly _ffPages: Map<string, FFPage>;
 | 
			
		||||
  readonly _contexts: Map<string, FFBrowserContext>;
 | 
			
		||||
| 
						 | 
				
			
			@ -163,7 +163,7 @@ export class FFBrowser extends BrowserBase {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class FFBrowserContext extends BrowserContextBase {
 | 
			
		||||
export class FFBrowserContext extends BrowserContext {
 | 
			
		||||
  readonly _browser: FFBrowser;
 | 
			
		||||
  readonly _browserContextId: string | null;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,7 +25,7 @@ import { Screenshotter } from './screenshotter';
 | 
			
		|||
import { TimeoutSettings } from './timeoutSettings';
 | 
			
		||||
import * as types from './types';
 | 
			
		||||
import { Events } from './events';
 | 
			
		||||
import { BrowserContext, BrowserContextBase } from './browserContext';
 | 
			
		||||
import { BrowserContext } from './browserContext';
 | 
			
		||||
import { ConsoleMessage } from './console';
 | 
			
		||||
import * as accessibility from './accessibility';
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
| 
						 | 
				
			
			@ -99,7 +99,7 @@ export class Page extends EventEmitter {
 | 
			
		|||
  readonly _disconnectedPromise: Promise<Error>;
 | 
			
		||||
  private _crashedCallback: (e: Error) => void;
 | 
			
		||||
  readonly _crashedPromise: Promise<Error>;
 | 
			
		||||
  readonly _browserContext: BrowserContextBase;
 | 
			
		||||
  readonly _browserContext: BrowserContext;
 | 
			
		||||
  readonly keyboard: input.Keyboard;
 | 
			
		||||
  readonly mouse: input.Mouse;
 | 
			
		||||
  readonly _timeoutSettings: TimeoutSettings;
 | 
			
		||||
| 
						 | 
				
			
			@ -116,7 +116,7 @@ export class Page extends EventEmitter {
 | 
			
		|||
  private _requestInterceptor?: network.RouteHandler;
 | 
			
		||||
  _ownedContext: BrowserContext | undefined;
 | 
			
		||||
 | 
			
		||||
  constructor(delegate: PageDelegate, browserContext: BrowserContextBase) {
 | 
			
		||||
  constructor(delegate: PageDelegate, browserContext: BrowserContext) {
 | 
			
		||||
    super();
 | 
			
		||||
    this._delegate = delegate;
 | 
			
		||||
    this._closedCallback = () => {};
 | 
			
		||||
| 
						 | 
				
			
			@ -144,7 +144,7 @@ export class Page extends EventEmitter {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  async _doSlowMo() {
 | 
			
		||||
    const slowMo = this._browserContext._browserBase._options.slowMo;
 | 
			
		||||
    const slowMo = this._browserContext._browser._options.slowMo;
 | 
			
		||||
    if (!slowMo)
 | 
			
		||||
      return;
 | 
			
		||||
    await new Promise(x => setTimeout(x, slowMo));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ import { LaunchServerOptions } from './client/types';
 | 
			
		|||
import { BrowserTypeBase } from '../server/browserType';
 | 
			
		||||
import * as ws from 'ws';
 | 
			
		||||
import { helper } from '../helper';
 | 
			
		||||
import { BrowserBase } from '../browser';
 | 
			
		||||
import { Browser } from '../browser';
 | 
			
		||||
import { ChildProcess } from 'child_process';
 | 
			
		||||
import { EventEmitter } from 'ws';
 | 
			
		||||
import { DispatcherScope, DispatcherConnection } from './server/dispatcher';
 | 
			
		||||
| 
						 | 
				
			
			@ -43,18 +43,18 @@ export class BrowserServerLauncherImpl implements BrowserServerLauncher {
 | 
			
		|||
      ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
 | 
			
		||||
      env: options.env ? envObjectToArray(options.env) : undefined,
 | 
			
		||||
    });
 | 
			
		||||
    return new BrowserServerImpl(this._browserType, browser as BrowserBase, options.port);
 | 
			
		||||
    return new BrowserServerImpl(this._browserType, browser, options.port);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class BrowserServerImpl extends EventEmitter implements BrowserServer {
 | 
			
		||||
  private _server: ws.Server;
 | 
			
		||||
  private _browserType: BrowserTypeBase;
 | 
			
		||||
  private _browser: BrowserBase;
 | 
			
		||||
  private _browser: Browser;
 | 
			
		||||
  private _wsEndpoint: string;
 | 
			
		||||
  private _process: ChildProcess;
 | 
			
		||||
 | 
			
		||||
  constructor(browserType: BrowserTypeBase, browser: BrowserBase, port: number = 0) {
 | 
			
		||||
  constructor(browserType: BrowserTypeBase, browser: Browser, port: number = 0) {
 | 
			
		||||
    super();
 | 
			
		||||
 | 
			
		||||
    this._browserType = browserType;
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +121,7 @@ class ConnectedBrowser extends BrowserDispatcher {
 | 
			
		|||
  private _contexts: BrowserContextDispatcher[] = [];
 | 
			
		||||
  _closed = false;
 | 
			
		||||
 | 
			
		||||
  constructor(scope: DispatcherScope, browser: BrowserBase) {
 | 
			
		||||
  constructor(scope: DispatcherScope, browser: Browser) {
 | 
			
		||||
    super(scope, browser, 'connectedBrowser');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
import * as types from '../../types';
 | 
			
		||||
import { BrowserContextBase, BrowserContext } from '../../browserContext';
 | 
			
		||||
import { BrowserContext } from '../../browserContext';
 | 
			
		||||
import { Events } from '../../events';
 | 
			
		||||
import { Dispatcher, DispatcherScope, lookupDispatcher } from './dispatcher';
 | 
			
		||||
import { PageDispatcher, BindingCallDispatcher, WorkerDispatcher } from './pageDispatcher';
 | 
			
		||||
| 
						 | 
				
			
			@ -26,9 +26,9 @@ import { CDPSessionDispatcher } from './cdpSessionDispatcher';
 | 
			
		|||
import { Events as ChromiumEvents } from '../../chromium/events';
 | 
			
		||||
 | 
			
		||||
export class BrowserContextDispatcher extends Dispatcher<BrowserContext, BrowserContextInitializer> implements BrowserContextChannel {
 | 
			
		||||
  private _context: BrowserContextBase;
 | 
			
		||||
  private _context: BrowserContext;
 | 
			
		||||
 | 
			
		||||
  constructor(scope: DispatcherScope, context: BrowserContextBase) {
 | 
			
		||||
  constructor(scope: DispatcherScope, context: BrowserContext) {
 | 
			
		||||
    super(scope, context, 'BrowserContext', {}, true);
 | 
			
		||||
    this._context = context;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +40,7 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, Browser
 | 
			
		|||
      this._dispose();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (context._browserBase._options.name === 'chromium') {
 | 
			
		||||
    if (context._browser._options.name === 'chromium') {
 | 
			
		||||
      for (const page of (context as CRBrowserContext).backgroundPages())
 | 
			
		||||
        this._dispatchEvent('crBackgroundPage', { page: new PageDispatcher(this._scope, page) });
 | 
			
		||||
      context.on(ChromiumEvents.ChromiumBrowserContext.BackgroundPage, page => this._dispatchEvent('crBackgroundPage', { page: new PageDispatcher(this._scope, page) }));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,8 +14,7 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { Browser, BrowserBase } from '../../browser';
 | 
			
		||||
import { BrowserContextBase } from '../../browserContext';
 | 
			
		||||
import { Browser } from '../../browser';
 | 
			
		||||
import { Events } from '../../events';
 | 
			
		||||
import { BrowserChannel, BrowserContextChannel, BrowserInitializer, CDPSessionChannel, Binary, BrowserNewContextParams } from '../channels';
 | 
			
		||||
import { BrowserContextDispatcher } from './browserContextDispatcher';
 | 
			
		||||
| 
						 | 
				
			
			@ -25,7 +24,7 @@ import { CRBrowser } from '../../chromium/crBrowser';
 | 
			
		|||
import { PageDispatcher } from './pageDispatcher';
 | 
			
		||||
 | 
			
		||||
export class BrowserDispatcher extends Dispatcher<Browser, BrowserInitializer> implements BrowserChannel {
 | 
			
		||||
  constructor(scope: DispatcherScope, browser: BrowserBase, guid?: string) {
 | 
			
		||||
  constructor(scope: DispatcherScope, browser: Browser, guid?: string) {
 | 
			
		||||
    super(scope, browser, 'Browser', { version: browser.version() }, true, guid);
 | 
			
		||||
    browser.on(Events.Browser.Disconnected, () => this._didClose());
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +35,7 @@ export class BrowserDispatcher extends Dispatcher<Browser, BrowserInitializer> i
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  async newContext(params: BrowserNewContextParams): Promise<{ context: BrowserContextChannel }> {
 | 
			
		||||
    return { context: new BrowserContextDispatcher(this._scope, await this._object.newContext(params) as BrowserContextBase) };
 | 
			
		||||
    return { context: new BrowserContextDispatcher(this._scope, await this._object.newContext(params)) };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async close(): Promise<void> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,12 +14,10 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { BrowserBase } from '../../browser';
 | 
			
		||||
import { BrowserTypeBase, BrowserType } from '../../server/browserType';
 | 
			
		||||
import { BrowserDispatcher } from './browserDispatcher';
 | 
			
		||||
import { BrowserChannel, BrowserTypeChannel, BrowserContextChannel, BrowserTypeInitializer, BrowserTypeLaunchParams, BrowserTypeLaunchPersistentContextParams } from '../channels';
 | 
			
		||||
import { Dispatcher, DispatcherScope } from './dispatcher';
 | 
			
		||||
import { BrowserContextBase } from '../../browserContext';
 | 
			
		||||
import { BrowserContextDispatcher } from './browserContextDispatcher';
 | 
			
		||||
 | 
			
		||||
export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeInitializer> implements BrowserTypeChannel {
 | 
			
		||||
| 
						 | 
				
			
			@ -32,11 +30,11 @@ export class BrowserTypeDispatcher extends Dispatcher<BrowserType, BrowserTypeIn
 | 
			
		|||
 | 
			
		||||
  async launch(params: BrowserTypeLaunchParams): Promise<{ browser: BrowserChannel }> {
 | 
			
		||||
    const browser = await this._object.launch(params);
 | 
			
		||||
    return { browser: new BrowserDispatcher(this._scope, browser as BrowserBase) };
 | 
			
		||||
    return { browser: new BrowserDispatcher(this._scope, browser) };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async launchPersistentContext(params: BrowserTypeLaunchPersistentContextParams): Promise<{ context: BrowserContextChannel }> {
 | 
			
		||||
    const browserContext = await this._object.launchPersistentContext(params.userDataDir, params);
 | 
			
		||||
    return { context: new BrowserContextDispatcher(this._scope, browserContext as BrowserContextBase) };
 | 
			
		||||
    return { context: new BrowserContextDispatcher(this._scope, browserContext) };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,6 @@ import { Dispatcher, DispatcherScope, lookupDispatcher } from './dispatcher';
 | 
			
		|||
import { Electron, ElectronApplication, ElectronEvents, ElectronPage } from '../../server/electron';
 | 
			
		||||
import { ElectronApplicationChannel, ElectronApplicationInitializer, PageChannel, JSHandleChannel, ElectronInitializer, ElectronChannel, SerializedArgument, ElectronLaunchParams, SerializedValue } from '../channels';
 | 
			
		||||
import { BrowserContextDispatcher } from './browserContextDispatcher';
 | 
			
		||||
import { BrowserContextBase } from '../../browserContext';
 | 
			
		||||
import { PageDispatcher } from './pageDispatcher';
 | 
			
		||||
import { parseArgument, serializeResult } from './jsHandleDispatcher';
 | 
			
		||||
import { createHandle } from './elementHandlerDispatcher';
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +36,7 @@ export class ElectronDispatcher extends Dispatcher<Electron, ElectronInitializer
 | 
			
		|||
export class ElectronApplicationDispatcher extends Dispatcher<ElectronApplication, ElectronApplicationInitializer> implements ElectronApplicationChannel {
 | 
			
		||||
  constructor(scope: DispatcherScope, electronApplication: ElectronApplication) {
 | 
			
		||||
    super(scope, electronApplication, 'ElectronApplication', {}, true);
 | 
			
		||||
    this._dispatchEvent('context', { context: new BrowserContextDispatcher(this._scope, electronApplication.context() as BrowserContextBase) });
 | 
			
		||||
    this._dispatchEvent('context', { context: new BrowserContextDispatcher(this._scope, electronApplication.context()) });
 | 
			
		||||
    electronApplication.on(ElectronEvents.ElectronApplication.Close, () => {
 | 
			
		||||
      this._dispatchEvent('close');
 | 
			
		||||
      this._dispose();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,7 @@ import * as util from 'util';
 | 
			
		|||
import { BrowserContext, verifyProxySettings, validateBrowserContextOptions } from '../browserContext';
 | 
			
		||||
import * as browserPaths from '../install/browserPaths';
 | 
			
		||||
import { ConnectionTransport, WebSocketTransport } from '../transport';
 | 
			
		||||
import { BrowserBase, BrowserOptions, Browser, BrowserProcess } from '../browser';
 | 
			
		||||
import { BrowserOptions, Browser, BrowserProcess } from '../browser';
 | 
			
		||||
import { assert, helper } from '../helper';
 | 
			
		||||
import { launchProcess, Env, waitForLine, envArrayToObject } from './processLauncher';
 | 
			
		||||
import { PipeTransport } from './pipeTransport';
 | 
			
		||||
| 
						 | 
				
			
			@ -87,7 +87,7 @@ export abstract class BrowserTypeBase implements BrowserType {
 | 
			
		|||
    return browser._defaultContext!;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async _innerLaunch(progress: Progress, options: types.LaunchOptions, persistent: types.BrowserContextOptions | undefined, userDataDir?: string): Promise<BrowserBase> {
 | 
			
		||||
  async _innerLaunch(progress: Progress, options: types.LaunchOptions, persistent: types.BrowserContextOptions | undefined, userDataDir?: string): Promise<Browser> {
 | 
			
		||||
    options.proxy = options.proxy ? verifyProxySettings(options.proxy) : undefined;
 | 
			
		||||
    const { browserProcess, downloadsPath, transport } = await this._launchProcess(progress, options, !!persistent, userDataDir);
 | 
			
		||||
    if ((options as any).__testHookBeforeCreateBrowser)
 | 
			
		||||
| 
						 | 
				
			
			@ -208,7 +208,7 @@ export abstract class BrowserTypeBase implements BrowserType {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  abstract _defaultArgs(options: types.LaunchOptions, isPersistent: boolean, userDataDir: string): string[];
 | 
			
		||||
  abstract _connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<BrowserBase>;
 | 
			
		||||
  abstract _connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<Browser>;
 | 
			
		||||
  abstract _amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[]): Env;
 | 
			
		||||
  abstract _amendArguments(browserArguments: string[]): string[];
 | 
			
		||||
  abstract _rewriteStartupError(error: Error): Error;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,8 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { BrowserBase, BrowserOptions } from '../browser';
 | 
			
		||||
import { assertBrowserContextIsNotOwned, BrowserContext, BrowserContextBase, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
 | 
			
		||||
import { Browser, BrowserOptions } from '../browser';
 | 
			
		||||
import { assertBrowserContextIsNotOwned, BrowserContext, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
 | 
			
		||||
import { Events } from '../events';
 | 
			
		||||
import { helper, RegisteredListener, assert } from '../helper';
 | 
			
		||||
import * as network from '../network';
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ import { WKPage } from './wkPage';
 | 
			
		|||
const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15';
 | 
			
		||||
const BROWSER_VERSION = '14.0';
 | 
			
		||||
 | 
			
		||||
export class WKBrowser extends BrowserBase {
 | 
			
		||||
export class WKBrowser extends Browser {
 | 
			
		||||
  private readonly _connection: WKConnection;
 | 
			
		||||
  readonly _browserSession: WKSession;
 | 
			
		||||
  readonly _contexts = new Map<string, WKBrowserContext>();
 | 
			
		||||
| 
						 | 
				
			
			@ -195,7 +195,7 @@ export class WKBrowser extends BrowserBase {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class WKBrowserContext extends BrowserContextBase {
 | 
			
		||||
export class WKBrowserContext extends BrowserContext {
 | 
			
		||||
  readonly _browser: WKBrowser;
 | 
			
		||||
  readonly _browserContextId: string | undefined;
 | 
			
		||||
  readonly _evaluateOnNewDocumentSources: string[];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue