fix(cdp): resume filtered targets to avoid hung navigations

This commit is contained in:
Tommy D. Rossi
2026-01-26 13:54:47 +01:00
parent 67e8976d2f
commit 3fa98ab689
+25 -1
View File
@@ -884,10 +884,34 @@ export async function startPlayWriterCDPRelayServer({
if (method === 'Target.attachedToTarget') {
const targetParams = params as Protocol.Target.AttachedToTargetEvent
// Filter out restricted targets (non-page types, extension pages, chrome:// URLs, etc.)
// Filter out restricted targets (unsupported types, extension pages, chrome:// URLs, etc.)
// These targets can't be properly controlled through chrome.debugger API
// and cause issues when Playwright tries to initialize them (issue #14)
if (isRestrictedTarget(targetParams.targetInfo)) {
// NOTE: We auto-resume restricted targets that were auto-attached with
// waitForDebuggerOnStart=true. We still filter them out, but Chrome pauses
// these targets until Runtime.runIfWaitingForDebugger is sent; if we dont
// resume, OOPIF navigations (e.g. Google RotateCookiesPage) can hang and the
// main tab spinner never finishes.
//
// To support iframes directly in the future, wed need to forward
// Target.attachedToTarget for type==='iframe', wire child session routing
// (commands/events per session), and allow iframes in isRestrictedTarget,
// plus add tests for iframe navigation + network lifecycles.
if (targetParams.waitingForDebugger && targetParams.sessionId) {
void sendToExtension({
method: 'forwardCDPCommand',
params: {
sessionId: targetParams.sessionId,
method: 'Runtime.runIfWaitingForDebugger',
params: {},
source: 'server',
},
}).catch((error) => {
const message = error instanceof Error ? error.message : String(error)
logger?.log(pc.yellow('[Server] Failed to resume restricted target:'), message)
})
}
logger?.log(pc.gray(`[Server] Ignoring restricted target: ${targetParams.targetInfo.type} (${targetParams.targetInfo.url})`))
return
}