Web (WASM App & WebUI)
Bern compiles browser targets (platform = "browser", ui = "web") to lightweight DOM + CSS paired with your Rust engine. Because a browser target can run the engine either inside the browser or on a native host, every Web target explicitly chooses a web_mode:
web_mode = "app"(WASM App): Compiles the Rust engine to WebAssembly and runs everything in the browser tab. Ideal for static hosting and zero-install web apps.web_mode = "ui"(WebUI): Generates a browser UI that connects over WebSocket JSON to a native<app>-hostserver (or directly into a running native desktop/mobile app viaweb_ui). Ideal when the engine needs full native I/O, local filesystem access, or a companion CLI/Skill.
Web targets can be built on macOS, Linux, or Windows.
Prerequisites
- Rust 1.99+ (
rustup update). - Add the WebAssembly Rust target:
rustup target add wasm32-unknown-unknown
bern doctorIf your project or a module pulls in wasm-bindgen, install a matching wasm-bindgen-cli on PATH (or point BERN_WASM_BINDGEN at the exact executable).
Configuration in Bern.toml
[app]
id = "tasks"
bundle_id = "com.example.tasks"
version = "0.1.0"
name = "Tasks"
[app.icon]
default = "assets/icon.png"
web = "assets/web-icons" # Optional: PNG, SVG, or folder of favicons
# Option 1: Standalone WebAssembly app
[targets.web_app]
platform = "browser"
ui = "web"
web_mode = "app"
# javascript = true # Optional: runs bern::script inside a Web Worker
# Option 2: WebUI backed by a native engine host
[targets.web_ui]
platform = "browser"
ui = "web"
web_mode = "ui"Embedding WebUI inside a native app
Any native target can bundle a web_mode = "ui" target inside its resources (__bern_web_ui/) so users can open the native app's live UI from any browser on the LAN:
[targets.macos]
platform = "macos"
ui = "swiftui"
web_ui = "web_ui" # References [targets.web_ui] aboveInside your Rust engine, start or stop the embedded server at runtime (typically behind a user setting):
use bern::web_ui::{self, Options};
// Start serving WebUI (and optional custom HTTP Routes) on port 8787
web_ui::set(Some(Options { port: 8787, routes: None }));
// Inspect state (Stopped / Running { port } / Failed(String))
let status = web_ui::status();
// Stop serving
web_ui::set(None);Build, run, and debug
# Build static WASM app or WebUI + native host
bern build --target web_app
bern build --target web_ui
# Start local dev server and open in your browser
# Passing --port keeps browser localStorage/origin consistent across restarts
bern run --target web_app --port 8080
bern run --target web_ui --port 8081During bern run --target web_app, Bern runs a local IPC bridge so the generated CLI can still inspect and drive the live browser tab during development:
target/bern/web_app/bin/tasks --help
target/bern/web_app/bin/tasks window screenshot --output web.pngFor web_mode = "ui", the standalone native host (<app>-host) listens on 127.0.0.1, validates HTTP Origin/Host headers, and authenticates the WebSocket session using a per-launch fragment token—while still exposing the generated app CLI and Skill for automation.
Platform behavior and adaptations
- Shared self-drawn visual system (
bern-surface): Emits--bern-*theme tokens and control rules frombern-surfaceoverbern-themesnapshots (shared with GPUI), delivering consistent translucent surfaces, spacing, typography, and perpendicular white capsule slider thumbs while preserving semantic HTML/CSS, native IME, and WAI-ARIA and respectingprefers-color-scheme,WindowSet(appearance:), andWindow(idle_enabled:). - Windows and dialogs: Secondary windows and
Dialogviews render as accessible virtual dialogs inside the viewport. - Files and storage: Local persistence uses same-origin
localStorageinweb_mode = "app"and native file storage inweb_mode = "ui". Browser file pickers exposeblob:URLs that plug straight intoMediaSource. - Orientation & TV:
Window(landscape: true)calls the Screen Orientation API where supported by mobile browsers; TV browsers activateLayout(size: tv)andfont(tv:). - Animated SVG & JavaScript: Animated
Svgcompiles toBSVGbytecode rendered by pure-Rustbern-svg(no heavy runtime library).javascript = trueis supported onweb_mode = "app"via an isolated Web Worker. - Web extensions & native views: Mount custom DOM/Web Component views via
NativeView(web: "...")(Native views), or bundle third-party JS/WASM assets withweb_extension(Web extensions). - Not applicable:
MenuBar,StatusItem, andSwitch(login_item: true)are accepted cleanly as no-ops.
Packaging and signing
bern package --target web_app
bern package --target web_uiPackaging outputs in target/bern/dist/:
| Mode | Output | Contents |
|---|---|---|
web_mode = "app" |
Static .zip and .tar.gz |
index.html, compiled .wasm, JS glue, CSS, and resources—ready to deploy to any static web host or CDN (no CLI or Skill bundled). |
web_mode = "ui" |
Platform .zip / .tar.gz |
Native <app>-host binary, static WebUI page, generated app CLI (bin/<app>), and Skill (skills/<app>/SKILL.md). |