Skip to content

Viewer SDK events

The Viewer SDK has five stable semantic events. Subscribe with viewer.on(), remove a listener with viewer.off(), or subscribe once with viewer.once().

Event Payload When it fires
load-start { filename } A scene begins loading.
load-progress { percentage } Loading advances; percentage is numeric.
scene-prepared {} The scene is decoded and may be adjusted before presentation completes.
scene-ready {} The scene is fully loaded and interactive.
error { error } Scene loading fails; error.code is stable and machine-readable.
function reportProgress({ percentage }) {
  progress.value = percentage;
}

viewer.on('load-progress', reportProgress);
viewer.once('scene-ready', () => {
  controls.disabled = false;
});

await viewer.load(new URL('./product.webex', location.href).href);
viewer.off('load-progress', reportProgress);

Use scene-ready for normal controls and post-load work. Use scene-prepared only when an opening scene must be changed before its completed presentation:

viewer.once('scene-prepared', () => {
  viewer.setProperty('Heart Head', 'obj_visible', 'false');
});
await viewer.load(new URL('./all-variants.webex', location.href).href);

When scene is passed to mount(), the mount promise resolves after that scene is ready. To show initial progress, mount first, subscribe, and then call load().

Operations such as capture(), getProperty(), product-choice changes, and multipart changes report completion or failure through their returned promises:

try {
  await viewer.mergePart('head', new URL('./parts/head.webex', location.href).href);
} catch (error) {
  console.error(error.code, error.message);
}

Engine messages are private and are never exposed as events.