Ende.BrowserWindow
interface · desktop apps only
interface Ende.BrowserWindow<T extends ValidBindings<T> = WindowBindings> extends BrowserWindowEventHandlersclass · desktop apps only
class Ende.BrowserWindow<T extends ValidBindings<T> = WindowBindings> extends EventTargetConstructors
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: numberMethods
bind
bind<N extends keyof T, F extends T[N]>(name: N, fn: F & BrowserWindowSerializableCheck<F>): voidExpose 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): voidexecuteJs
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): voidgetSize
getSize(): [number, number]setSize
setSize(width: number, height: number): voidgetPosition
getPosition(): [number, number]setPosition
setPosition(x: number, y: number): voidisResizable
isResizable(): booleansetResizable
setResizable(resizable: boolean): voidisAlwaysOnTop
isAlwaysOnTop(): booleansetAlwaysOnTop
setAlwaysOnTop(alwaysOnTop: boolean): voidgetOpacity
getOpacity(): numberGet the window's overall opacity, a uniform factor in the range 0–1
where 1 is fully opaque.
setOpacity
setOpacity(opacity: number): voidSet 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(): booleanclose
close(): voidClose 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(): booleanshow
show(): voidhide
hide(): voidfocus
focus(): voidnavigate
navigate(url: string): voidLoad 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): voidOpen 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(): voidsetApplicationMenu
setApplicationMenu(menu: MenuItem[]): voidshowContextMenu
showContextMenu(x: number, y: number, menu: MenuItem[]): voidPop 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.UnsafeWindowSurfaceThe 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): voidaddEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): voidremoveEventListener
removeEventListener<K extends keyof BrowserWindowEventMap>(type: K, listener: (this: BrowserWindow, ev: BrowserWindowEventMap[K]) => any, options?: boolean | EventListenerOptions): voidremoveEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void