Skip to content

Extension mode: pages lost after relay disconnect/reconnect #41

@parkerhancock

Description

@parkerhancock

Problem

In extension mode, the relay server loses track of pages when the extension disconnects and reconnects. This happens frequently during normal usage (extension reload, browser restart, network hiccups).

Symptoms:

  • client.list() returns empty array despite Chrome tabs still existing
  • client.page("name") creates new tabs instead of finding existing ones
  • Tab accumulation: users end up with 30+ orphaned tabs they can't close via API

Root Cause

The relay stores page name→tabId mappings only in memory. When the extension reconnects:

  1. The WebSocket connection resets
  2. In-memory mappings are lost
  3. Chrome tabs still exist but relay doesn't know about them

Additionally, the extension doesn't initialize CDP domains (Page, Network, Runtime) after attaching the debugger, causing Playwright to miss navigation events.

Proposed Solution

  1. Persist page mappings to disk (~/.dev-browser/pages.json) with {name, targetId, url, lastSeen}
  2. Recover on reconnect by matching persisted entries to available tabs by URL
  3. Initialize CDP domains in extension's TabManager after debugger attach
  4. Preserve debugger attachments on unexpected disconnect (only detach on intentional user action)

Working Implementation

I have a working fix in my fork that addresses all these issues:

Key commits:

  • b7ca586 - Persist page mappings across extension disconnects
  • 0b49b4a - Preserve session state across extension reconnects
  • 648f049 - Enable Page domain on debugger attach

Happy to submit a PR if there's interest.

Related

This may help with #39 (extension stuck on "Connecting") by improving connection resilience.

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