From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Tue, 21 Oct 2025 20:00:06 +0200
Subject: fix: allow disabling fetch in renderer and worker processes

We need to disable Node.js' fetch implementation to prevent
conflict with Blink's in renderer and worker processes.

We should try to upstream some version of this.

diff --git a/doc/api/cli.md b/doc/api/cli.md
index f05686608297e538f0a6f65abb389281bced4291..c8da076f80a559b9ee6d2ffed831b088c15c8e88 100644
--- a/doc/api/cli.md
+++ b/doc/api/cli.md
@@ -1820,6 +1820,14 @@ changes:
 
 Disable using [syntax detection][] to determine module type.
 
+### `--no-experimental-fetch`
+
+<!-- YAML
+added: v18.0.0
+-->
+
+Disable exposition of Fetch API on the global scope.
+
 ### `--no-experimental-global-navigator`
 
 <!-- YAML
@@ -3499,6 +3507,7 @@ one is included in the list below.
 * `--no-addons`
 * `--no-async-context-frame`
 * `--no-deprecation`
+* `--no-experimental-fetch`
 * `--no-experimental-global-navigator`
 * `--no-experimental-repl-await`
 * `--no-experimental-sqlite`
diff --git a/doc/node.1 b/doc/node.1
index 9a0f5beb5b995fb92b31514c166e1c76e18d8ca9..fab0b24b630e755658b58a7281df1dacc4b7f32a 100644
--- a/doc/node.1
+++ b/doc/node.1
@@ -201,6 +201,9 @@ Enable transformation of TypeScript-only syntax into JavaScript code.
 .It Fl -experimental-eventsource
 Enable experimental support for the EventSource Web 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.
 .
diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js
index 9a99ff6d44320c0e28f4a787d24ea98ae1c96196..8f5810267d1ba430bae02be141f087f2a5d3cf9f 100644
--- a/lib/internal/process/pre_execution.js
+++ b/lib/internal/process/pre_execution.js
@@ -117,6 +117,7 @@ function prepareExecution(options) {
   setupSQLite();
   setupQuic();
   setupWebStorage();
+  setupFetch();
   setupWebsocket();
   setupEventsource();
   setupCodeCoverage();
@@ -345,6 +346,16 @@ function setupWarningHandler() {
   }
 }
 
+function setupFetch() {
+  if (getOptionValue('--no-experimental-fetch')) {
+    delete globalThis.fetch;
+    delete globalThis.FormData;
+    delete globalThis.Headers;
+    delete globalThis.Request;
+    delete globalThis.Response;
+  }
+}
+
 // https://websockets.spec.whatwg.org/
 function setupWebsocket() {
   if (getOptionValue('--no-experimental-websocket')) {
diff --git a/src/node_options.cc b/src/node_options.cc
index f6f81f50c8bd91a72ca96093dc64c183bd58039b..aa18dab6e4171d8a7f0af4b7db1b8c2c07191859 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -545,7 +545,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
             &EnvironmentOptions::experimental_eventsource,
             kAllowedInEnvvar,
             false);
-  AddOption("--experimental-fetch", "", NoOp{}, kAllowedInEnvvar);
+  AddOption("--experimental-fetch",
+            "experimental Fetch API",
+            &EnvironmentOptions::experimental_fetch,
+            kAllowedInEnvvar,
+            true);
   AddOption("--experimental-websocket",
             "experimental WebSocket API",
             &EnvironmentOptions::experimental_websocket,
diff --git a/test/parallel/test-process-env-allowed-flags-are-documented.js b/test/parallel/test-process-env-allowed-flags-are-documented.js
index d62a2583523c6b3c1de394a18e8060199e446bf1..7d6c6ea7949fd6b52bb54c31a2d71257349e64a9 100644
--- a/test/parallel/test-process-env-allowed-flags-are-documented.js
+++ b/test/parallel/test-process-env-allowed-flags-are-documented.js
@@ -122,7 +122,6 @@ const undocumented = difference(process.allowedNodeEnvironmentFlags,
 assert(undocumented.delete('--debug-arraybuffer-allocations'));
 assert(undocumented.delete('--no-debug-arraybuffer-allocations'));
 assert(undocumented.delete('--es-module-specifier-resolution'));
-assert(undocumented.delete('--experimental-fetch'));
 assert(undocumented.delete('--experimental-wasm-modules'));
 assert(undocumented.delete('--experimental-global-customevent'));
 assert(undocumented.delete('--experimental-global-webcrypto'));
