Skip to content

Commit c975384

Browse files
authored
lib: enable WebSocket by default
PR-URL: #51594 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 9a4052c commit c975384

File tree

10 files changed

+32
-25
lines changed

10 files changed

+32
-25
lines changed

benchmark/websocket/simple.js

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const common = require('../common.js');
44
const crypto = require('crypto');
55
const http = require('http');
6-
const { WebSocket } = require('../../deps/undici/undici');
76

87
const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
98

doc/api/cli.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -949,16 +949,6 @@ added: v12.3.0
949949

950950
Enable experimental WebAssembly module support.
951951

952-
### `--experimental-websocket`
953-
954-
<!-- YAML
955-
added:
956-
- v21.0.0
957-
- v20.10.0
958-
-->
959-
960-
Enable experimental [`WebSocket`][] support.
961-
962952
### `--force-context-aware`
963953

964954
<!-- YAML
@@ -1377,6 +1367,14 @@ added: v16.6.0
13771367

13781368
Use this flag to disable top-level await in REPL.
13791369

1370+
### `--no-experimental-websocket`
1371+
1372+
<!-- YAML
1373+
added: REPLACEME
1374+
-->
1375+
1376+
Use this flag to disable experimental [`WebSocket`][] support.
1377+
13801378
### `--no-extra-info-on-fatal-exception`
13811379

13821380
<!-- YAML
@@ -2511,7 +2509,6 @@ Node.js options that are allowed are:
25112509
* `--experimental-vm-modules`
25122510
* `--experimental-wasi-unstable-preview1`
25132511
* `--experimental-wasm-modules`
2514-
* `--experimental-websocket`
25152512
* `--force-context-aware`
25162513
* `--force-fips`
25172514
* `--force-node-api-uncaught-exceptions-policy`
@@ -2536,6 +2533,7 @@ Node.js options that are allowed are:
25362533
* `--no-experimental-global-navigator`
25372534
* `--no-experimental-global-webcrypto`
25382535
* `--no-experimental-repl-await`
2536+
* `--no-experimental-websocket`
25392537
* `--no-extra-info-on-fatal-exception`
25402538
* `--no-force-async-hooks-checks`
25412539
* `--no-global-search-paths`

doc/api/globals.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1097,12 +1097,16 @@ The object that acts as the namespace for all W3C
10971097
added:
10981098
- v21.0.0
10991099
- v20.10.0
1100+
changes:
1101+
- version: REPLACEME
1102+
pr-url: https://github.com/nodejs/node/pull/51594
1103+
description: No longer behind `--experimental-websocket` CLI flag.
11001104
-->
11011105

11021106
> Stability: 1 - Experimental.
11031107
1104-
A browser-compatible implementation of [`WebSocket`][]. Enable this API
1105-
with the [`--experimental-websocket`][] CLI flag.
1108+
A browser-compatible implementation of [`WebSocket`][]. Disable this API
1109+
with the [`--no-experimental-websocket`][] CLI flag.
11061110

11071111
## Class: `WritableStream`
11081112

@@ -1139,10 +1143,10 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
11391143
[Navigator API]: https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object
11401144
[RFC 5646]: https://www.rfc-editor.org/rfc/rfc5646.txt
11411145
[Web Crypto API]: webcrypto.md
1142-
[`--experimental-websocket`]: cli.md#--experimental-websocket
11431146
[`--no-experimental-global-customevent`]: cli.md#--no-experimental-global-customevent
11441147
[`--no-experimental-global-navigator`]: cli.md#--no-experimental-global-navigator
11451148
[`--no-experimental-global-webcrypto`]: cli.md#--no-experimental-global-webcrypto
1149+
[`--no-experimental-websocket`]: cli.md#--no-experimental-websocket
11461150
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
11471151
[`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy
11481152
[`CompressionStream`]: webstreams.md#class-compressionstream

doc/node.1

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ Use this flag to enable ShadowRealm support.
186186
.It Fl -experimental-test-coverage
187187
Enable code coverage in the test runner.
188188
.
189-
.It Fl -experimental-websocket
190-
Enable experimental support for the WebSocket API.
191-
.
192189
.It Fl -no-experimental-fetch
193190
Disable experimental support for the Fetch API.
194191
.
192+
.It Fl -no-experimental-websocket
193+
Disable experimental support for the WebSocket API.
194+
.
195195
.It Fl -no-experimental-global-customevent
196196
Disable exposition of the CustomEvent on the global scope.
197197
.

lib/internal/bootstrap/web/exposed-window-or-worker.js

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', [
9292
'FormData', 'Headers', 'Request', 'Response',
9393
]);
9494

95+
// https://websockets.spec.whatwg.org/
96+
exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['WebSocket']);
97+
9598
// The WebAssembly Web API which relies on Response.
9699
// https:// webassembly.github.io/spec/web-api/#streaming-modules
97100
internalBinding('wasm_web_api').setImplementation((streamState, source) => {

lib/internal/process/pre_execution.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ function setupUndici() {
315315
delete globalThis.Response;
316316
}
317317

318-
if (!getEmbedderOptions().noBrowserGlobals && getOptionValue('--experimental-websocket')) {
319-
exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['WebSocket']);
318+
if (getOptionValue('--no-experimental-websocket')) {
319+
delete globalThis.WebSocket;
320320
}
321321
}
322322

src/node_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class EnvironmentOptions : public Options {
108108
std::string dns_result_order;
109109
bool enable_source_maps = false;
110110
bool experimental_fetch = true;
111-
bool experimental_websocket = false;
111+
bool experimental_websocket = true;
112112
bool experimental_global_customevent = true;
113113
bool experimental_global_navigator = true;
114114
bool experimental_global_web_crypto = true;

test/common/index.js

-3
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,6 @@ if (global.ReadableStream) {
369369
global.DecompressionStream,
370370
);
371371
}
372-
if (global.WebSocket) {
373-
knownGlobals.push(WebSocket);
374-
}
375372

376373
function allowGlobals(...allowlist) {
377374
knownGlobals = knownGlobals.concat(allowlist);
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Flags: --no-experimental-websocket
2+
'use strict';
3+
4+
require('../common');
5+
const assert = require('assert');
6+
7+
assert.strictEqual(typeof WebSocket, 'undefined');

test/parallel/test-websocket.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Flags: --experimental-websocket
21
'use strict';
32

43
require('../common');

0 commit comments

Comments
 (0)