Generic Web Integration

This guide connects a character to a DOM application without React. The application registers its own targets.

Integration shape

flowchart LR
  App[Web application] --> Load[Public Content validation]
  App --> Session[Runtime / autonomy session]
  App --> Registry[Public Host registry]
  App --> Geometry[Browser Host geometry adapter]
  Registry --> Selector[Host target selector]
  Geometry --> Coordinator[Browser Runtime coordinator]
  Selector --> Coordinator
  Session --> Coordinator
  Coordinator --> Renderer[Application renderer]

A complete minimal ordinary Browser integration

Use @charaweave/core and @charaweave/browser (Content V10). The example assumes a Vite/TypeScript app in the repository workspace. Declare the required workspace dependencies and build them before running the example. These packages are not published to npm.

Copy the existing apps/runtime-playground/public/demo-character-cw019c-simple-cat/ fixture into your Vite app's public directory (preserve its package-relative file layout). It is a V7 source package supported by the V10 projection, not a V11 demo. Keep it under demo-character-cw019c-simple-cat/. For a real product use your own authorized assets.

Create an index.html file:

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Character host example</title>
<link rel="icon" href="data:,">
<style>
  #photo { position: fixed; left: 65%; top: 50%; }
  #character { position: fixed; width: 80px; height: 80px;
    object-fit: contain; pointer-events: none; }
</style>
<button id="photo" type="button">Open photo</button>
<button id="stop" type="button">Stop and detach</button>
<img id="character" alt="Example character">
<output id="status" aria-live="polite"></output>
<script type="module" src="./main.ts"></script>
</html>

Create main.ts (complete example):

import { loadCharacterContentV10 } from "@charaweave/content";
import { createCoreSession } from "@charaweave/core";
import { createBrowserSession } from "@charaweave/browser";

const packageBase = new URL("./demo-character-cw019c-simple-cat/", document.baseURI);
function resource(path: string): URL {
  if (path.split("/").some(s => !s || s === "." || s === "..") ||
      /[\\:%?#]/.test(path)) throw Error("Unsafe package path");
  return new URL(path, packageBase);
}
const reader = {
  async readText(path: string) {
    const response = await fetch(resource(path));
    if (!response.ok) throw Error("Package text request failed: " + response.status);
    return response.text();
  },
  async exists(path: string) {
    const response = await fetch(resource(path), { method: "HEAD" });
    if (response.status === 404 || response.status === 410) return false;
    if (!response.ok) throw Error("Package resource check failed: " + response.status);
    return true;
  },
};
const input = { reader, characterId: "sorune.simple-cat:cat" };
const loaded = await loadCharacterContentV10(input);
if (!loaded.ok) throw Error(JSON.stringify(loaded.issues));

const image = document.querySelector<HTMLImageElement>("#character")!;
const photo = document.querySelector<HTMLButtonElement>("#photo")!;
const status = document.querySelector<HTMLOutputElement>("#status")!;
const render = loaded.character.render;
image.src = resource(render.primaryAsset.path).href;
await image.decode();
const scale = render.defaultScale ?? 1;
image.style.width = (80 * scale) + "px";
image.style.height = (80 * scale) + "px";
let placement = { x: 100, y: 180 };
function applyPlacement(next: { x: number; y: number }) {
  placement = next;
  image.style.left = next.x + "px";
  image.style.top = next.y + "px";
}
applyPlacement(placement);

// The Host treats placement as the image box's top-left CSS-pixel position.
const core = await createCoreSession({
  character: input,
  targetSessionPolicy: {
    repeatTargetFactor: 0.5, recentTargetFactor: 0.5,
    seenTargetFactor: 0.8, recentCapacity: 8, seenCapacity: 32,
  },
});
const browser = createBrowserSession({
  core,
  character: {
    getElement: () => image,
    getCurrentPlacement: () => placement,
    applyPlacement,
  },
  approachClearancePx: 12,
  motionDurationMs: 400,
  onDiagnostic: diagnostic => console.warn(diagnostic.code, diagnostic.message),
  onCharacterExecution: event => { status.value = JSON.stringify(event); },
});
const binding = browser.attachHost({
  element: photo,
  id: "feed.photo.42",
  role: "photo-card",
  capabilities: ["activate"],
  onActivate: () => { photo.click(); },
});
photo.addEventListener("click", () => { photo.dataset.opened = "true"; });
core.start();
if (browser.start().status !== "accepted") {
  binding.detach(); browser.dispose(); core.dispose();
  throw Error("Browser did not start");
}
status.value = "RUNNING";

let closed = false;
function cleanup() {
  if (closed) return;
  closed = true;
  browser.suspend();
  binding.detach();
  browser.dispose();
  core.dispose();
  status.value = "DISPOSED";
}
document.querySelector("#stop")!.addEventListener("click", cleanup);
window.addEventListener("pagehide", cleanup, { once: true });

Serve the app with its existing Vite dev command. Open the page: the primary image decodes and status reads RUNNING. Wait for the effective opportunity interval and idle gate; depending on the fixture, applicable targets and random observations, an accepted execution can visit or activate the photo. The trusted callback sets the photo's opened marker; a visit is not a business activation. Click Stop and detach to end the owned lifecycle.

The example renders a static image in a fixed box. It demonstrates browser movement and execution; it does not include animation, anchor-aware rendering, pointer manipulation or the full V11 repertoire. For full presentation, bind asset clips to semantic state, honor authored anchors and advance finite clips through the supported lifecycle. Check the execution result as well as movement. The example assumes the static server returns real 404/410 for missing resources; an SPA fallback returning HTML with 200 for missing assets is not a valid existence check. A production reader may use a manifest-backed resource index instead.

Bind and detach a target on the Platform V6 helper

For the existing @charaweave/platform/browser composition, attach the live element through the environment:

const registration = browser.attachHost({
  element: cardElement,
  id: "feed.photo.42",
  role: "photo-card",
  capabilities: ["activate"],
  onActivate: async ({ surfaceId }) => openPhoto(surfaceId),
});

// Call when the element unmounts or refers to a different product object.
registration.detach();

Use BrowserEnvironment with ConsumerSession. createConsumerSession reads Content V6. Use loadCharacterContentV11 from @charaweave/content to read V11 fields. That loader does not construct a full V11 runtime; there is no public createCharacterSession factory.

Placement and rendering

The application owns its character DOM element and placement projection. Browser Runtime motion consumes the current placement, applies motion updates through the application port, and measures bound Host geometry with @charaweave/host-browser. The renderer loads validated Content assets, applies the authored anchor/scale in its own coordinate system, advances finite clips, and reports the appropriate terminal observation.

Use viewport CSS pixels for DOMRect geometry. Do not multiply bounds by devicePixelRatio. The current supported geometry is axis-aligned rendered DOMRect behavior, including the documented translated/scaled Host and ancestor cases; arbitrary rotated or perspective hit geometry is not promised.

Interaction and business action

Activation requires a registered surface with the activate capability and an application-owned handler. visit is movement/approach and does not itself invoke the business action callback. inspect, emote, and rest are Character WHAT kinds in the V11 repertoire; they do not cause CharaWeave to read the underlying product record or execute package code.

Cleanup order

  1. Stop the autonomous loop and cancel active Browser execution.
  2. Detach every Host binding.
  3. Dispose Browser motion/geometry/action/registry services owned by the composition.
  4. Dispose the Character/Autonomy session and ordinary Runtime.

Use the existing composition's documented lifecycle where available; do not independently dispose resources owned by another layer. See Consumer Integration Manual and Troubleshooting.