From 56d145c7a351bae4fd0c31f48e6d43e97ff2918b Mon Sep 17 00:00:00 2001 From: Andrew Hewitt Date: Sat, 21 Feb 2026 05:29:26 +0900 Subject: [PATCH] feat: add show option to BrowserWindow for deferred visibility Allow creating windows without immediately showing them via show: false. Enables E2E testing, splash screens, and background window patterns. Co-Authored-By: Claude Opus 4.6 --- package/src/bun/core/BrowserWindow.ts | 7 ++++++- package/src/bun/proc/native.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package/src/bun/core/BrowserWindow.ts b/package/src/bun/core/BrowserWindow.ts index b3ef6991..b78caa14 100644 --- a/package/src/bun/core/BrowserWindow.ts +++ b/package/src/bun/core/BrowserWindow.ts @@ -36,6 +36,8 @@ export type WindowOptionsType = { // Use for untrusted content (remote URLs) to prevent malicious sites from // accessing internal APIs, creating OOPIFs, or communicating with Bun sandbox: boolean; + /** Whether to show the window immediately on creation. Default: true */ + show?: boolean; }; const defaultOptions: WindowOptionsType = { @@ -54,6 +56,7 @@ const defaultOptions: WindowOptionsType = { transparent: false, navigationRules: null, sandbox: false, + show: true, }; export const BrowserWindowMap: { @@ -112,7 +115,7 @@ export class BrowserWindow { this.navigationRules = options.navigationRules || null; this.sandbox = options.sandbox ?? false; - this.init(options); + this.init({ ...options, show: options.show ?? defaultOptions.show }); } init({ @@ -120,6 +123,7 @@ export class BrowserWindow { styleMask, titleBarStyle, transparent, + show, }: Partial>) { this.ptr = ffi.request.createWindow({ id: this.id, @@ -162,6 +166,7 @@ export class BrowserWindow { }, titleBarStyle: titleBarStyle || "default", transparent: transparent ?? false, + show: show ?? true, }) as Pointer; BrowserWindowMap[this.id] = this; diff --git a/package/src/bun/proc/native.ts b/package/src/bun/proc/native.ts index dfeff8e4..76d06203 100644 --- a/package/src/bun/proc/native.ts +++ b/package/src/bun/proc/native.ts @@ -605,6 +605,7 @@ export const ffi = { }; titleBarStyle: string; transparent: boolean; + show?: boolean; }): FFIType.ptr => { const { id, @@ -667,7 +668,10 @@ export const ffi = { } native.symbols.setWindowTitle(windowPtr, toCString(title)); - native.symbols.showWindow(windowPtr); + + if (params.show !== false) { + native.symbols.showWindow(windowPtr); + } return windowPtr; },