Skip to content

Comments

Fix jsdom 28 WebSocket cross-realm Event incompatibility#1161

Open
Copilot wants to merge 5 commits intodependabot/npm_and_yarn/jsdom-28.1.0from
copilot/sub-pr-1157
Open

Fix jsdom 28 WebSocket cross-realm Event incompatibility#1161
Copilot wants to merge 5 commits intodependabot/npm_and_yarn/jsdom-28.1.0from
copilot/sub-pr-1157

Conversation

Copy link

Copilot AI commented Feb 23, 2026

jsdom 28 creates Event objects in an isolated realm, causing Node.js's native WebSocket to fail validation with TypeError: The "event" argument must be an instance of Event. Received an instance of Event.

Changes

  • WebSocketTransportFactory: Added jsdom environment detection to force ws package usage instead of native WebSocket

    • Checks navigator.userAgent, window constructor name, and jsdom-specific Symbols
    • Prevents cross-realm Event issues by keeping all WebSocket operations in Node.js realm
  • transport.test.ts: Updated expectations to reflect WsWebSocketTransport usage in jsdom environments

Technical Context

jsdom 28's improved prototype chain isolation means:

// Before: Uses jsdom's WebSocket → creates Events in jsdom realm → fails Node.js validation
if (typeof WebSocket === "function") {
  return new NativeWebSocketTransport(new WebSocket(url));
}

// After: Detects jsdom → uses ws package → Events stay in Node.js realm
if (typeof WebSocket === "function" && !isJsdomEnvironment()) {
  return new NativeWebSocketTransport(new WebSocket(url));
}

Real browsers unaffected - detection is specific to jsdom's implementation details.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 23, 2026 07:05
Co-authored-by: MatthijsBurgh <18014833+MatthijsBurgh@users.noreply.github.com>
Add detection for jsdom environment in WebSocketTransportFactory to
prevent using jsdom's native WebSocket which has cross-realm Event
issues. This forces the use of the ws package in jsdom environments,
avoiding the ERR_INVALID_ARG_TYPE error when dispatching events.

Co-authored-by: MatthijsBurgh <18014833+MatthijsBurgh@users.noreply.github.com>
Update transport test to expect WsWebSocketTransport in jsdom
environments, as the fix intentionally uses ws package instead of
native WebSocket to avoid cross-realm Event issues.

Co-authored-by: MatthijsBurgh <18014833+MatthijsBurgh@users.noreply.github.com>
Enhanced jsdom environment detection with multiple checks:
- Try-catch for navigator.userAgent check (avoids circular lint rules)
- Window constructor name check
- jsdom-specific Symbol check in globalThis

Also simplified test name per code review feedback.

Co-authored-by: MatthijsBurgh <18014833+MatthijsBurgh@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 23, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/nodejs/undici/issues/2663/comments
    • Triggering command: /usr/bin/curl curl -sL REDACTED /bin/sh -c -dev_2%3a4.35-0ubuntu0.20.04.1_amd64.deb -I de/node/bin/bash ter3@5.0.1/dist/bash /home/REDACTED/.ca--norc -I t -c node install.js --64 apt-cache -ignore-src -y (http block)
  • npmlookup.jspm.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/roslibjs/roslibjs/node_modules/.bin/jspm install --release --provider unpkg (dns block)
  • snapshots.ros.org
    • Triggering command: /usr/lib/apt/methods/http /usr/lib/apt/methods/http l/config om/RobotWebTools/home/REDACTED/.cache/node-gyp/24.13.0/deps/uv/include e (dns block)
    • Triggering command: /usr/lib/apt/methods/http /usr/lib/apt/methods/http (dns block)
    • Triggering command: /usr/lib/apt/methods/http /usr/lib/apt/methods/http --local 0/x64/lib/node_m/var/cache/apt/archives/*.deb bash arch�� --log /var/lib/docker/buildkit/executor/runc-log.json /.bin/node json om&gt; --bundle chmod /.bi�� /tmp/apt-key-gpghome.jiGVjXKnO0 13.0/deps/openssl/openssl/include /home/REDACTED/work/roslibjs/node_modules/.bin/sh 13.0/include/nodsh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Bump jsdom from 27.4.0 to 28.1.0 Fix jsdom 28 WebSocket cross-realm Event incompatibility Feb 23, 2026
Copilot AI requested a review from MatthijsBurgh February 23, 2026 07:16
@MatthijsBurgh MatthijsBurgh marked this pull request as ready for review February 23, 2026 07:56
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.

2 participants