Taking a screenshot
Screenshots that include the camera feed need the session started with the screenshot opt-in (see the warning below):
await ar.create({ enableScreenshots: true }); // ARView
// or, on the engine/hook: startSession({ enableScreenshots: true })
const shot = await ar.takeScreenshot({ format: 'png', includeReticle: false });
if (shot.success) {
// shot.dataUrl: 'data:image/png;base64,…'
// shot.width / shot.height
// shot.timestamp
// shot.includesCamera: whether the camera feed is in the image
const img = new Image();
img.src = shot.dataUrl;
document.body.appendChild(img);
} else {
console.warn(shot.code, shot.error);
}Options (all optional):
| Option | Default | Meaning |
|---|---|---|
format | 'png' | 'png' or 'jpeg' |
quality | 0.92 | JPEG quality (ignored for PNG) |
width / height | canvas size | Output dimensions |
includeReticle | engine default | Whether the placement reticle is composited in |
The same call exists as a functional helper,
takeScreenshot(view, options), and on the useARCore hook.
Saving the image
A data URL is all you get back, turning it into a download or an upload is your app's job:
function downloadShot(shot) {
const a = document.createElement('a');
a.href = shot.dataUrl;
a.download = `ar-${shot.timestamp}.png`;
a.click();
}When screenshots fail
Screenshots composite the camera image with the rendered scene, which
needs the WebXR camera-access feature. Two failure codes exist:
| Code | Meaning |
|---|---|
CAMERA_CAPTURE_UNAVAILABLE | The browser/session has no camera access; the capture cannot include the camera feed |
CAPTURE_BUSY | Another capture is already in flight |
Warning
Camera access is an explicit opt-in: the session must start with
enableScreenshots: true (ARView.create() or the engine's
startSession()), which adds camera-access to the session's
optional features. It is not implied by lightEstimation
(that coupling was removed in 1.1.0). Without the opt-in,
or on browsers that don't grant camera access at all,
takeScreenshot returns CAMERA_CAPTURE_UNAVAILABLE while AR
keeps running. Design your UI to treat screenshots as best-effort,
and always branch on shot.success.
Note
Composition runs as a per-pixel loop on the main thread (~2M iterations at 1080p), so expect a visible hitch on capture. Fine for a shutter button; don't call it per frame.