Fix open browser behaviour on Windows

This commit is contained in:
x86matthew
2026-08-12 02:42:53 +01:00
parent 052095e156
commit 8924c152a4
2 changed files with 8 additions and 10 deletions
+6 -3
View File
@@ -69,8 +69,6 @@ function windowsOpenerCommand(target: string): string[] {
powershell,
"-NoProfile",
"-NonInteractive",
"-WindowStyle",
"Hidden",
"-EncodedCommand",
Buffer.from(script, "utf16le").toString("base64"),
];
@@ -93,7 +91,12 @@ export function openPath(urlOrPath: string): void {
}
let child: Bun.Subprocess | undefined;
try {
child = Bun.spawn(cmd, { stdin: "ignore", stdout: "ignore", stderr: "ignore" });
child = Bun.spawn(cmd, {
stdin: "ignore",
stdout: "ignore",
stderr: "ignore",
windowsHide: process.platform === "win32",
});
} catch (error) {
// Spawn threw synchronously (missing binary, denied exec, sandbox
// restriction, …). Best-effort: log so the failure isn't invisible while
@@ -159,13 +159,8 @@ describe("openPath", () => {
// on Windows boxes where the machine PATH no longer references
// System32.
expect(call?.cmd[0]).toBe(powershellPath);
expect(call?.cmd.slice(1, -1)).toEqual([
"-NoProfile",
"-NonInteractive",
"-WindowStyle",
"Hidden",
"-EncodedCommand",
]);
expect(call?.cmd.slice(1, -1)).toEqual(["-NoProfile", "-NonInteractive", "-EncodedCommand"]);
expect(call?.options.windowsHide).toBe(true);
// The target rides inside the UTF-16LE payload: no cmd/PowerShell
// metacharacter parsing ever sees the `&` in the query string, and the
// terminating error preference makes Start-Process failures exit 1 so