Skip to content

Commit

Permalink
lib: enable WebSocket by default
Browse files Browse the repository at this point in the history
PR-URL: nodejs#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>
  • Loading branch information
Uzlopak authored and marco-ippolito committed Feb 19, 2024
1 parent 77db2af commit bedb9db
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 25 deletions.
1 change: 0 additions & 1 deletion benchmark/websocket/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const common = require('../common.js');
const crypto = require('crypto');
const http = require('http');
const { WebSocket } = require('../../deps/undici/undici');

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

Expand Down
20 changes: 9 additions & 11 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -949,16 +949,6 @@ added: v12.3.0

Enable experimental WebAssembly module support.

### `--experimental-websocket`

<!-- YAML
added:
- v21.0.0
- v20.10.0
-->

Enable experimental [`WebSocket`][] support.

### `--force-context-aware`

<!-- YAML
Expand Down Expand Up @@ -1377,6 +1367,14 @@ added: v16.6.0

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

### `--no-experimental-websocket`

<!-- YAML
added: REPLACEME
-->

Use this flag to disable experimental [`WebSocket`][] support.

### `--no-extra-info-on-fatal-exception`

<!-- YAML
Expand Down Expand Up @@ -2511,7 +2509,6 @@ Node.js options that are allowed are:
* `--experimental-vm-modules`
* `--experimental-wasi-unstable-preview1`
* `--experimental-wasm-modules`
* `--experimental-websocket`
* `--force-context-aware`
* `--force-fips`
* `--force-node-api-uncaught-exceptions-policy`
Expand All @@ -2536,6 +2533,7 @@ Node.js options that are allowed are:
* `--no-experimental-global-navigator`
* `--no-experimental-global-webcrypto`
* `--no-experimental-repl-await`
* `--no-experimental-websocket`
* `--no-extra-info-on-fatal-exception`
* `--no-force-async-hooks-checks`
* `--no-global-search-paths`
Expand Down
10 changes: 7 additions & 3 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -1097,12 +1097,16 @@ The object that acts as the namespace for all W3C
added:
- v21.0.0
- v20.10.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/51594
description: No longer behind `--experimental-websocket` CLI flag.
-->

> Stability: 1 - Experimental.
A browser-compatible implementation of [`WebSocket`][]. Enable this API
with the [`--experimental-websocket`][] CLI flag.
A browser-compatible implementation of [`WebSocket`][]. Disable this API
with the [`--no-experimental-websocket`][] CLI flag.

## Class: `WritableStream`

Expand Down Expand Up @@ -1139,10 +1143,10 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
[Navigator API]: https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object
[RFC 5646]: https://www.rfc-editor.org/rfc/rfc5646.txt
[Web Crypto API]: webcrypto.md
[`--experimental-websocket`]: cli.md#--experimental-websocket
[`--no-experimental-global-customevent`]: cli.md#--no-experimental-global-customevent
[`--no-experimental-global-navigator`]: cli.md#--no-experimental-global-navigator
[`--no-experimental-global-webcrypto`]: cli.md#--no-experimental-global-webcrypto
[`--no-experimental-websocket`]: cli.md#--no-experimental-websocket
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
[`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy
[`CompressionStream`]: webstreams.md#class-compressionstream
Expand Down
6 changes: 3 additions & 3 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ Use this flag to enable ShadowRealm support.
.It Fl -experimental-test-coverage
Enable code coverage in the test runner.
.
.It Fl -experimental-websocket
Enable experimental support for the WebSocket API.
.
.It Fl -no-experimental-fetch
Disable experimental support for the Fetch API.
.
.It Fl -no-experimental-websocket
Disable experimental support for the WebSocket API.
.
.It Fl -no-experimental-global-customevent
Disable exposition of the CustomEvent on the global scope.
.
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/bootstrap/web/exposed-window-or-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', [
'FormData', 'Headers', 'Request', 'Response',
]);

// https://websockets.spec.whatwg.org/
exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['WebSocket']);

// The WebAssembly Web API which relies on Response.
// https:// webassembly.github.io/spec/web-api/#streaming-modules
internalBinding('wasm_web_api').setImplementation((streamState, source) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ function setupUndici() {
delete globalThis.Response;
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class EnvironmentOptions : public Options {
std::string dns_result_order;
bool enable_source_maps = false;
bool experimental_fetch = true;
bool experimental_websocket = false;
bool experimental_websocket = true;
bool experimental_global_customevent = true;
bool experimental_global_navigator = true;
bool experimental_global_web_crypto = true;
Expand Down
3 changes: 0 additions & 3 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,6 @@ if (global.ReadableStream) {
global.DecompressionStream,
);
}
if (global.WebSocket) {
knownGlobals.push(WebSocket);
}

function allowGlobals(...allowlist) {
knownGlobals = knownGlobals.concat(allowlist);
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-websocket-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Flags: --no-experimental-websocket
'use strict';

require('../common');
const assert = require('assert');

assert.strictEqual(typeof WebSocket, 'undefined');
1 change: 0 additions & 1 deletion test/parallel/test-websocket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Flags: --experimental-websocket
'use strict';

require('../common');
Expand Down

0 comments on commit bedb9db

Please sign in to comment.