mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
chore(chromium): remove obsolete target related code (#1417)
This commit is contained in:
parent
049b336800
commit
b8e79e60c7
@ -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.targetCreated', this._targetCreated.bind(this));
|
||||||
this._session.on('Target.targetDestroyed', this._targetDestroyed.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._session.on('Target.attachedToTarget', this._onAttachedToTarget.bind(this));
|
||||||
this._firstPagePromise = new Promise(f => this._firstPageCallback = f);
|
this._firstPagePromise = new Promise(f => this._firstPageCallback = f);
|
||||||
}
|
}
|
||||||
@ -163,13 +162,6 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
|
|||||||
target._didClose();
|
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) {
|
async _closePage(page: Page) {
|
||||||
await this._session.send('Target.closeTarget', { targetId: CRTarget.fromPage(page)._targetId });
|
await this._session.send('Target.closeTarget', { targetId: CRTarget.fromPage(page)._targetId });
|
||||||
}
|
}
|
||||||
@ -267,7 +259,7 @@ export class CRBrowserContext extends BrowserContextBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pages(): Page[] {
|
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<Page> {
|
async newPage(): Promise<Page> {
|
||||||
@ -401,7 +393,7 @@ export class CRBrowserContext extends BrowserContextBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
backgroundPages(): Page[] {
|
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<CRSession> {
|
async newCDPSession(page: Page): Promise<CRSession> {
|
||||||
|
@ -42,17 +42,16 @@ import { CRTarget } from './crTarget';
|
|||||||
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
||||||
|
|
||||||
export class CRPage implements PageDelegate {
|
export class CRPage implements PageDelegate {
|
||||||
_client: CRSession;
|
readonly _client: CRSession;
|
||||||
_initialized = false;
|
|
||||||
private readonly _page: Page;
|
private readonly _page: Page;
|
||||||
readonly _networkManager: CRNetworkManager;
|
readonly _networkManager: CRNetworkManager;
|
||||||
private _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
|
private readonly _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
|
||||||
private _eventListeners: RegisteredListener[] = [];
|
private _eventListeners: RegisteredListener[] = [];
|
||||||
rawMouse: RawMouseImpl;
|
readonly rawMouse: RawMouseImpl;
|
||||||
rawKeyboard: RawKeyboardImpl;
|
readonly rawKeyboard: RawKeyboardImpl;
|
||||||
private _browser: CRBrowser;
|
private readonly _browser: CRBrowser;
|
||||||
private _pdf: CRPDF;
|
private readonly _pdf: CRPDF;
|
||||||
private _coverage: CRCoverage;
|
private readonly _coverage: CRCoverage;
|
||||||
private readonly _browserContext: CRBrowserContext;
|
private readonly _browserContext: CRBrowserContext;
|
||||||
|
|
||||||
constructor(client: CRSession, browser: CRBrowser, 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.evaluateOnNewDocument(source));
|
||||||
promises.push(this._client.send('Runtime.runIfWaitingForDebugger'));
|
promises.push(this._client.send('Runtime.runIfWaitingForDebugger'));
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
this._initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
didClose() {
|
didClose() {
|
||||||
|
@ -26,14 +26,14 @@ import { CRExecutionContext } from './crExecutionContext';
|
|||||||
const targetSymbol = Symbol('target');
|
const targetSymbol = Symbol('target');
|
||||||
|
|
||||||
export class CRTarget {
|
export class CRTarget {
|
||||||
private _targetInfo: Protocol.Target.TargetInfo;
|
private readonly _targetInfo: Protocol.Target.TargetInfo;
|
||||||
private readonly _browser: CRBrowser;
|
private readonly _browser: CRBrowser;
|
||||||
private readonly _browserContext: CRBrowserContext;
|
private readonly _browserContext: CRBrowserContext;
|
||||||
readonly _targetId: string;
|
readonly _targetId: string;
|
||||||
readonly sessionFactory: () => Promise<CRSession>;
|
readonly sessionFactory: () => Promise<CRSession>;
|
||||||
private _pagePromiseCallback: ((pageOrError: Page | Error) => void) | null = null;
|
private readonly _pagePromise: Promise<Page | Error> | null = null;
|
||||||
private _pagePromise: Promise<Page | Error> | null = null;
|
readonly _crPage: CRPage | null = null;
|
||||||
_crPage: CRPage | null = null;
|
_initializedPage: Page | null = null;
|
||||||
private _workerPromise: Promise<Worker> | null = null;
|
private _workerPromise: Promise<Worker> | null = null;
|
||||||
|
|
||||||
static fromPage(page: Page): CRTarget {
|
static fromPage(page: Page): CRTarget {
|
||||||
@ -61,7 +61,7 @@ export class CRTarget {
|
|||||||
const page = this._crPage.page();
|
const page = this._crPage.page();
|
||||||
(page as any)[targetSymbol] = this;
|
(page as any)[targetSymbol] = this;
|
||||||
session.once(CRSessionEvents.Disconnected, () => page._didDisconnect());
|
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();
|
this._crPage.didClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
_initializedPage(): Page | null {
|
|
||||||
if (this._crPage && this._crPage._initialized)
|
|
||||||
return this._crPage.page();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async pageOrError(): Promise<Page | Error> {
|
async pageOrError(): Promise<Page | Error> {
|
||||||
if (CRTarget.isPageType(this.type()))
|
if (CRTarget.isPageType(this.type()))
|
||||||
return this._pagePromise!;
|
return this._pagePromise!;
|
||||||
@ -100,10 +94,6 @@ export class CRTarget {
|
|||||||
return this._workerPromise;
|
return this._workerPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
url(): string {
|
|
||||||
return this._targetInfo.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
type(): 'page' | 'background_page' | 'service_worker' | 'shared_worker' | 'other' | 'browser' {
|
type(): 'page' | 'background_page' | 'service_worker' | 'shared_worker' | 'other' | 'browser' {
|
||||||
const type = this._targetInfo.type;
|
const type = this._targetInfo.type;
|
||||||
if (type === 'page' || type === 'background_page' || type === 'service_worker' || type === 'shared_worker' || type === 'browser')
|
if (type === 'page' || type === 'background_page' || type === 'service_worker' || type === 'shared_worker' || type === 'browser')
|
||||||
@ -121,8 +111,4 @@ export class CRTarget {
|
|||||||
return null;
|
return null;
|
||||||
return this._browser._targets.get(openerId)!;
|
return this._browser._targets.get(openerId)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
_targetInfoChanged(targetInfo: Protocol.Target.TargetInfo) {
|
|
||||||
this._targetInfo = targetInfo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user