namespace
WebView
namespace WebView
interface ClickOptions
interface ClickSelectorOptions
- timeout?: number
Maximum time in milliseconds to wait for the element to become actionable (attached, visible, stable for 2 frames, not obscured).
interface ConstructorOptions
- dataStore?: 'ephemeral' | { directory: string }
Storage backing for cookies, localStorage, IndexedDB, etc.
"ephemeral"(default): in-memory only, nothing written to disk.{ directory }: persistent storage rooted at the given path. Multiple views with the same directory share state.
Chrome backend:
directoryis per-Chrome-process (--user-data-dir), not per-view. The first view's directory applies to all views spawned in the same Bun process. - url?: string
Initial URL to navigate to. The navigation starts before the constructor returns;
await view.navigate(otherUrl)or any other operation waits for it to complete first.Equivalent to calling
view.navigate(url)immediately after construction.
interface PressOptions
interface ScrollToOptions
- block?: 'end' | 'center' | 'start' | 'nearest'
Vertical alignment.
"nearest"scrolls minimally (no-op if already in view);"center"snaps the element's center to the viewport center.
- type Backend =| 'webkit'| 'chrome'| { type: 'chrome'; url: string }| { argv: string[]; path: string; stderr: 'inherit' | 'ignore'; stdout: 'inherit' | 'ignore'; type: 'chrome'; url: false }| { stderr: 'inherit' | 'ignore'; stdout: 'inherit' | 'ignore'; type: 'webkit' }
Browser backend selection.
"webkit"(default): WKWebView. macOS only. Zero external dependencies — uses the system WebKit.framework."chrome": Chrome/Chromium via DevTools Protocol over--remote-debugging-pipe. Works anywhere Chrome is installed. Auto-detects the binary in standard locations; override withbackend.pathor theBUN_CHROME_PATHenvironment variable.
The object form accepts extra launch flags. Chrome switches are last-wins for duplicates, so
argvcan override the defaults.Chrome is spawned once per process — the first
new Bun.WebView()call'spath/argv/dataStore.directorywin; subsequent views reuse the same Chrome instance viaTarget.createTarget.Default flags:
--remote-debugging-pipe --headless --no-first-run --no-default-browser-check --disable-gpu --user-data-dir=<temp>. - type ConsoleCapture = typeof console | (type: string, ...args: unknown[]) => void
Console capture. Called for each
console.*invocation in the page.globalThis.console: forward directly to the parent's console.console.log("hi")in the page printshito stdout with Bun's formatter;console.errorgoes to stderr. Zero JS overhead per call — dispatches throughConsoleClientdirectly.(type, ...args) => void: custom callback.typeis the method name ("log"|"warn"|"error"|"info"|"debug"| ...). Primitive args unwrap to their raw values; object args arrive as a structured descriptor — for Chrome, the CDPRemoteObjectwith.type/.className/.description/.preview.properties; for WebKit, the JSON round-trip of the object (lossy for functions/ circular refs, which stringify to theirString(...)coercion).
- type Modifier =| 'Shift'| 'Control'| 'Alt'| 'Meta'
- type VirtualKey =| 'Enter'| 'Tab'| 'Space'| 'Backspace'| 'Delete'| 'Escape'| 'ArrowLeft'| 'ArrowRight'| 'ArrowUp'| 'ArrowDown'| 'Home'| 'End'| 'PageUp'| 'PageDown'