read_console_messages returns duplicate messages from multiple execution contexts

Resolved 💬 1 comment Opened Mar 4, 2026 by obrienatimothy-sketch Closed Mar 28, 2026

Description

The read_console_messages Chrome MCP tool returns duplicate console messages. A single console.log("hello") on a page can appear 2-3 times in the tool's output. This is because the Chrome DevTools Protocol (CDP) fires Runtime.consoleAPICalled once per execution context in the tab (main page, service worker, extension content scripts), and the tool doesn't filter by context.

Steps to Reproduce

  1. Open a page that has a service worker (e.g., any PWA)
  2. The page logs a message via console.log("sync complete")
  3. Call read_console_messages on that tab
  4. The message appears 2-3 times in the results

Expected Behavior

Each console.log call should appear once in the output, from the main page execution context only.

Actual Behavior

Messages are duplicated — once per execution context that exists in the tab (main world, service worker context, extension content script isolated worlds). There is no way to distinguish or filter by context, since the tool doesn't expose executionContextId in its output.

Impact

  • False positive bug investigations: Duplicate console messages led to investigating a non-existent "double API call" bug, wasting significant debugging time before server logs proved only one call occurred.
  • Message counts are unreliable: Any workflow that counts console messages (e.g., "did this fire once or twice?") produces incorrect results.

Suggested Fix

Both Puppeteer and Playwright solve this exact problem by filtering Runtime.consoleAPICalled events to only include main-world execution contexts:

  1. Track Runtime.executionContextCreated events
  2. Identify main-world contexts: auxData.isDefault === true AND auxData.type === 'default'
  3. Only process consoleAPICalled events where executionContextId matches a tracked main-world context
  4. Drop events with executionContextId === 0 (stale replayed messages when Runtime.enable is called)

Playwright reference: crPage.ts lines 660-674 and 787-809

Puppeteer reference: FrameManager.ts lines 539-571

Current Workaround

Using read_network_requests with urlPattern instead of read_console_messages for verifying API calls, and using server-side logs as ground truth for counting operations.

Environment

  • Claude Code on Windows 11
  • Chrome MCP extension (Claude in Chrome)
  • Testing against a PWA with a service worker

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗