Skip to main content

Webview.open

Webview.open(options) creates a new webview and returns a Webview instance.

static async open(options: WebviewOpenOptions): Promise<Webview>

Parameters

ParameterTypeDescription
optionsWebviewOpenOptionsConfiguration for the webview

WebviewOpenOptions

FieldTypeDefaultDescription
sourceWebviewSource--What to display (required)
sizeVec2--Dimensions in 3D world space (e.g., [0.7, 0.7])
viewportSizeVec2--HTML pixel dimensions (e.g., [800, 600])
offsetVec2--Position relative to linked persona or world origin
linkedPersonastring--Persona ID to attach to

Returns

A Promise that resolves to a new Webview instance.

Examples

Open a webview displaying a mod's local HTML asset:

const webview = await Webview.open({
source: webviewSource.local("my-mod:ui"),
size: [0.7, 0.7],
viewportSize: [800, 600],
offset: [0, 0.5],
});

Link a webview to a persona so it follows the character's position:

import { persona } from "@hmcs/sdk";

const p = await persona.load("alice");
const webview = await Webview.open({
source: webviewSource.local("my-mod:ui"),
size: [1, 0.9],
viewportSize: [900, 700],
offset: [1.1, 0],
linkedPersona: p.id,
});