2019-12-19 16:53:24 -08:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-02-11 12:06:58 -08:00
|
|
|
import { Browser, createPageInNewContext } from '../browser';
|
2020-03-05 17:22:57 -08:00
|
|
|
import { assertBrowserContextIsNotOwned, BrowserContext, BrowserContextBase, BrowserContextOptions, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
|
|
|
|
import { Events } from '../events';
|
2020-03-05 15:18:27 -08:00
|
|
|
import { assert, helper, RegisteredListener } from '../helper';
|
2019-12-19 16:53:24 -08:00
|
|
|
import * as network from '../network';
|
2020-03-03 16:46:06 -08:00
|
|
|
import { Page, PageBinding, PageEvent } from '../page';
|
2020-03-05 17:22:57 -08:00
|
|
|
import * as platform from '../platform';
|
2020-02-04 19:41:38 -08:00
|
|
|
import { ConnectionTransport, SlowMoTransport } from '../transport';
|
2020-01-07 10:39:01 -08:00
|
|
|
import * as types from '../types';
|
|
|
|
import { Protocol } from './protocol';
|
2020-03-05 17:22:57 -08:00
|
|
|
import { kPageProxyMessageReceived, PageProxyMessageReceivedPayload, WKConnection, WKSession } from './wkConnection';
|
2020-02-26 12:42:20 -08:00
|
|
|
import { WKPage } from './wkPage';
|
2019-12-19 16:53:24 -08:00
|
|
|
|
2020-01-29 20:12:09 -08:00
|
|
|
const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15';
|
|
|
|
|
2020-01-08 14:04:33 -08:00
|
|
|
export class WKBrowser extends platform.EventEmitter implements Browser {
|
2020-01-09 15:14:35 -08:00
|
|
|
private readonly _connection: WKConnection;
|
2020-02-27 08:49:09 -08:00
|
|
|
private readonly _attachToDefaultContext: boolean;
|
2020-02-24 08:53:30 -08:00
|
|
|
readonly _browserSession: WKSession;
|
2020-02-27 16:18:33 -08:00
|
|
|
readonly _defaultContext: WKBrowserContext;
|
2020-02-24 08:53:30 -08:00
|
|
|
readonly _contexts = new Map<string, WKBrowserContext>();
|
2020-03-06 11:41:46 -08:00
|
|
|
readonly _wkPages = new Map<string, WKPage>();
|
2020-01-04 10:12:40 -08:00
|
|
|
private readonly _eventListeners: RegisteredListener[];
|
|
|
|
|
2020-03-06 11:41:46 -08:00
|
|
|
private _firstPageCallback?: () => void;
|
|
|
|
private readonly _firstPagePromise: Promise<void>;
|
2019-12-19 16:53:24 -08:00
|
|
|
|
2020-02-27 08:49:09 -08:00
|
|
|
static async connect(transport: ConnectionTransport, slowMo: number = 0, attachToDefaultContext: boolean = false): Promise<WKBrowser> {
|
|
|
|
const browser = new WKBrowser(SlowMoTransport.wrap(transport, slowMo), attachToDefaultContext);
|
2020-01-07 16:15:07 -08:00
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
2020-02-27 08:49:09 -08:00
|
|
|
constructor(transport: ConnectionTransport, attachToDefaultContext: boolean) {
|
2019-12-19 16:53:24 -08:00
|
|
|
super();
|
2020-01-09 15:14:35 -08:00
|
|
|
this._connection = new WKConnection(transport, this._onDisconnect.bind(this));
|
2020-02-27 08:49:09 -08:00
|
|
|
this._attachToDefaultContext = attachToDefaultContext;
|
2020-01-09 15:14:35 -08:00
|
|
|
this._browserSession = this._connection.browserSession;
|
2019-12-19 16:53:24 -08:00
|
|
|
|
2020-02-24 08:53:30 -08:00
|
|
|
this._defaultContext = new WKBrowserContext(this, undefined, validateBrowserContextOptions({}));
|
2019-12-19 16:53:24 -08:00
|
|
|
|
|
|
|
this._eventListeners = [
|
2020-01-09 15:14:35 -08:00
|
|
|
helper.addEventListener(this._browserSession, 'Browser.pageProxyCreated', this._onPageProxyCreated.bind(this)),
|
|
|
|
helper.addEventListener(this._browserSession, 'Browser.pageProxyDestroyed', this._onPageProxyDestroyed.bind(this)),
|
2020-01-14 11:46:08 -08:00
|
|
|
helper.addEventListener(this._browserSession, 'Browser.provisionalLoadFailed', event => this._onProvisionalLoadFailed(event)),
|
2020-01-09 15:14:35 -08:00
|
|
|
helper.addEventListener(this._browserSession, kPageProxyMessageReceived, this._onPageProxyMessageReceived.bind(this)),
|
2019-12-19 16:53:24 -08:00
|
|
|
];
|
|
|
|
|
2020-03-06 11:41:46 -08:00
|
|
|
this._firstPagePromise = new Promise<void>(resolve => this._firstPageCallback = resolve);
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
2020-01-09 15:14:35 -08:00
|
|
|
_onDisconnect() {
|
2020-03-06 11:41:46 -08:00
|
|
|
for (const wkPage of this._wkPages.values())
|
|
|
|
wkPage.dispose();
|
|
|
|
this._wkPages.clear();
|
2020-03-09 16:53:33 -07:00
|
|
|
for (const context of this._contexts.values())
|
|
|
|
context._browserClosed();
|
2020-01-09 15:14:35 -08:00
|
|
|
this.emit(Events.Browser.Disconnected);
|
|
|
|
}
|
|
|
|
|
2019-12-19 16:53:24 -08:00
|
|
|
async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {
|
2020-02-24 08:53:30 -08:00
|
|
|
options = validateBrowserContextOptions(options);
|
2020-01-09 15:14:35 -08:00
|
|
|
const { browserContextId } = await this._browserSession.send('Browser.createContext');
|
2020-01-29 20:12:09 -08:00
|
|
|
options.userAgent = options.userAgent || DEFAULT_USER_AGENT;
|
2020-02-24 08:53:30 -08:00
|
|
|
const context = new WKBrowserContext(this, browserContextId, options);
|
2020-01-13 13:32:44 -08:00
|
|
|
await context._initialize();
|
2019-12-19 16:53:24 -08:00
|
|
|
this._contexts.set(browserContextId, context);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2020-02-10 10:41:45 -08:00
|
|
|
contexts(): BrowserContext[] {
|
2020-02-05 12:41:55 -08:00
|
|
|
return Array.from(this._contexts.values());
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
2020-02-10 10:41:45 -08:00
|
|
|
async newPage(options?: BrowserContextOptions): Promise<Page> {
|
2020-02-11 12:06:58 -08:00
|
|
|
return createPageInNewContext(this, options);
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
2020-02-13 13:54:01 -08:00
|
|
|
async _waitForFirstPageTarget(): Promise<void> {
|
2020-03-06 11:41:46 -08:00
|
|
|
assert(!this._wkPages.size);
|
|
|
|
return this._firstPagePromise;
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
2020-01-09 15:14:35 -08:00
|
|
|
_onPageProxyCreated(event: Protocol.Browser.pageProxyCreatedPayload) {
|
|
|
|
const { pageProxyInfo } = event;
|
|
|
|
const pageProxyId = pageProxyInfo.pageProxyId;
|
2020-03-02 18:32:56 -08:00
|
|
|
let context: WKBrowserContext | null = null;
|
2020-01-07 10:39:01 -08:00
|
|
|
if (pageProxyInfo.browserContextId) {
|
2019-12-19 16:53:24 -08:00
|
|
|
// FIXME: we don't know about the default context id, so assume that all targets from
|
|
|
|
// unknown contexts are created in the 'default' context which can in practice be represented
|
|
|
|
// by multiple actual contexts in WebKit. Solving this properly will require adding context
|
|
|
|
// lifecycle events.
|
2020-03-02 18:32:56 -08:00
|
|
|
context = this._contexts.get(pageProxyInfo.browserContextId) || null;
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
2020-02-27 08:49:09 -08:00
|
|
|
if (!context && !this._attachToDefaultContext)
|
|
|
|
return;
|
2019-12-19 16:53:24 -08:00
|
|
|
if (!context)
|
|
|
|
context = this._defaultContext;
|
2020-01-09 15:14:35 -08:00
|
|
|
const pageProxySession = new WKSession(this._connection, pageProxyId, `The page has been closed.`, (message: any) => {
|
|
|
|
this._connection.rawSend({ ...message, pageProxyId });
|
|
|
|
});
|
2020-03-06 11:41:46 -08:00
|
|
|
const opener = pageProxyInfo.openerId ? this._wkPages.get(pageProxyInfo.openerId) : undefined;
|
|
|
|
const wkPage = new WKPage(context, pageProxySession, opener || null);
|
|
|
|
this._wkPages.set(pageProxyId, wkPage);
|
2019-12-19 16:53:24 -08:00
|
|
|
|
2020-03-06 11:41:46 -08:00
|
|
|
if (this._firstPageCallback) {
|
|
|
|
this._firstPageCallback();
|
|
|
|
this._firstPageCallback = undefined;
|
2020-01-07 10:39:01 -08:00
|
|
|
}
|
2020-03-02 18:32:56 -08:00
|
|
|
|
2020-03-06 11:41:46 -08:00
|
|
|
const pageEvent = new PageEvent(wkPage.pageOrError());
|
2020-03-05 15:18:27 -08:00
|
|
|
context.emit(Events.BrowserContext.Page, pageEvent);
|
|
|
|
if (!opener)
|
|
|
|
return;
|
|
|
|
opener.pageOrError().then(openerPage => {
|
|
|
|
if (openerPage instanceof Page && !openerPage.isClosed())
|
|
|
|
openerPage.emit(Events.Page.Popup, pageEvent);
|
|
|
|
});
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
2020-01-09 15:14:35 -08:00
|
|
|
_onPageProxyDestroyed(event: Protocol.Browser.pageProxyDestroyedPayload) {
|
|
|
|
const pageProxyId = event.pageProxyId;
|
2020-03-06 11:41:46 -08:00
|
|
|
const wkPage = this._wkPages.get(pageProxyId);
|
|
|
|
if (!wkPage)
|
2020-02-27 08:49:09 -08:00
|
|
|
return;
|
2020-03-09 12:32:42 -07:00
|
|
|
wkPage.didClose();
|
2020-03-06 11:41:46 -08:00
|
|
|
wkPage.dispose();
|
|
|
|
this._wkPages.delete(pageProxyId);
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
2020-01-09 15:14:35 -08:00
|
|
|
_onPageProxyMessageReceived(event: PageProxyMessageReceivedPayload) {
|
2020-03-06 11:41:46 -08:00
|
|
|
const wkPage = this._wkPages.get(event.pageProxyId);
|
|
|
|
if (!wkPage)
|
2020-02-27 08:49:09 -08:00
|
|
|
return;
|
2020-03-06 11:41:46 -08:00
|
|
|
wkPage.dispatchMessageToSession(event.message);
|
2020-01-09 15:14:35 -08:00
|
|
|
}
|
|
|
|
|
2020-01-14 11:46:08 -08:00
|
|
|
_onProvisionalLoadFailed(event: Protocol.Browser.provisionalLoadFailedPayload) {
|
2020-03-06 11:41:46 -08:00
|
|
|
const wkPage = this._wkPages.get(event.pageProxyId);
|
|
|
|
if (!wkPage)
|
2020-02-27 08:49:09 -08:00
|
|
|
return;
|
2020-03-06 11:41:46 -08:00
|
|
|
wkPage.handleProvisionalLoadFailed(event);
|
2020-01-14 11:46:08 -08:00
|
|
|
}
|
|
|
|
|
2019-12-19 16:53:24 -08:00
|
|
|
isConnected(): boolean {
|
2020-01-22 17:42:10 -08:00
|
|
|
return !this._connection.isClosed();
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async close() {
|
|
|
|
helper.removeEventListeners(this._eventListeners);
|
2020-01-09 15:14:35 -08:00
|
|
|
const disconnected = new Promise(f => this.once(Events.Browser.Disconnected, f));
|
2020-02-10 10:41:45 -08:00
|
|
|
await Promise.all(this.contexts().map(context => context.close()));
|
2020-02-06 12:41:43 -08:00
|
|
|
this._connection.close();
|
2020-01-08 13:55:38 -08:00
|
|
|
await disconnected;
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
|
2020-02-12 22:35:06 -08:00
|
|
|
_setDebugFunction(debugFunction: (message: string) => void) {
|
|
|
|
this._connection._debugFunction = debugFunction;
|
|
|
|
}
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
2020-02-24 08:53:30 -08:00
|
|
|
|
2020-03-05 17:22:57 -08:00
|
|
|
export class WKBrowserContext extends BrowserContextBase {
|
2020-02-24 08:53:30 -08:00
|
|
|
readonly _browser: WKBrowser;
|
|
|
|
readonly _browserContextId: string | undefined;
|
2020-02-27 16:18:33 -08:00
|
|
|
readonly _evaluateOnNewDocumentSources: string[];
|
2020-02-24 08:53:30 -08:00
|
|
|
|
|
|
|
constructor(browser: WKBrowser, browserContextId: string | undefined, options: BrowserContextOptions) {
|
2020-03-05 17:22:57 -08:00
|
|
|
super(options);
|
2020-02-24 08:53:30 -08:00
|
|
|
this._browser = browser;
|
|
|
|
this._browserContextId = browserContextId;
|
2020-02-27 16:18:33 -08:00
|
|
|
this._evaluateOnNewDocumentSources = [];
|
2020-02-24 08:53:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async _initialize() {
|
|
|
|
if (this._options.ignoreHTTPSErrors)
|
|
|
|
await this._browser._browserSession.send('Browser.setIgnoreCertificateErrors', { browserContextId: this._browserContextId, ignore: true });
|
|
|
|
if (this._options.locale)
|
|
|
|
await this._browser._browserSession.send('Browser.setLanguages', { browserContextId: this._browserContextId, languages: [this._options.locale] });
|
|
|
|
const entries = Object.entries(this._options.permissions || {});
|
|
|
|
await Promise.all(entries.map(entry => this.setPermissions(entry[0], entry[1])));
|
|
|
|
if (this._options.geolocation)
|
|
|
|
await this.setGeolocation(this._options.geolocation);
|
2020-03-04 17:58:12 -08:00
|
|
|
if (this._options.offline)
|
|
|
|
await this.setOffline(this._options.offline);
|
2020-03-06 13:50:42 -08:00
|
|
|
if (this._options.httpCredentials)
|
|
|
|
await this.setHTTPCredentials(this._options.httpCredentials);
|
2020-02-24 08:53:30 -08:00
|
|
|
}
|
|
|
|
|
2020-03-09 12:32:42 -07:00
|
|
|
_wkPages(): WKPage[] {
|
|
|
|
return Array.from(this._browser._wkPages.values()).filter(wkPage => wkPage._browserContext === this);
|
|
|
|
}
|
|
|
|
|
2020-02-24 08:53:30 -08:00
|
|
|
_existingPages(): Page[] {
|
2020-03-09 12:32:42 -07:00
|
|
|
return this._wkPages().map(wkPage => wkPage._initializedPage()).filter(pageOrNull => !!pageOrNull) as Page[];
|
2020-02-24 08:53:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async pages(): Promise<Page[]> {
|
2020-03-06 11:41:46 -08:00
|
|
|
const wkPages = Array.from(this._browser._wkPages.values()).filter(wkPage => wkPage._browserContext === this);
|
|
|
|
const pages = await Promise.all(wkPages.map(wkPage => wkPage.pageOrError()));
|
2020-03-05 15:18:27 -08:00
|
|
|
return pages.filter(page => page instanceof Page && !page.isClosed()) as Page[];
|
2020-02-24 08:53:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async newPage(): Promise<Page> {
|
|
|
|
assertBrowserContextIsNotOwned(this);
|
|
|
|
const { pageProxyId } = await this._browser._browserSession.send('Browser.createPage', { browserContextId: this._browserContextId });
|
2020-03-06 11:41:46 -08:00
|
|
|
const wkPage = this._browser._wkPages.get(pageProxyId)!;
|
|
|
|
const result = await wkPage.pageOrError();
|
2020-03-05 15:18:27 -08:00
|
|
|
if (result instanceof Page) {
|
|
|
|
if (result.isClosed())
|
|
|
|
throw new Error('Page has been closed.');
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
throw result;
|
2020-02-24 08:53:30 -08:00
|
|
|
}
|
|
|
|
|
2020-03-06 08:24:32 -08:00
|
|
|
async cookies(urls?: string | string[]): Promise<network.NetworkCookie[]> {
|
2020-02-24 08:53:30 -08:00
|
|
|
const { cookies } = await this._browser._browserSession.send('Browser.getAllCookies', { browserContextId: this._browserContextId });
|
2020-03-07 08:41:57 -08:00
|
|
|
return network.filterCookies(cookies.map((c: network.NetworkCookie) => {
|
|
|
|
const copy: any = { ... c };
|
|
|
|
copy.expires = c.expires === 0 ? -1 : c.expires / 1000;
|
|
|
|
delete copy.session;
|
|
|
|
return copy as network.NetworkCookie;
|
|
|
|
}), urls);
|
2020-02-24 08:53:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async setCookies(cookies: network.SetNetworkCookieParam[]) {
|
2020-03-07 08:41:57 -08:00
|
|
|
const cc = network.rewriteCookies(cookies).map(c => ({
|
|
|
|
...c,
|
|
|
|
session: c.expires === -1 || c.expires === undefined,
|
|
|
|
expires: c.expires && c.expires !== -1 ? c.expires * 1000 : c.expires
|
|
|
|
})) as Protocol.Browser.SetCookieParam[];
|
2020-02-24 08:53:30 -08:00
|
|
|
await this._browser._browserSession.send('Browser.setCookies', { cookies: cc, browserContextId: this._browserContextId });
|
|
|
|
}
|
|
|
|
|
|
|
|
async clearCookies() {
|
|
|
|
await this._browser._browserSession.send('Browser.deleteAllCookies', { browserContextId: this._browserContextId });
|
|
|
|
}
|
|
|
|
|
|
|
|
async setPermissions(origin: string, permissions: string[]): Promise<void> {
|
|
|
|
const webPermissionToProtocol = new Map<string, string>([
|
|
|
|
['geolocation', 'geolocation'],
|
|
|
|
]);
|
|
|
|
const filtered = permissions.map(permission => {
|
|
|
|
const protocolPermission = webPermissionToProtocol.get(permission);
|
|
|
|
if (!protocolPermission)
|
|
|
|
throw new Error('Unknown permission: ' + permission);
|
|
|
|
return protocolPermission;
|
|
|
|
});
|
|
|
|
await this._browser._browserSession.send('Browser.grantPermissions', { origin, browserContextId: this._browserContextId, permissions: filtered });
|
|
|
|
}
|
|
|
|
|
|
|
|
async clearPermissions() {
|
|
|
|
await this._browser._browserSession.send('Browser.resetPermissions', { browserContextId: this._browserContextId });
|
|
|
|
}
|
|
|
|
|
|
|
|
async setGeolocation(geolocation: types.Geolocation | null): Promise<void> {
|
|
|
|
if (geolocation)
|
|
|
|
geolocation = verifyGeolocation(geolocation);
|
|
|
|
this._options.geolocation = geolocation || undefined;
|
|
|
|
const payload: any = geolocation ? { ...geolocation, timestamp: Date.now() } : undefined;
|
|
|
|
await this._browser._browserSession.send('Browser.setGeolocationOverride', { browserContextId: this._browserContextId, geolocation: payload });
|
|
|
|
}
|
|
|
|
|
2020-02-26 12:42:20 -08:00
|
|
|
async setExtraHTTPHeaders(headers: network.Headers): Promise<void> {
|
|
|
|
this._options.extraHTTPHeaders = network.verifyHeaders(headers);
|
|
|
|
for (const page of this._existingPages())
|
|
|
|
await (page._delegate as WKPage).updateExtraHTTPHeaders();
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:58:12 -08:00
|
|
|
async setOffline(offline: boolean): Promise<void> {
|
|
|
|
this._options.offline = offline;
|
|
|
|
for (const page of this._existingPages())
|
|
|
|
await (page._delegate as WKPage).updateOffline();
|
|
|
|
}
|
|
|
|
|
2020-03-06 13:50:42 -08:00
|
|
|
async setHTTPCredentials(httpCredentials: types.Credentials | null): Promise<void> {
|
|
|
|
this._options.httpCredentials = httpCredentials || undefined;
|
|
|
|
for (const page of this._existingPages())
|
|
|
|
await (page._delegate as WKPage).updateHttpCredentials();
|
|
|
|
}
|
|
|
|
|
2020-02-27 17:42:14 -08:00
|
|
|
async addInitScript(script: Function | string | { path?: string, content?: string }, ...args: any[]) {
|
2020-02-28 15:34:07 -08:00
|
|
|
const source = await helper.evaluationScript(script, args);
|
2020-02-27 16:18:33 -08:00
|
|
|
this._evaluateOnNewDocumentSources.push(source);
|
|
|
|
for (const page of this._existingPages())
|
|
|
|
await (page._delegate as WKPage)._updateBootstrapScript();
|
|
|
|
}
|
|
|
|
|
2020-03-03 16:46:06 -08:00
|
|
|
async exposeFunction(name: string, playwrightFunction: Function): Promise<void> {
|
|
|
|
for (const page of this._existingPages()) {
|
|
|
|
if (page._pageBindings.has(name))
|
|
|
|
throw new Error(`Function "${name}" has been already registered in one of the pages`);
|
|
|
|
}
|
|
|
|
if (this._pageBindings.has(name))
|
|
|
|
throw new Error(`Function "${name}" has been already registered`);
|
|
|
|
const binding = new PageBinding(name, playwrightFunction);
|
|
|
|
this._pageBindings.set(name, binding);
|
|
|
|
for (const page of this._existingPages())
|
|
|
|
await (page._delegate as WKPage).exposeBinding(binding);
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:02:54 -07:00
|
|
|
async route(url: types.URLMatch, handler: network.RouteHandler): Promise<void> {
|
|
|
|
this._routes.push({ url, handler });
|
|
|
|
for (const page of this._existingPages())
|
|
|
|
await (page._delegate as WKPage).updateRequestInterception();
|
|
|
|
}
|
|
|
|
|
2020-02-24 08:53:30 -08:00
|
|
|
async close() {
|
|
|
|
if (this._closed)
|
|
|
|
return;
|
2020-03-09 16:53:33 -07:00
|
|
|
if (!this._browserContextId) {
|
|
|
|
// Default context is only created in 'persistent' mode and closing it should close
|
|
|
|
// the browser.
|
|
|
|
await this._browser.close();
|
|
|
|
return;
|
|
|
|
}
|
2020-02-24 08:53:30 -08:00
|
|
|
await this._browser._browserSession.send('Browser.deleteContext', { browserContextId: this._browserContextId });
|
|
|
|
this._browser._contexts.delete(this._browserContextId);
|
2020-03-05 17:22:57 -08:00
|
|
|
this._didCloseInternal();
|
2020-02-24 08:53:30 -08:00
|
|
|
}
|
|
|
|
}
|