read_console_messages returns duplicate messages from multiple execution contexts
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
- Open a page that has a service worker (e.g., any PWA)
- The page logs a message via
console.log("sync complete") - Call
read_console_messageson that tab - 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:
- Track
Runtime.executionContextCreatedevents - Identify main-world contexts:
auxData.isDefault === trueANDauxData.type === 'default' - Only process
consoleAPICalledevents whereexecutionContextIdmatches a tracked main-world context - Drop events with
executionContextId === 0(stale replayed messages whenRuntime.enableis 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
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗