From bcb12fcf7fcd4fc7aebdcbaf99c75d04c186321e Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Sat, 2 Apr 2022 18:02:27 -0800 Subject: [PATCH] chore: mark public methods on server as such (#13271) --- .../dispatchers/browserContextDispatcher.ts | 6 +-- .../src/dispatchers/browserDispatcher.ts | 2 +- .../src/dispatchers/pageDispatcher.ts | 8 ++-- .../src/server/browserContext.ts | 46 +++++++++++-------- .../src/server/chromium/crBrowser.ts | 25 +++++----- .../src/server/chromium/crPage.ts | 12 ++--- .../playwright-core/src/server/download.ts | 2 +- .../src/server/firefox/ffBrowser.ts | 24 +++++----- .../src/server/firefox/ffPage.ts | 4 +- packages/playwright-core/src/server/page.ts | 14 +++--- .../src/server/trace/recorder/snapshotter.ts | 2 +- .../src/server/webkit/wkBrowser.ts | 23 ++++------ .../src/server/webkit/wkPage.ts | 6 +-- 13 files changed, 86 insertions(+), 88 deletions(-) diff --git a/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts b/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts index dcc0747fd7..0a33e146e6 100644 --- a/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/browserContextDispatcher.ts @@ -166,15 +166,15 @@ export class BrowserContextDispatcher extends Dispatcher { - await this._context._doAddInitScript(params.source); + await this._context.addInitScript(params.source); } async setNetworkInterceptionEnabled(params: channels.BrowserContextSetNetworkInterceptionEnabledParams): Promise { if (!params.enabled) { - await this._context._setRequestInterceptor(undefined); + await this._context.setRequestInterceptor(undefined); return; } - await this._context._setRequestInterceptor((route, request) => { + await this._context.setRequestInterceptor((route, request) => { this._dispatchEvent('route', { route: RouteDispatcher.from(this._scope, route), request: RequestDispatcher.from(this._scope, request) }); }); } diff --git a/packages/playwright-core/src/dispatchers/browserDispatcher.ts b/packages/playwright-core/src/dispatchers/browserDispatcher.ts index b8a92fe068..d0681c90a9 100644 --- a/packages/playwright-core/src/dispatchers/browserDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/browserDispatcher.ts @@ -91,7 +91,7 @@ export class ConnectedBrowserDispatcher extends Dispatcher this._contexts.delete(context)); return { context: new BrowserContextDispatcher(this._scope, context) }; } diff --git a/packages/playwright-core/src/dispatchers/pageDispatcher.ts b/packages/playwright-core/src/dispatchers/pageDispatcher.ts index 65ae5c2ca1..0676894f2c 100644 --- a/packages/playwright-core/src/dispatchers/pageDispatcher.ts +++ b/packages/playwright-core/src/dispatchers/pageDispatcher.ts @@ -137,15 +137,15 @@ export class PageDispatcher extends Dispatcher imple } async addInitScript(params: channels.PageAddInitScriptParams, metadata: CallMetadata): Promise { - await this._page._addInitScriptExpression(params.source); + await this._page.addInitScript(params.source); } async setNetworkInterceptionEnabled(params: channels.PageSetNetworkInterceptionEnabledParams, metadata: CallMetadata): Promise { if (!params.enabled) { - await this._page._setClientRequestInterceptor(undefined); + await this._page.setClientRequestInterceptor(undefined); return; } - await this._page._setClientRequestInterceptor((route, request) => { + await this._page.setClientRequestInterceptor((route, request) => { this._dispatchEvent('route', { route: RouteDispatcher.from(this._scope, route), request: RequestDispatcher.from(this._scope, request) }); }); } @@ -191,7 +191,7 @@ export class PageDispatcher extends Dispatcher imple } async setFileChooserInterceptedNoReply(params: channels.PageSetFileChooserInterceptedNoReplyParams, metadata: CallMetadata): Promise { - await this._page._setFileChooserIntercepted(params.intercepted); + await this._page.setFileChooserIntercepted(params.intercepted); } async keyboardDown(params: channels.PageKeyboardDownParams, metadata: CallMetadata): Promise { diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts index 39c08b94c7..180b0632a8 100644 --- a/packages/playwright-core/src/server/browserContext.ts +++ b/packages/playwright-core/src/server/browserContext.ts @@ -69,6 +69,7 @@ export abstract class BrowserContext extends SdkObject { private _customCloseHandler?: () => Promise; readonly _tempDirs: string[] = []; private _settingStorageState = false; + readonly initScripts: string[] = []; constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) { super(browser, 'browser-context'); @@ -91,7 +92,7 @@ export abstract class BrowserContext extends SdkObject { return this._isPersistentContext; } - _setSelectors(selectors: Selectors) { + setSelectors(selectors: Selectors) { this._selectors = selectors; } @@ -143,7 +144,7 @@ export abstract class BrowserContext extends SdkObject { this._downloads.clear(); this.tracing.dispose(); if (this._isPersistentContext) - this._onClosePersistent(); + this.onClosePersistent(); this._closePromiseFulfill!(new Error('Context closed')); this.emit(BrowserContext.Events.Close); } @@ -151,30 +152,30 @@ export abstract class BrowserContext extends SdkObject { // BrowserContext methods. abstract pages(): Page[]; abstract newPageDelegate(): Promise; - abstract _doCookies(urls: string[]): Promise; abstract addCookies(cookies: types.SetNetworkCookieParam[]): Promise; abstract clearCookies(): Promise; - abstract _doGrantPermissions(origin: string, permissions: string[]): Promise; - abstract _doClearPermissions(): Promise; abstract setGeolocation(geolocation?: types.Geolocation): Promise; - abstract _doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise; abstract setExtraHTTPHeaders(headers: types.HeadersArray): Promise; abstract setOffline(offline: boolean): Promise; - abstract _doAddInitScript(expression: string): Promise; - abstract _doExposeBinding(binding: PageBinding): Promise; - abstract _doUpdateRequestInterception(): Promise; - abstract _doClose(): Promise; - abstract _onClosePersistent(): void; - abstract _doCancelDownload(uuid: string): Promise; + abstract cancelDownload(uuid: string): Promise; + protected abstract doGetCookies(urls: string[]): Promise; + protected abstract doGrantPermissions(origin: string, permissions: string[]): Promise; + protected abstract doClearPermissions(): Promise; + protected abstract doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise; + protected abstract doAddInitScript(expression: string): Promise; + protected abstract doExposeBinding(binding: PageBinding): Promise; + protected abstract doUpdateRequestInterception(): Promise; + protected abstract doClose(): Promise; + protected abstract onClosePersistent(): void; async cookies(urls: string | string[] | undefined = []): Promise { if (urls && !Array.isArray(urls)) urls = [ urls ]; - return await this._doCookies(urls as string[]); + return await this.doGetCookies(urls as string[]); } setHTTPCredentials(httpCredentials?: types.Credentials): Promise { - return this._doSetHTTPCredentials(httpCredentials); + return this.doSetHTTPCredentials(httpCredentials); } async exposeBinding(name: string, needsHandle: boolean, playwrightBinding: frames.FunctionWithSource): Promise { @@ -186,7 +187,7 @@ export abstract class BrowserContext extends SdkObject { } const binding = new PageBinding(name, playwrightBinding, needsHandle); this._pageBindings.set(name, binding); - await this._doExposeBinding(binding); + await this.doExposeBinding(binding); } async grantPermissions(permissions: string[], origin?: string) { @@ -199,12 +200,12 @@ export abstract class BrowserContext extends SdkObject { permissions.forEach(p => existing.add(p)); const list = [...existing.values()]; this._permissions.set(resolvedOrigin, list); - await this._doGrantPermissions(resolvedOrigin, list); + await this.doGrantPermissions(resolvedOrigin, list); } async clearPermissions() { this._permissions.clear(); - await this._doClearPermissions(); + await this.doClearPermissions(); } setDefaultNavigationTimeout(timeout: number | undefined) { @@ -264,9 +265,14 @@ export abstract class BrowserContext extends SdkObject { this._options.httpCredentials = { username, password: password || '' }; } - async _setRequestInterceptor(handler: network.RouteHandler | undefined): Promise { + async addInitScript(script: string) { + this.initScripts.push(script); + await this.doAddInitScript(script); + } + + async setRequestInterceptor(handler: network.RouteHandler | undefined): Promise { this._requestInterceptor = handler; - await this._doUpdateRequestInterception(); + await this.doUpdateRequestInterception(); } isClosingOrClosed() { @@ -309,7 +315,7 @@ export abstract class BrowserContext extends SdkObject { await Promise.all(this.pages().map(page => page.close(metadata))); } else { // Close the context. - await this._doClose(); + await this.doClose(); } // We delete downloads after context closure diff --git a/packages/playwright-core/src/server/chromium/crBrowser.ts b/packages/playwright-core/src/server/chromium/crBrowser.ts index 937582c631..175412c35f 100644 --- a/packages/playwright-core/src/server/chromium/crBrowser.ts +++ b/packages/playwright-core/src/server/chromium/crBrowser.ts @@ -323,11 +323,9 @@ export class CRBrowserContext extends BrowserContext { }; declare readonly _browser: CRBrowser; - readonly _evaluateOnNewDocumentSources: string[]; constructor(browser: CRBrowser, browserContextId: string | undefined, options: types.BrowserContextOptions) { super(browser, options, browserContextId); - this._evaluateOnNewDocumentSources = []; this._authenticateProxyViaCredentials(); } @@ -382,7 +380,7 @@ export class CRBrowserContext extends BrowserContext { return this._browser._crPages.get(targetId)!; } - async _doCookies(urls: string[]): Promise { + async doGetCookies(urls: string[]): Promise { const { cookies } = await this._browser._session.send('Storage.getCookies', { browserContextId: this._browserContextId }); return network.filterCookies(cookies.map(c => { const copy: any = { sameSite: 'Lax', ...c }; @@ -404,7 +402,7 @@ export class CRBrowserContext extends BrowserContext { await this._browser._session.send('Storage.clearCookies', { browserContextId: this._browserContextId }); } - async _doGrantPermissions(origin: string, permissions: string[]) { + async doGrantPermissions(origin: string, permissions: string[]) { const webPermissionToProtocol = new Map([ ['geolocation', 'geolocation'], ['midi', 'midi'], @@ -432,7 +430,7 @@ export class CRBrowserContext extends BrowserContext { await this._browser._session.send('Browser.grantPermissions', { origin: origin === '*' ? undefined : origin, browserContextId: this._browserContextId, permissions: filtered }); } - async _doClearPermissions() { + async doClearPermissions() { await this._browser._session.send('Browser.resetPermissions', { browserContextId: this._browserContextId }); } @@ -455,29 +453,28 @@ export class CRBrowserContext extends BrowserContext { await (page._delegate as CRPage).updateOffline(); } - async _doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise { + async doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise { this._options.httpCredentials = httpCredentials; for (const page of this.pages()) await (page._delegate as CRPage).updateHttpCredentials(); } - async _doAddInitScript(source: string) { - this._evaluateOnNewDocumentSources.push(source); + async doAddInitScript(source: string) { for (const page of this.pages()) - await (page._delegate as CRPage).evaluateOnNewDocument(source); + await (page._delegate as CRPage).addInitScript(source); } - async _doExposeBinding(binding: PageBinding) { + async doExposeBinding(binding: PageBinding) { for (const page of this.pages()) await (page._delegate as CRPage).exposeBinding(binding); } - async _doUpdateRequestInterception(): Promise { + async doUpdateRequestInterception(): Promise { for (const page of this.pages()) await (page._delegate as CRPage).updateRequestInterception(); } - async _doClose() { + async doClose() { assert(this._browserContextId); // Headful chrome cannot dispose browser context with opened 'beforeunload' // dialogs, so we should close all that are currently opened. @@ -505,7 +502,7 @@ export class CRBrowserContext extends BrowserContext { } } - _onClosePersistent() { + onClosePersistent() { // When persistent context is closed, we do not necessary get Target.detachedFromTarget // for all the background pages. for (const [targetId, backgroundPage] of this._browser._backgroundPages.entries()) { @@ -516,7 +513,7 @@ export class CRBrowserContext extends BrowserContext { } } - async _doCancelDownload(guid: string) { + async cancelDownload(guid: string) { // The upstream CDP method is implemented in a way that no explicit error would be given // regarding the requested `guid`, even if the download is in a state not suitable for // cancellation (finished, cancelled, etc.) or the guid is invalid at all. diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts index a8ffd5c07f..952db56960 100644 --- a/packages/playwright-core/src/server/chromium/crPage.ts +++ b/packages/playwright-core/src/server/chromium/crPage.ts @@ -213,7 +213,7 @@ export class CRPage implements PageDelegate { } async setFileChooserIntercepted(enabled: boolean) { - await this._forAllFrameSessions(frame => frame._setFileChooserIntercepted(enabled)); + await this._forAllFrameSessions(frame => frame.setFileChooserIntercepted(enabled)); } async reload(): Promise { @@ -237,7 +237,7 @@ export class CRPage implements PageDelegate { return this._go(+1); } - async evaluateOnNewDocument(source: string, world: types.World = 'main'): Promise { + async addInitScript(source: string, world: types.World = 'main'): Promise { await this._forAllFrameSessions(frame => frame._evaluateOnNewDocument(source, world)); } @@ -487,7 +487,7 @@ class FrameSession { }); for (const binding of this._crPage._browserContext._pageBindings.values()) frame.evaluateExpression(binding.source, false, undefined).catch(e => {}); - for (const source of this._crPage._browserContext._evaluateOnNewDocumentSources) + for (const source of this._crPage._browserContext.initScripts) frame.evaluateExpression(source, false, undefined, 'main').catch(e => {}); } const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ':'; @@ -543,9 +543,9 @@ class FrameSession { promises.push(this._updateEmulateMedia(true)); for (const binding of this._crPage._page.allBindings()) promises.push(this._initBinding(binding)); - for (const source of this._crPage._browserContext._evaluateOnNewDocumentSources) + for (const source of this._crPage._browserContext.initScripts) promises.push(this._evaluateOnNewDocument(source, 'main')); - for (const source of this._crPage._page._evaluateOnNewDocumentSources) + for (const source of this._crPage._page.initScripts) promises.push(this._evaluateOnNewDocument(source, 'main')); if (screencastOptions) promises.push(this._startVideoRecording(screencastOptions)); @@ -1048,7 +1048,7 @@ class FrameSession { await this._networkManager.setRequestInterception(this._page._needsRequestInterception()); } - async _setFileChooserIntercepted(enabled: boolean) { + async setFileChooserIntercepted(enabled: boolean) { await this._client.send('Page.setInterceptFileChooserDialog', { enabled }).catch(e => {}); // target can be closed. } diff --git a/packages/playwright-core/src/server/download.ts b/packages/playwright-core/src/server/download.ts index 847c8cf061..f6fda002af 100644 --- a/packages/playwright-core/src/server/download.ts +++ b/packages/playwright-core/src/server/download.ts @@ -28,7 +28,7 @@ export class Download { constructor(page: Page, downloadsPath: string, uuid: string, url: string, suggestedFilename?: string) { const unaccessibleErrorMessage = !page._browserContext._options.acceptDownloads ? 'Pass { acceptDownloads: true } when you are creating your browser context.' : undefined; this.artifact = new Artifact(page, path.join(downloadsPath, uuid), unaccessibleErrorMessage, () => { - return this._page._browserContext._doCancelDownload(uuid); + return this._page._browserContext.cancelDownload(uuid); }); this._page = page; this.url = url; diff --git a/packages/playwright-core/src/server/firefox/ffBrowser.ts b/packages/playwright-core/src/server/firefox/ffBrowser.ts index ed24cf53c8..570bb71753 100644 --- a/packages/playwright-core/src/server/firefox/ffBrowser.ts +++ b/packages/playwright-core/src/server/firefox/ffBrowser.ts @@ -153,7 +153,6 @@ export class FFBrowser extends Browser { export class FFBrowserContext extends BrowserContext { declare readonly _browser: FFBrowser; - private _initScripts: string[] = []; constructor(browser: FFBrowser, browserContextId: string | undefined, options: types.BrowserContextOptions) { super(browser, options, browserContextId); @@ -255,7 +254,7 @@ export class FFBrowserContext extends BrowserContext { return this._browser._ffPages.get(targetId)!; } - async _doCookies(urls: string[]): Promise { + async doGetCookies(urls: string[]): Promise { const { cookies } = await this._browser._connection.send('Browser.getCookies', { browserContextId: this._browserContextId }); return network.filterCookies(cookies.map(c => { const copy: any = { ... c }; @@ -277,7 +276,7 @@ export class FFBrowserContext extends BrowserContext { await this._browser._connection.send('Browser.clearCookies', { browserContextId: this._browserContextId }); } - async _doGrantPermissions(origin: string, permissions: string[]) { + async doGrantPermissions(origin: string, permissions: string[]) { const webPermissionToProtocol = new Map([ ['geolocation', 'geo'], ['persistent-storage', 'persistent-storage'], @@ -293,7 +292,7 @@ export class FFBrowserContext extends BrowserContext { await this._browser._connection.send('Browser.grantPermissions', { origin: origin, browserContextId: this._browserContextId, permissions: filtered }); } - async _doClearPermissions() { + async doClearPermissions() { await this._browser._connection.send('Browser.resetPermissions', { browserContextId: this._browserContextId }); } @@ -316,33 +315,32 @@ export class FFBrowserContext extends BrowserContext { await this._browser._connection.send('Browser.setOnlineOverride', { browserContextId: this._browserContextId, override: offline ? 'offline' : 'online' }); } - async _doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise { + async doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise { this._options.httpCredentials = httpCredentials; await this._browser._connection.send('Browser.setHTTPCredentials', { browserContextId: this._browserContextId, credentials: httpCredentials || null }); } - async _doAddInitScript(source: string) { - this._initScripts.push(source); - await this._browser._connection.send('Browser.setInitScripts', { browserContextId: this._browserContextId, scripts: this._initScripts.map(script => ({ script })) }); + async doAddInitScript(source: string) { + await this._browser._connection.send('Browser.setInitScripts', { browserContextId: this._browserContextId, scripts: this.initScripts.map(script => ({ script })) }); } - async _doExposeBinding(binding: PageBinding) { + async doExposeBinding(binding: PageBinding) { await this._browser._connection.send('Browser.addBinding', { browserContextId: this._browserContextId, name: binding.name, script: binding.source }); } - async _doUpdateRequestInterception(): Promise { + async doUpdateRequestInterception(): Promise { await this._browser._connection.send('Browser.setRequestInterception', { browserContextId: this._browserContextId, enabled: !!this._requestInterceptor }); } - _onClosePersistent() {} + onClosePersistent() {} - async _doClose() { + async doClose() { assert(this._browserContextId); await this._browser._connection.send('Browser.removeBrowserContext', { browserContextId: this._browserContextId }); this._browser._contexts.delete(this._browserContextId); } - async _doCancelDownload(uuid: string) { + async cancelDownload(uuid: string) { await this._browser._connection.send('Browser.cancelDownload', { uuid }); } } diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.ts index d07390cd39..569f49b566 100644 --- a/packages/playwright-core/src/server/firefox/ffPage.ts +++ b/packages/playwright-core/src/server/firefox/ffPage.ts @@ -113,7 +113,7 @@ export class FFPage implements PageDelegate { }); // Ideally, we somehow ensure that utility world is created before Page.ready arrives, but currently it is racy. // Therefore, we can end up with an initialized page without utility world, although very unlikely. - this.evaluateOnNewDocument('', UTILITY_WORLD_NAME).catch(e => this._markAsError(e)); + this.addInitScript('', UTILITY_WORLD_NAME).catch(e => this._markAsError(e)); } potentiallyUninitializedPage(): Page { @@ -398,7 +398,7 @@ export class FFPage implements PageDelegate { return success; } - async evaluateOnNewDocument(script: string, worldName?: string): Promise { + async addInitScript(script: string, worldName?: string): Promise { this._initScripts.push({ script, worldName }); await this._session.send('Page.setInitScripts', { scripts: this._initScripts }); } diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts index 6f7dc9e889..107bab226e 100644 --- a/packages/playwright-core/src/server/page.ts +++ b/packages/playwright-core/src/server/page.ts @@ -47,7 +47,7 @@ export interface PageDelegate { goBack(): Promise; goForward(): Promise; exposeBinding(binding: PageBinding): Promise; - evaluateOnNewDocument(source: string): Promise; + addInitScript(source: string): Promise; closePage(runBeforeUnload: boolean): Promise; potentiallyUninitializedPage(): Page; pageOrError(): Promise; @@ -145,7 +145,7 @@ export class Page extends SdkObject { readonly _delegate: PageDelegate; readonly _state: PageState; private readonly _pageBindings = new Map(); - readonly _evaluateOnNewDocumentSources: string[] = []; + readonly initScripts: string[] = []; readonly _screenshotter: Screenshotter; readonly _frameManager: frames.FrameManager; readonly accessibility: accessibility.Accessibility; @@ -411,16 +411,16 @@ export class Page extends SdkObject { await this._delegate.bringToFront(); } - async _addInitScriptExpression(source: string) { - this._evaluateOnNewDocumentSources.push(source); - await this._delegate.evaluateOnNewDocument(source); + async addInitScript(source: string) { + this.initScripts.push(source); + await this._delegate.addInitScript(source); } _needsRequestInterception(): boolean { return !!this._clientRequestInterceptor || !!this._serverRequestInterceptor || !!this._browserContext._requestInterceptor; } - async _setClientRequestInterceptor(handler: network.RouteHandler | undefined): Promise { + async setClientRequestInterceptor(handler: network.RouteHandler | undefined): Promise { this._clientRequestInterceptor = handler; await this._delegate.updateRequestInterception(); } @@ -591,7 +591,7 @@ export class Page extends SdkObject { } } - async _setFileChooserIntercepted(enabled: boolean): Promise { + async setFileChooserIntercepted(enabled: boolean): Promise { await this._delegate.setFileChooserIntercepted(enabled); } diff --git a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts b/packages/playwright-core/src/server/trace/recorder/snapshotter.ts index fe78974b2e..088f02f8b2 100644 --- a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts +++ b/packages/playwright-core/src/server/trace/recorder/snapshotter.ts @@ -80,7 +80,7 @@ export class Snapshotter { ]; const initScript = `(${frameSnapshotStreamer})("${this._snapshotStreamer}")`; - await this._context._doAddInitScript(initScript); + await this._context.addInitScript(initScript); await this._runInAllFrames(initScript); } diff --git a/packages/playwright-core/src/server/webkit/wkBrowser.ts b/packages/playwright-core/src/server/webkit/wkBrowser.ts index 3dcbed9682..c0126be5c0 100644 --- a/packages/playwright-core/src/server/webkit/wkBrowser.ts +++ b/packages/playwright-core/src/server/webkit/wkBrowser.ts @@ -202,11 +202,9 @@ export class WKBrowser extends Browser { export class WKBrowserContext extends BrowserContext { declare readonly _browser: WKBrowser; - readonly _evaluateOnNewDocumentSources: string[]; constructor(browser: WKBrowser, browserContextId: string | undefined, options: types.BrowserContextOptions) { super(browser, options, browserContextId); - this._evaluateOnNewDocumentSources = []; this._authenticateProxyViaHeader(); } @@ -248,7 +246,7 @@ export class WKBrowserContext extends BrowserContext { return this._browser._wkPages.get(pageProxyId)!; } - async _doCookies(urls: string[]): Promise { + async doGetCookies(urls: string[]): Promise { const { cookies } = await this._browser._browserSession.send('Playwright.getAllCookies', { browserContextId: this._browserContextId }); return network.filterCookies(cookies.map((c: types.NetworkCookie) => { const copy: any = { ... c }; @@ -271,11 +269,11 @@ export class WKBrowserContext extends BrowserContext { await this._browser._browserSession.send('Playwright.deleteAllCookies', { browserContextId: this._browserContextId }); } - async _doGrantPermissions(origin: string, permissions: string[]) { + async doGrantPermissions(origin: string, permissions: string[]) { await Promise.all(this.pages().map(page => (page._delegate as WKPage)._grantPermissions(origin, permissions))); } - async _doClearPermissions() { + async doClearPermissions() { await Promise.all(this.pages().map(page => (page._delegate as WKPage)._clearPermissions())); } @@ -298,37 +296,36 @@ export class WKBrowserContext extends BrowserContext { await (page._delegate as WKPage).updateOffline(); } - async _doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise { + async doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise { this._options.httpCredentials = httpCredentials; for (const page of this.pages()) await (page._delegate as WKPage).updateHttpCredentials(); } - async _doAddInitScript(source: string) { - this._evaluateOnNewDocumentSources.push(source); + async doAddInitScript(source: string) { for (const page of this.pages()) await (page._delegate as WKPage)._updateBootstrapScript(); } - async _doExposeBinding(binding: PageBinding) { + async doExposeBinding(binding: PageBinding) { for (const page of this.pages()) await (page._delegate as WKPage).exposeBinding(binding); } - async _doUpdateRequestInterception(): Promise { + async doUpdateRequestInterception(): Promise { for (const page of this.pages()) await (page._delegate as WKPage).updateRequestInterception(); } - _onClosePersistent() {} + onClosePersistent() {} - async _doClose() { + async doClose() { assert(this._browserContextId); await this._browser._browserSession.send('Playwright.deleteContext', { browserContextId: this._browserContextId }); this._browser._contexts.delete(this._browserContextId); } - async _doCancelDownload(uuid: string) { + async cancelDownload(uuid: string) { await this._browser._browserSession.send('Playwright.cancelDownload', { uuid }); } } diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts index 8c487de975..8044beb50e 100644 --- a/packages/playwright-core/src/server/webkit/wkPage.ts +++ b/packages/playwright-core/src/server/webkit/wkPage.ts @@ -758,7 +758,7 @@ export class WKPage implements PageDelegate { await Promise.all(this._page.frames().map(frame => frame.evaluateExpression(script, false, {}).catch(e => {}))); } - async evaluateOnNewDocument(script: string): Promise { + async addInitScript(script: string): Promise { await this._updateBootstrapScript(); } @@ -775,8 +775,8 @@ export class WKPage implements PageDelegate { } for (const binding of this._page.allBindings()) scripts.push(this._bindingToScript(binding)); - scripts.push(...this._browserContext._evaluateOnNewDocumentSources); - scripts.push(...this._page._evaluateOnNewDocumentSources); + scripts.push(...this._browserContext.initScripts); + scripts.push(...this._page.initScripts); return scripts.join(';'); }