ES module viewer¶
Open the example · JavaScript source
This example uses the module build, which is ideal for Vite, webpack, Rollup, and modern browser projects. It does not create window.WebexViewer or any WASM protocol globals.
import { WebexViewer } from './components/viewer/webex-viewer.mjs';
const viewer = await WebexViewer.mount({
container: '#viewer',
engine: 'webex-viewer-127958.js',
apiKey: window.WEBEX_API_KEY
});
viewer.on('load-progress', ({ percentage }) => {
progress.value = percentage;
});
await viewer.load(new URL('./scenes/scene.webex', location.href).href);
This hosted scratchpad pins its staging engine with engine:. Omit that option when you copy the example alongside release files, whose standard engine name is webex-viewer-engine.js.
The example mounts the viewer, then calls viewer.setMaterial(...) and reads camera properties once scene-ready has fired. In a single-page application, call viewer.destroy() when the component unmounts.
