Native desktop webviews for Bun and Deno.
Bun and Deno provide the native implementation on supported macOS, Linux, and Windows targets. Node and browser bundles can import the package, but constructing a webview throws a descriptive unsupported-runtime error.
import Webview from "@rcompat/webview";
import platform from "@rcompat/webview/default";
import type {
Init, Size, SizeHint, Webview as WebviewContract,
} from "@rcompat/webview";Webview constructor#
Runtime-selected native webview constructor.
Example
const webview = new Webview({ platform });
webview.html = "<h1>Hello</h1>";
webview.run();new Webview(init: Init): WebviewContract;Types#
Init#
Options used to construct a webview.
type Init<Platform = Blob | string> = {
// Enables native developer tools.
// Default: `false`
debug?: boolean;
// Runtime-specific native sidecar artifact.
platform: Platform;
};Size#
Partial native window size assignment.
type Size = {
// Window height in pixels.
// Default: `720`
height?: number;
// Native size constraint.
// Default: `0`
hint?: SizeHint;
// Window width in pixels.
// Default: `1280`
width?: number;
};SizeHint#
Native window size constraint: 0 none, 1 minimum, 2 maximum, or 3
fixed.
type SizeHint = 0 | 1 | 2 | 3;Webview#
A native webview instance.
Webview members#
Webview.html#
Latest HTML assigned to the webview, if any. Replaces the webview document with an HTML string.
get html(): string | undefined;
set html(value: string);Webview.size#
Effective size as an isolated snapshot. Resizes the window, applying defaults to omitted fields.
Mutating the returned object does not resize the native window.
Assign a new partial size object to resize the native window.
Webview.destroy#
Idempotently terminates and releases the native handle.
Posts "destroyed" when globalThis.postMessage is available.
destroy(): void;Webview.navigate#
Navigates the webview to a URL.
navigate(url: string): void;Webview.run#
Runs the blocking native event loop, then destroys the handle.
run(): void;Platform exports#
The default subpath detects the current target; named subpaths select the indicated target explicitly. Bun loads the embedded sidecar artifact, while Deno returns its filesystem path. Node and browser imports resolve to undefined because native webviews are unsupported there.
@rcompat/webview/default#
import platform from "@rcompat/webview/default";@rcompat/webview/darwin-arm64#
import platform from "@rcompat/webview/darwin-arm64";@rcompat/webview/darwin-x64#
import platform from "@rcompat/webview/darwin-x64";@rcompat/webview/linux-arm64#
import platform from "@rcompat/webview/linux-arm64";@rcompat/webview/linux-x64#
import platform from "@rcompat/webview/linux-x64";@rcompat/webview/windows-x64#
import platform from "@rcompat/webview/windows-x64";