Windows

The Ende.BrowserWindow class controls native windows. A window opens automatically when your binary starts and loads your app's HTTP server. The first new Ende.BrowserWindow() you construct adopts that initial window; every construction after that opens a new one. All windows share the same Ende runtime: there is one async runtime per process, regardless of how many windows are open.

For a complete app that manages a window, application menus, and packaging, see the denidian example.

Creating windows

// The first construction adopts the implicit startup window.
const win = new Ende.BrowserWindow({ title: "My App" });

// Subsequent constructions open additional windows.
const settings = new Ende.BrowserWindow({
  title: "Settings",
  width: 420,
  height: 320
});
// `appOrigin()` returns the app's origin; see "Navigation" below.
settings.navigate(new URL("/settings", appOrigin()).href);

The constructor accepts a BrowserWindowOptions object:

Option Type Default Notes
title string none Window title.
width number 800 Initial width in logical pixels.
height number 600 Initial height in logical pixels.
x, y number none Initial position; centered if omitted.
resizable boolean true Whether the user can resize the window.
alwaysOnTop boolean false Keep the window above others.
opacity number 1 Opacity of the whole window, from 0 to 1. Out-of-range values are clamped. Change it later with setOpacity().
visible boolean true Show the window when it's created. See Hidden windows.
frameless boolean false Remove the title bar and window chrome. Creation-only.
noActivate boolean false Floating, non-activating panel that doesn't steal focus. Creation-only.
transparentTitlebar boolean false Blend the title bar into the content. Creation-only.
transparent boolean false Transparent window background; the page's own alpha shows what's behind. macOS and Linux with webview only. Creation-only.

new Ende.BrowserWindow() opens (or adopts) a window immediately. The window is alive until close() is called or the user closes it from the OS.

frameless, noActivate, transparentTitlebar, and transparent can only be set at creation time. frameless + noActivate together are the building blocks for tray / menu-bar popovers; see Tray.attachPanel.

opacity fades the whole window, web content and native chrome alike, like CSS opacity. transparent instead keeps the window opaque where the page paints and lets the desktop show through where the page is transparent. It's ignored on Windows and with the CEF backend.

The initial window

The window your app starts with is created before your code runs, from the desktop.initialWindow section of ende.json. The first BrowserWindow adopts it, so:

  • Its creation-time options (frameless, noActivate, transparentTitlebar, transparent) are ignored. Set them in desktop.initialWindow instead.
  • width and height resize it only when you pass them.
  • visible: false hides it.
ende.json
{
  "desktop": {
    "initialWindow": { "width": 1024, "height": 720, "frameless": true }
  }
}

Ende 2026.11.10

The desktop.initialWindow section, the visible option, and printToPdf() are new in this release.

Multiple windows are independent: each has its own size, position, focus state, and webview. They can navigate to different paths or different origins, set their own bindings, and emit their own events.

Lifecycle

win.show();
win.hide();
win.focus();
win.close(); // closes right away, fires no "close" event
win.reload(); // reload the webview's current document

if (win.isClosed()) { /* … */ }
if (win.isVisible()) { /* … */ }

Each window has a stable numeric id:

console.log(win.windowId);

Closing a window does not stop the runtime; the process keeps running until all windows are closed (or you call Ende.exit()).

Size and position

const [w, h] = win.getSize();
win.setSize(800, 600);

const [x, y] = win.getPosition();
win.setPosition(100, 100);

if (win.isResizable()) { /* … */ }
win.setResizable(false);

if (win.isAlwaysOnTop()) { /* … */ }
win.setAlwaysOnTop(true);

Sizes are in logical pixels. The OS handles HiDPI scaling.

Persisting size and position

Ende does not remember a window's size or position between runs, and you should not rely on the OS to restore them — some window managers do, but many don't (on Linux/KDE, for example, each launch opens at the constructor's defaults). If you want a window to reopen where the user left it, save its geometry to app-owned configuration and restore it on the next startup.

Seed the constructor from the saved values, then write the geometry back whenever it changes:

const file = `${Ende.env.get("HOME")}/.myapp-window.json`;

let saved: { width?: number; height?: number; x?: number; y?: number } = {};
try {
  saved = JSON.parse(await Ende.readTextFile(file));
} catch {
  // First run, or no saved state yet — fall back to defaults.
}

const win = new Ende.BrowserWindow({
  title: "My App",
  width: saved.width ?? 800,
  height: saved.height ?? 600,
  x: saved.x,
  y: saved.y
});

async function save() {
  const [width, height] = win.getSize();
  const [x, y] = win.getPosition();
  await Ende.writeTextFile(file, JSON.stringify({ width, height, x, y }));
}

win.addEventListener("resize", save);
win.addEventListener("move", save);

Title

win.setTitle("My App: Untitled");

Use a stable prefix plus a document-specific suffix; this is what users see in window switchers, the dock, and the taskbar.

navigate() takes an absolute URL. To show one of the app's own pages, use the app's origin: app://<host> with the webview backend on macOS and Windows, and http://127.0.0.1:<port> elsewhere. In the page, location.origin is that origin. In your Ende code, build it from ENDE_SERVE_ADDRESS:

function appOrigin(): string {
  const addr = Ende.env.get("ENDE_SERVE_ADDRESS")!;
  if (addr.startsWith("memory:")) {
    return `app://${addr.slice("memory:".length)}`;
  }
  return `http://127.0.0.1:${addr.split(":").pop()}`;
}

win.navigate(new URL("/", appOrigin()).href);

Reading ENDE_SERVE_ADDRESS needs --allow-env=ENDE_SERVE_ADDRESS when you build. See Building URLs to your own pages.

Navigation works with any URL the embedded webview can load, most commonly the app's own pages, but also https:// URLs, file:// URLs, and data: URLs. The load event fires on the window after a navigation finishes loading.

For multi-page apps, use the local HTTP server's routing rather than swapping windows. For modal dialogs, prefer creating a child window over navigating away.

Events

Ende.BrowserWindow is an EventTarget. Listen with addEventListener or assign to the matching on<event> property.

win.addEventListener("resize", (e) => {
  console.log("resized to", e.detail.width, e.detail.height);
});

win.onfocus = () => console.log("focused");
win.onblur = () => console.log("blurred");
Event When it fires
resize The window's size changed.
move The window's position changed.
focus The window gained focus.
blur The window lost focus.
close The user asked to close the window. Cancelable.
load A navigation finished loading.
keydown A key was pressed while the window was focused.
keyup A key was released.
mousemove The pointer moved over the window.
mouseenter The pointer entered the window.
mouseleave The pointer left the window.
mousedown A mouse button was pressed.
mouseup A mouse button was released.
click A mouse click landed on the window.
dblclick A double-click landed on the window.
wheel A scroll wheel / trackpad scroll happened.
menuclick An application-menu item was clicked.
contextmenuclick A context-menu item was clicked.

The pointer and keyboard events mirror their browser equivalents (KeyboardEvent, MouseEvent, WheelEvent). resize, move, menuclick, and contextmenuclick are CustomEvents carrying a detail payload; see Menus for the menu events.

win.addEventListener("keydown", (e) => {
  if (e.key === "Escape") win.close();
});

Running JavaScript in the webview

const result = await win.executeJs(
  "document.querySelectorAll('li').length"
);
console.log(result); // number of <li> on the current page

executeJs runs the code in the webview's main world and resolves with the result. The value crosses a realm boundary, so it must be JSON-serializable; if the script throws, the returned promise rejects with the thrown value.

For richer Ende ↔ webview communication, use bindings instead.

Native window handle

const surface = win.getNativeWindow();

getNativeWindow() wraps the window's native surface as a Ende.UnsafeWindowSurface so you can render to it with WebGPU. Only windows of the raw backend have one; on the webview and cef backends the call throws an error that names the backend. Request a GPU adapter first; the call also throws if there is no active WebGPU context:

const adapter = await navigator.gpu.requestAdapter();
const device = await adapter!.requestDevice();
const surface = win.getNativeWindow();
const context = surface.getContext("webgpu");
// configure `context` with `device` and draw…

Once a surface has been taken, close() is downgraded to hide() so the native handles backing the surface are not destroyed out from under WebGPU.

For a full walkthrough — configuring the context, drawing geometry, and running a render loop — see WebGPU rendering.

Hidden windows

Pass visible: false to create a window off screen, and call show() to reveal it later. A hidden window still loads and renders its page, so you can, for example, make a PDF without showing anything:

// The app's first BrowserWindow adopts the initial window, which is already
// loading "/". Create it first, so the PDF window below is a new one.
const main = new Ende.BrowserWindow({ title: "My App" });

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 });
win.navigate(new URL("/report", appOrigin()).href);

The first BrowserWindow adopts the initial window, which is already loading your page and is shown once that page loads. If the page can load before your code creates the window, set desktop.initialWindow.showOnFirstLoad to false in ende.json so the window never flashes on screen; it then stays hidden until you call show(). With the CEF backend, a hidden window can appear for a moment before it is hidden.

Printing to PDF

printToPdf() renders the window's current page to a PDF and resolves with its bytes. With a path, it also writes the PDF to that file, replacing it, before the promise resolves:

const bytes = await win.printToPdf();
await win.printToPdf({ path: "invoice.pdf" });

Writing path needs --allow-write for that path, checked before anything is rendered; a relative path resolves against the current working directory. The promise rejects with Ende.errors.NotCapable if the write isn't permitted, with Ende.errors.NotSupported on the raw backend, which has no web page, and with Ende.errors.BadResource if the window is closed.

DevTools

win.openDevtools(); // both isolates
win.openDevtools({ ende: false }); // renderer only
win.openDevtools({ renderer: false }); // Ende runtime only

See DevTools.

Closing the app

The runtime exits when no windows are open and there are no other live async tasks (timers, pending fetches, etc.). To exit explicitly:

Ende.exit(0);

The close event fires when the user asks to close a window: its close button, Cmd+W, Alt+F4 or the window manager's close action. To keep the window open (for example, to show a "Save?" dialog), call event.preventDefault(), then call close() once you're done:

win.addEventListener("close", async (e) => {
  if (hasUnsavedChanges) {
    e.preventDefault();
    const ok = await win.executeJs("confirm('Discard changes?')");
    if (ok) win.close();
  }
});

close() closes the window right away and doesn't fire close, so calling it from a close listener can't loop. Quitting the app doesn't fire close either.

Listeners must run within about 5 seconds of the request, or the window closes anyway, so a busy or hung JavaScript thread can't leave a window the user can't close. Time spent in alert(), confirm() and prompt() doesn't count. An event that arrives later can't be canceled. Once a listener has called preventDefault(), the window stays open for as long as it needs.

Ende 2026.11.10

The close event is cancelable, with the 5-second limit. In earlier releases the window closed even when a listener called preventDefault().