Skip to content

Fix window.atob/window.btoa runtime crashes under Node#1949

Open
batbone wants to merge 1 commit intoChromeDevTools:mainfrom
batbone:fix/node-window-atob-shim
Open

Fix window.atob/window.btoa runtime crashes under Node#1949
batbone wants to merge 1 commit intoChromeDevTools:mainfrom
batbone:fix/node-window-atob-shim

Conversation

@batbone
Copy link
Copy Markdown

@batbone batbone commented Apr 23, 2026

Summary

  • define a Node-safe globalThis.window alias before vendored DevTools/Lighthouse runtime paths execute
  • avoid ReferenceError: window is not defined when runtime code calls window.atob / window.btoa

Context

The published chrome-devtools-mcp bundle currently includes vendored runtime code paths that call window.atob and window.btoa even when the MCP server is running under Node.js. In that environment, Node provides global atob/btoa, but not a browser window object, which causes crashes during affected flows (for example SSE parsing through the MCP transport).

This patch keeps the fix narrow by exposing globalThis.window = globalThis when window is otherwise absent, so those vendored runtime calls resolve correctly in Node.

Here is the original error:

[mcp-proxy] establishing new SSE stream for session ID 6081ef15-f8a4-4f81-9594-a80f7cf8cb56
file:///Users/evar/.npm/_npx/15c61037b1978c83/node_modules/chrome-devtools-mcp/build/src/third_party/index.js:129773
        const binString = window.atob(chunk);
                          ^

ReferenceError: window is not defined
    at Base64TextDecoder.addBase64Chunk (file:///Users/evar/.npm/_npx/15c61037b1978c83/node_modules/chrome-devtools-mcp/build/src/third_party/index.js:129773:27)
    at ServerSentEventsParser.addBase64Chunk (file:///Users/evar/.npm/_npx/15c61037b1978c83/node_modules/chrome-devtools-mcp/build/src/third_party/index.js:129704:29)
    at file:///Users/evar/.npm/_npx/15c61037b1978c83/node_modules/chrome-devtools-mcp/build/src/third_party/index.js:129793:40
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@batbone
Copy link
Copy Markdown
Author

batbone commented Apr 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

This fix is trivial and does not CLA.

@OrKoN
Copy link
Copy Markdown
Collaborator

OrKoN commented Apr 24, 2026

what chrome-devtools-mcp version are you seeing this with?

@OrKoN
Copy link
Copy Markdown
Collaborator

OrKoN commented Apr 24, 2026

I have fixed the specific occurrence upstream https://crrev.com/c/7790303 I think this code should not be running in the latest mcp server version and I was not able to reproduce it on a page with sse streams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants