diff --git a/packages/puppeteer-core/src/cdp/ChromeTargetManager.ts b/packages/puppeteer-core/src/cdp/ChromeTargetManager.ts index f857e28f4da8b..97a72a947f40d 100644 --- a/packages/puppeteer-core/src/cdp/ChromeTargetManager.ts +++ b/packages/puppeteer-core/src/cdp/ChromeTargetManager.ts @@ -127,14 +127,6 @@ export class ChromeTargetManager this.#onSessionDetached ); this.#setupAttachmentListeners(this.#connection); - - this.#connection - .send('Target.setDiscoverTargets', { - discover: true, - filter: this.#discoveryFilter, - }) - .then(this.#storeExistingTargetsForInit) - .catch(debugError); } #storeExistingTargetsForInit = () => { @@ -163,6 +155,13 @@ export class ChromeTargetManager }; async initialize(): Promise { + await this.#connection.send('Target.setDiscoverTargets', { + discover: true, + filter: this.#discoveryFilter, + }); + + this.#storeExistingTargetsForInit(); + await this.#connection.send('Target.setAutoAttach', { waitForDebuggerOnStart: true, flatten: true,