Skip to content

CDP connection hangs when attaching to non-page targets #42

@parkerhancock

Description

@parkerhancock

Problem

In extension mode, CDP connections can hang indefinitely when the relay attempts to attach to non-page targets (service workers, shared workers, browser targets). This causes page.goto() and other operations to timeout even though the page loads correctly in the browser.

Root Cause

When Playwright calls Target.getTargets or Target.setAutoAttach, it discovers all CDP targets including:

  • service_worker targets
  • shared_worker targets
  • browser targets
  • background_page targets

Attempting to route CDP commands to these non-page targets causes hangs because they don't respond to Page domain commands the way page targets do.

Proposed Solution

Filter CDP target discovery to only return actual page targets:

// In relay's CDP command routing
if (command === 'Target.getTargets') {
  const result = await forwardToExtension(command, params);
  // Filter to only page targets
  result.targetInfos = result.targetInfos.filter(
    t => t.type === 'page' && !t.url.startsWith('chrome')
  );
  return result;
}

Working Implementation

I have a fix in my fork:

The fix filters Target.getTargets responses and Target.attachedToTarget events to only include page-type targets with valid URLs.

Happy to submit a PR if there's interest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions