Skip to content

Subsequent Option+Click selections not received after first one #19

@syh52

Description

@syh52

Bug Description

After the first successful element selection, all subsequent Option+Click selections fail to update the MCP server data. The get-pointed-element tool keeps returning the stale first element.

Steps to Reproduce

  1. Restart browser (or restart Claude Code which restarts the MCP server)
  2. Refresh the target webpage
  3. Option+Click an element → works (MCP server receives the data)
  4. Wait ~10+ seconds
  5. Option+Click a different element → fails (MCP server still returns the old element)

Root Cause Analysis

After reading the source code, I believe this is related to the Manifest V3 service worker lifecycle:

  1. First click works because the service worker is active after browser startup
  2. ElementSenderService has a 10-second IDLE_DURATION that disconnects the WebSocket
  3. After disconnect, Chrome kills the idle service worker (MV3 behavior)
  4. On subsequent clicks, chrome.runtime.sendMessage from content script wakes up the service worker
  5. However, there's a race condition: chrome.runtime.onMessage.addListener in background.ts may not be registered before the message arrives, OR initialize() hasn't completed yet when the message handler fires

Suggested Fix

Consider one of:

  • Use chrome.runtime.onMessage at the top level (before initialize()) to ensure the listener is always registered on service worker startup
  • Add a keep-alive mechanism (e.g., periodic chrome.alarms) to prevent service worker termination
  • In sendElement, add a retry when the first WebSocket connection attempt after idle fails

Environment

  • macOS Darwin 25.2.0
  • Chrome (latest)
  • MCP Pointer Chrome Extension v0.6.0
  • MCP Server: @mcp-pointer/server@latest via npx
  • Client: Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions