Files
learnharness/electron/server-title-guard.cjs
T
amosblomqvist 480a29aaea fix: prevent macOS backend Dock registration
Preload a backend-only JS title accessor from an unpacked macOS resource before Next starts. Preserve Windows and Linux launch arguments, and test title semantics, process scope, argument order, and resource copying.

Based on the prevention approach proposed by marchellodev in PR #47.
2026-10-24 21:56:57 +03:00

25 lines
991 B
JavaScript

/**
* Preloaded only into the packaged macOS backend, before Next starts.
*
* Next assigns process.title. In Electron's Node mode on macOS, the native
* setter checks in with Launch Services using the main app bundle, creating
* an unwanted foreground application registration. Keep title writes in JS
* instead: the native process name stays unchanged while JS can read back
* its assigned title. This deliberately does not emulate native truncation
* or every coercion detail; assignments use String(value).
*
* Explicit launch arguments (not NODE_OPTIONS) keep the full-Electron browser
* helper untouched. Node-mode fork descendants can inherit this preload.
*/
if (process.platform === "darwin" && process.env.ELECTRON_RUN_AS_NODE === "1" && process.env.LH_DESKTOP_SERVER === "1") {
let title = process.title;
Object.defineProperty(process, "title", {
configurable: true,
enumerable: true,
get: () => title,
set: (value) => {
title = String(value);
},
});
}