diff --git a/docs/api/command-line-switches.md b/docs/api/command-line-switches.md index 8026d9351d37..e5ab9dcbe94d 100644 --- a/docs/api/command-line-switches.md +++ b/docs/api/command-line-switches.md @@ -325,6 +325,10 @@ Set the directory to which all Node.js diagnostic output files are written. Defa Affects the default output directory of [v8.setHeapSnapshotNearHeapLimit](https://nodejs.org/docs/latest/api/v8.html#v8setheapsnapshotnearheaplimitlimit). +### `--no-experimental-global-navigator` + +Disable exposition of [Navigator API][] on the global scope from Node.js. + [app]: app.md [append-switch]: command-line.md#commandlineappendswitchswitch-value [debugging-main-process]: ../tutorial/debugging-main-process.md @@ -333,3 +337,4 @@ Affects the default output directory of [v8.setHeapSnapshotNearHeapLimit](https: [play-silent-audio]: https://github.com/atom/atom/pull/9485/files [ready]: app.md#event-ready [severities]: https://source.chromium.org/chromium/chromium/src/+/main:base/logging.h?q=logging::LogSeverity&ss=chromium +[Navigator API]: https://github.com/nodejs/node/blob/main/doc/api/globals.md#navigator diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 4ff3fda19c1f..c1b1b3e4ef62 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -375,6 +375,7 @@ bool IsAllowedOption(const std::string_view option) { "--throw-deprecation", "--trace-deprecation", "--trace-warnings", + "--no-experimental-global-navigator", }); if (debug_options.contains(option)) diff --git a/spec/api-utility-process-spec.ts b/spec/api-utility-process-spec.ts index dfd62945ec6b..5a132a42ec91 100644 --- a/spec/api-utility-process-spec.ts +++ b/spec/api-utility-process-spec.ts @@ -800,5 +800,33 @@ describe('utilityProcess module', () => { expect(stat.size).to.be.greaterThan(0); await fs.rm(tmpDir, { recursive: true }); }); + + it('supports --no-experimental-global-navigator flag', async () => { + { + const child = utilityProcess.fork(path.join(fixturesPath, 'navigator.js'), [], { + stdio: 'ignore' + }); + await once(child, 'spawn'); + const [data] = await once(child, 'message'); + expect(data).to.be.true(); + const exit = once(child, 'exit'); + expect(child.kill()).to.be.true(); + await exit; + } + { + const child = utilityProcess.fork(path.join(fixturesPath, 'navigator.js'), [], { + stdio: 'ignore', + execArgv: [ + '--no-experimental-global-navigator' + ] + }); + await once(child, 'spawn'); + const [data] = await once(child, 'message'); + expect(data).to.be.false(); + const exit = once(child, 'exit'); + expect(child.kill()).to.be.true(); + await exit; + } + }); }); }); diff --git a/spec/fixtures/api/utility-process/navigator.js b/spec/fixtures/api/utility-process/navigator.js new file mode 100644 index 000000000000..c7bfafb07c54 --- /dev/null +++ b/spec/fixtures/api/utility-process/navigator.js @@ -0,0 +1 @@ +process.parentPort.postMessage(typeof navigator === 'object');