Skip to content

Use globalThis.WebSocket in Node.js before of require('ws') #26676

@jeroen

Description

@jeroen

We can use the Native WebSocket Client in Node.js on Node >= 21 instsead of hardcoding require('ws')

#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
WebSocketConstructor = /** @type{(typeof WebSocket)} */(require('ws'));
} else
#endif // ENVIRONMENT_MAY_BE_NODE

An additional reason is that applications may use a proxy for globalThis.WebSocket to proxy webSocket communication through the main thread. However this gets ignored when emscripten hardcodes require('ws').

See

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions