diff --git a/.github/workflows/puppeteer.yml b/.github/workflows/puppeteer.yml index 9bc82c4a70..f507a42975 100644 --- a/.github/workflows/puppeteer.yml +++ b/.github/workflows/puppeteer.yml @@ -30,8 +30,6 @@ jobs: uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 with: path: 'bidi' - - name: Set up FFmpeg - uses: FedericoCarboni/setup-ffmpeg@36c6454b5a2348e7794ba2d82a21506605921e3d # v3.0.0 - name: Set up Node.js uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: diff --git a/src/bidiMapper/modules/cdp/CdpTargetManager.ts b/src/bidiMapper/modules/cdp/CdpTargetManager.ts index 74c02ce4fa..6306efd692 100644 --- a/src/bidiMapper/modules/cdp/CdpTargetManager.ts +++ b/src/bidiMapper/modules/cdp/CdpTargetManager.ts @@ -43,6 +43,7 @@ const cdpToBidiTargetTypes = { export class CdpTargetManager { readonly #browserCdpClient: CdpClient; readonly #cdpConnection: CdpConnection; + readonly #targetIdsToBeIgnoredByAutoAttach = new Set(); readonly #selfTargetId: string; readonly #eventManager: EventManager; @@ -70,6 +71,7 @@ export class CdpTargetManager { ) { this.#cdpConnection = cdpConnection; this.#browserCdpClient = browserCdpClient; + this.#targetIdsToBeIgnoredByAutoAttach.add(selfTargetId); this.#selfTargetId = selfTargetId; this.#eventManager = eventManager; this.#browsingContextStorage = browsingContextStorage; @@ -149,12 +151,41 @@ export class CdpTargetManager { parentSessionCdpClient: CdpClient ) { const {sessionId, targetInfo} = params; + + if (this.#selfTargetId !== targetInfo.targetId) { + // Mapper only needs one session per target. If we receive additional + // auto-attached sessions, that is very likely coming from custom CDP + // sessions. + if (this.#targetIdsToBeIgnoredByAutoAttach.has(targetInfo.targetId)) { + // Return to leave the session be unless it is a service worker. + if (targetInfo.type === 'service_worker' && params.waitingForDebugger) { + // Service workers are special case because they attach to the + // browser target and the page target during the regular + // auto-attach and might hang if the CDP session is not + // detached. + const targetCdpClient = this.#cdpConnection.getCdpClient(sessionId); + targetCdpClient + .sendCommand('Runtime.runIfWaitingForDebugger') + .then(() => + parentSessionCdpClient.sendCommand( + 'Target.detachFromTarget', + params + ) + ) + .catch((error) => this.#logger?.(LogType.debugError, error)); + } + return; + } + this.#targetIdsToBeIgnoredByAutoAttach.add(targetInfo.targetId); + } + const targetCdpClient = this.#cdpConnection.getCdpClient(sessionId); switch (targetInfo.type) { case 'page': case 'iframe': { - if (targetInfo.targetId === this.#selfTargetId) { + if (this.#selfTargetId === targetInfo.targetId) { + // break to detach from the self target. break; } @@ -162,7 +193,7 @@ export class CdpTargetManager { const maybeContext = this.#browsingContextStorage.findContext( targetInfo.targetId ); - if (maybeContext) { + if (maybeContext && targetInfo.type === 'iframe') { // OOPiF. maybeContext.updateCdpTarget(cdpTarget); } else { diff --git a/tests/service_worker/test_navigate.py b/tests/service_worker/test_navigate.py index b416659228..a3b98535f9 100644 --- a/tests/service_worker/test_navigate.py +++ b/tests/service_worker/test_navigate.py @@ -24,7 +24,7 @@ }], indirect=True) async def test_serviceWorker_acceptInsecureCertsCapability_respected( - websocket, context_id, url_bad_ssl, local_server_bad_ssl): + websocket, context_id, local_server_bad_ssl): service_worker_script = local_server_bad_ssl.url_200( content='', content_type='text/javascript') service_worker_page = local_server_bad_ssl.url_200(content=f"""