From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Thu, 12 Mar 2026 17:03:29 +0100
Subject: fix: prefer browser runtime over node in HostRuntime detection

In Electron, the `process` global is available in renderer processes,
including the DevTools renderer. This causes the IS_NODE check to pass,
leading DevTools to attempt importing the Node.js platform runtime
(which uses `node:worker_threads`). However, DevTools Web Workers
running under the `devtools://` protocol don't have access to Node.js
built-in modules, resulting in a failed dynamic import.

Fix by checking IS_BROWSER first, since DevTools always runs in a
browser-like environment. The Node.js runtime is only needed when
DevTools runs under pure Node.js (e.g., CLI tooling or testing).

diff --git a/front_end/core/platform/HostRuntime.ts b/front_end/core/platform/HostRuntime.ts
index 91adba7c966a9c4c0e5315d2cfee07f8f622b731..16822b8d4ea74a4ffd6870e5e95948d75918f5d2 100644
--- a/front_end/core/platform/HostRuntime.ts
+++ b/front_end/core/platform/HostRuntime.ts
@@ -14,12 +14,12 @@ export const IS_BROWSER =
     typeof window !== 'undefined' || (typeof self !== 'undefined' && typeof self.postMessage === 'function');
 
 export const HOST_RUNTIME = await (async(): Promise<Api.HostRuntime.HostRuntime> => {
-  if (IS_NODE) {
-    return (await import('./node/node.js')).HostRuntime.HOST_RUNTIME;
-  }
   if (IS_BROWSER) {
     return (await import('./browser/browser.js')).HostRuntime.HOST_RUNTIME;
   }
+  if (IS_NODE) {
+    return (await import('./node/node.js')).HostRuntime.HOST_RUNTIME;
+  }
 
   throw new Error('Unknown runtime!');
 })();
