Ende.BrowserWindow

interface · desktop apps only

interface Ende.BrowserWindow<T extends ValidBindings<T> = WindowBindings> extends BrowserWindowEventHandlers

class · desktop apps only

class Ende.BrowserWindow<T extends ValidBindings<T> = WindowBindings> extends EventTarget

Constructors

constructor

new BrowserWindow(options?: BrowserWindowOptions)

Create a window.

The first BrowserWindow an app creates takes over the app's initial window, which is created at startup from desktop.initialWindow in ende.json and is already loading the app's page. Its creation-time options (frameless, noActivate, transparentTitlebar and transparent) can't change, so set them in desktop.initialWindow. width and height resize it, and visible: false hides it. With desktop.initialWindow.showOnFirstLoad set to false, it stays hidden until BrowserWindow.show is called.

Properties

windowId

readonly windowId: number

Methods

bind

bind<N extends keyof T, F extends T[N]>(name: N, fn: F & BrowserWindowSerializableCheck<F>): void

Expose fn to the webview under name.

The resolved value must be serializable; see BrowserWindowSerializable. This is checked even when T is left to its default, so returning e.g. a Date is a type error rather than an empty object at runtime.

unbind

unbind<N extends keyof T>(name: N): void

executeJs

executeJs(script: string): Promise<BrowserWindowValue>

printToPdf

printToPdf(options?: PrintToPdfOptions): Promise<Uint8Array>

Render the window's current page to a PDF and resolve with its bytes. With PrintToPdfOptions.path, the bytes are also written to that file before the promise resolves.

Works on hidden windows too (see BrowserWindowOptions.visible), so an app can make PDFs without showing a window.

const win = new Ende.BrowserWindow({ visible: false });
win.addEventListener("load", async () => {
  const pdf = await win.printToPdf({ path: "report.pdf" });
  console.log(`wrote ${pdf.length} bytes`);
}, { once: true });

Rejects with Ende.errors.NotCapable if writing path isn't permitted, Ende.errors.NotSupported on the raw backend, which has no web page, and Ende.errors.BadResource if the window is closed.

setTitle

setTitle(title: string): void

getSize

getSize(): [number, number]

setSize

setSize(width: number, height: number): void

getPosition

getPosition(): [number, number]

setPosition

setPosition(x: number, y: number): void

isResizable

isResizable(): boolean

setResizable

setResizable(resizable: boolean): void

isAlwaysOnTop

isAlwaysOnTop(): boolean

setAlwaysOnTop

setAlwaysOnTop(alwaysOnTop: boolean): void

getOpacity

getOpacity(): number

Get the window's overall opacity, a uniform factor in the range 0–1 where 1 is fully opaque.

setOpacity

setOpacity(opacity: number): void

Set the window's overall opacity, a uniform factor in the range 0–1 where 1 is fully opaque (the default) and 0 is fully transparent. Fades the entire window — web content and native chrome alike — like CSS opacity. Out-of-range values are clamped. No-op on backends without opacity support.

isClosed

isClosed(): boolean

close

close(): void

Close the window. It closes right away and doesn't fire a close event, so it's safe to call from a close listener.

A window whose WebGPU surface was taken with BrowserWindow.getNativeWindow is hidden instead, because destroying it would leave the surface's native handles dangling.

isVisible

isVisible(): boolean

show

show(): void

hide

hide(): void

focus

focus(): void

navigate

navigate(url: string): void

Load url, an absolute URL, in the window.

To show one of the app's own pages, use the app's origin. With the webview backend on macOS and Windows that is app://<host>, where <host> is the app identifier, lowercased: the name in ENDE_SERVE_ADDRESS (memory:<host>). A page can use location.origin. Elsewhere the app is at http://127.0.0.1:<port> (ENDE_SERVE_ADDRESS is tcp:127.0.0.1:<port>).

openDevtools

openDevtools(options?: OpenDevtoolsOptions): void

Open a DevTools window.

By default both targets are shown. Pass an options object to select which targets to inspect. At least one must be true.

reload

reload(): void

setApplicationMenu

setApplicationMenu(menu: MenuItem[]): void

showContextMenu

showContextMenu(x: number, y: number, menu: MenuItem[]): void

Pop up a context menu inside this window.

x and y are window-relative CSS pixels with a top-left origin — the same space as a DOM mouse event's clientX / clientY, so those can be forwarded unchanged:

win.addEventListener("mousedown", (e) => {
  if (e.button === 2) win.showContextMenu(e.clientX, e.clientY, menu);
});

The platform may shift the menu to keep it on screen when it does not fit below or to the right of that point.

getNativeWindow

getNativeWindow(): Ende.UnsafeWindowSurface

The window's WebGPU surface. Only windows of the raw backend have one ("desktop": { "backend": "raw" } in ende.json); elsewhere this throws.

addEventListener

addEventListener<K extends keyof BrowserWindowEventMap>(type: K, listener: (this: BrowserWindow, ev: BrowserWindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void

removeEventListener

removeEventListener<K extends keyof BrowserWindowEventMap>(type: K, listener: (this: BrowserWindow, ev: BrowserWindowEventMap[K]) => any, options?: boolean | EventListenerOptions): void
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void