diff --git a/src/chromium/crBrowser.ts b/src/chromium/crBrowser.ts index cb0759abe6..876e35f644 100644 --- a/src/chromium/crBrowser.ts +++ b/src/chromium/crBrowser.ts @@ -83,7 +83,6 @@ export class CRBrowser extends platform.EventEmitter implements Browser { }); this._session.on('Target.targetCreated', this._targetCreated.bind(this)); this._session.on('Target.targetDestroyed', this._targetDestroyed.bind(this)); - this._session.on('Target.targetInfoChanged', this._targetInfoChanged.bind(this)); this._session.on('Target.attachedToTarget', this._onAttachedToTarget.bind(this)); this._firstPagePromise = new Promise(f => this._firstPageCallback = f); } @@ -163,13 +162,6 @@ export class CRBrowser extends platform.EventEmitter implements Browser { target._didClose(); } - _targetInfoChanged(event: Protocol.Target.targetInfoChangedPayload) { - const target = this._targets.get(event.targetInfo.targetId)!; - if (!target) - return; - target._targetInfoChanged(event.targetInfo); - } - async _closePage(page: Page) { await this._session.send('Target.closeTarget', { targetId: CRTarget.fromPage(page)._targetId }); } @@ -267,7 +259,7 @@ export class CRBrowserContext extends BrowserContextBase { } pages(): Page[] { - return this._targets().filter(target => target.type() === 'page').map(target => target._initializedPage()).filter(pageOrNull => !!pageOrNull) as Page[]; + return this._targets().filter(target => target.type() === 'page').map(target => target._initializedPage).filter(pageOrNull => !!pageOrNull) as Page[]; } async newPage(): Promise { @@ -401,7 +393,7 @@ export class CRBrowserContext extends BrowserContextBase { } backgroundPages(): Page[] { - return this._targets().filter(target => target.type() === 'background_page').map(target => target._initializedPage()).filter(pageOrNull => !!pageOrNull) as Page[]; + return this._targets().filter(target => target.type() === 'background_page').map(target => target._initializedPage).filter(pageOrNull => !!pageOrNull) as Page[]; } async newCDPSession(page: Page): Promise { diff --git a/src/chromium/crPage.ts b/src/chromium/crPage.ts index 3d379b5847..3d79d0fcc5 100644 --- a/src/chromium/crPage.ts +++ b/src/chromium/crPage.ts @@ -42,17 +42,16 @@ import { CRTarget } from './crTarget'; const UTILITY_WORLD_NAME = '__playwright_utility_world__'; export class CRPage implements PageDelegate { - _client: CRSession; - _initialized = false; + readonly _client: CRSession; private readonly _page: Page; readonly _networkManager: CRNetworkManager; - private _contextIdToContext = new Map(); + private readonly _contextIdToContext = new Map(); private _eventListeners: RegisteredListener[] = []; - rawMouse: RawMouseImpl; - rawKeyboard: RawKeyboardImpl; - private _browser: CRBrowser; - private _pdf: CRPDF; - private _coverage: CRCoverage; + readonly rawMouse: RawMouseImpl; + readonly rawKeyboard: RawKeyboardImpl; + private readonly _browser: CRBrowser; + private readonly _pdf: CRPDF; + private readonly _coverage: CRCoverage; private readonly _browserContext: CRBrowserContext; constructor(client: CRSession, browser: CRBrowser, browserContext: CRBrowserContext) { @@ -144,7 +143,6 @@ export class CRPage implements PageDelegate { promises.push(this.evaluateOnNewDocument(source)); promises.push(this._client.send('Runtime.runIfWaitingForDebugger')); await Promise.all(promises); - this._initialized = true; } didClose() { diff --git a/src/chromium/crTarget.ts b/src/chromium/crTarget.ts index 594c7b7b5d..e06b72b0ad 100644 --- a/src/chromium/crTarget.ts +++ b/src/chromium/crTarget.ts @@ -26,14 +26,14 @@ import { CRExecutionContext } from './crExecutionContext'; const targetSymbol = Symbol('target'); export class CRTarget { - private _targetInfo: Protocol.Target.TargetInfo; + private readonly _targetInfo: Protocol.Target.TargetInfo; private readonly _browser: CRBrowser; private readonly _browserContext: CRBrowserContext; readonly _targetId: string; readonly sessionFactory: () => Promise; - private _pagePromiseCallback: ((pageOrError: Page | Error) => void) | null = null; - private _pagePromise: Promise | null = null; - _crPage: CRPage | null = null; + private readonly _pagePromise: Promise | null = null; + readonly _crPage: CRPage | null = null; + _initializedPage: Page | null = null; private _workerPromise: Promise | null = null; static fromPage(page: Page): CRTarget { @@ -61,7 +61,7 @@ export class CRTarget { const page = this._crPage.page(); (page as any)[targetSymbol] = this; session.once(CRSessionEvents.Disconnected, () => page._didDisconnect()); - this._pagePromise = this._crPage.initialize().then(() => page).catch(e => e); + this._pagePromise = this._crPage.initialize().then(() => this._initializedPage = page).catch(e => e); } } @@ -70,12 +70,6 @@ export class CRTarget { this._crPage.didClose(); } - _initializedPage(): Page | null { - if (this._crPage && this._crPage._initialized) - return this._crPage.page(); - return null; - } - async pageOrError(): Promise { if (CRTarget.isPageType(this.type())) return this._pagePromise!; @@ -100,10 +94,6 @@ export class CRTarget { return this._workerPromise; } - url(): string { - return this._targetInfo.url; - } - type(): 'page' | 'background_page' | 'service_worker' | 'shared_worker' | 'other' | 'browser' { const type = this._targetInfo.type; if (type === 'page' || type === 'background_page' || type === 'service_worker' || type === 'shared_worker' || type === 'browser') @@ -121,8 +111,4 @@ export class CRTarget { return null; return this._browser._targets.get(openerId)!; } - - _targetInfoChanged(targetInfo: Protocol.Target.TargetInfo) { - this._targetInfo = targetInfo; - } }