Skip to content

Fix jsdom 28 WebSocket cross-realm Event incompatibility#1161

Open
Copilot wants to merge 8 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 8 commits intodependabot/npm_and_yarn/jsdom-28.1.0from
copilot/sub-pr-1157

Conversation

Copy link

Copilot AI commented Feb 23, 2026

  • Investigate jsdom 28 breaking changes
  • Identify the root cause: cross-realm Event issue with WebSocket
  • Fix WebSocketTransportFactory to detect jsdom environment
  • Test the fix with simple tests (60/60 tests pass)
  • Update tests to reflect new behavior
  • Address code review feedback
  • Verify all non-ROS tests pass
  • Make constructor name check case-insensitive

💡 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.

dependabot bot and others added 2 commits February 23, 2026 06:12
Bumps [jsdom](https://github.com/jsdom/jsdom) from 27.4.0 to 28.1.0.
- [Release notes](https://github.com/jsdom/jsdom/releases)
- [Changelog](https://github.com/jsdom/jsdom/blob/main/Changelog.md)
- [Commits](jsdom/jsdom@27.4.0...28.1.0)

---
updated-dependencies:
- dependency-name: jsdom
  dependency-version: 28.1.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
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
@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/jsdom-28.1.0 branch from a3cbcfc to 7497fc2 Compare March 2, 2026 06:52
Comment on lines +21 to +22
windowConstructorName === "jsdom" ||
windowConstructorName === "JSDOM"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Lower the string before checking equality.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 06df02c. The constructor name is now converted to lowercase before comparison, simplifying the check.

Convert windowConstructorName to lowercase before comparison,
simplifying the check from two comparisons to one.

Co-authored-by: MatthijsBurgh <18014833+MatthijsBurgh@users.noreply.github.com>
Comment on lines +3 to +37
/**
* Detect if we're running in a jsdom environment.
* jsdom provides WebSocket but has cross-realm issues with Event objects.
*/
function isJsdomEnvironment(): boolean {
// Check for jsdom-specific navigator.userAgent
try {
if (navigator.userAgent.includes("jsdom")) {
return true;
}
} catch {
// navigator not available
}

// Check for jsdom-specific window constructor name
if (typeof window !== "undefined") {
const windowConstructorName = window.constructor.name.toLowerCase();
if (windowConstructorName === "jsdom") {
return true;
}
}

// Check for jsdom-specific globals that aren't present in real browsers
if (typeof globalThis !== "undefined") {
// jsdom creates a special Symbol for internal use
const hasJsdomSymbol = Object.getOwnPropertySymbols(globalThis).some(
(sym) => sym.toString().includes("jsdom"),
);
if (hasJsdomSymbol) {
return true;
}
}

return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having test code in application code. Did you try deleting window.WebSocket during test suite setup as an alternative workaround?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, wait, this issue clearly would impact downstream tests as well, from our consumers.

I think that first navigator.userAgent.includes("jsdom") should be sufficient, shouldn't it?

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