mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00: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.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<Page> {
 | 
			
		||||
@ -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<CRSession> {
 | 
			
		||||
 | 
			
		||||
@ -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<number, dom.FrameExecutionContext>();
 | 
			
		||||
  private readonly _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
 | 
			
		||||
  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() {
 | 
			
		||||
 | 
			
		||||
@ -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<CRSession>;
 | 
			
		||||
  private _pagePromiseCallback: ((pageOrError: Page | Error) => void) | null = null;
 | 
			
		||||
  private _pagePromise: Promise<Page | Error> | null = null;
 | 
			
		||||
  _crPage: CRPage | null = null;
 | 
			
		||||
  private readonly _pagePromise: Promise<Page | Error> | null = null;
 | 
			
		||||
  readonly _crPage: CRPage | null = null;
 | 
			
		||||
  _initializedPage: Page | null = null;
 | 
			
		||||
  private _workerPromise: Promise<Worker> | 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<Page | Error> {
 | 
			
		||||
    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;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user