Events
React when the button is ready, or when it fails and why.
<vizbl-core> dispatches two events. Both bubble, so you can listen on the element or on any parent, and both cross shadow roots.
| Event | When |
|---|---|
core-ar-ready | The model's details are read and the button works; the 3D file loads on tap. Fires again each time the element starts over, after an attribute changes. |
core-ar-error | The element could not start, or a tap could not open anything. |
Each event's detail has the same shape:
interface CoreArWidgetEventDetail {
/** Set on `core-ar-error` only. */
code?: CoreArWidgetErrorCode
/** The element's `object-id`. */
objectId: string
/** The element's `type`. */
type: string
}The detail never contains your key. Both types are exported by @vizbl/core-ar.
Listen
document.addEventListener('core-ar-error', (event) => {
console.warn('Core AR failed for', event.detail.objectId, event.detail.code)
})A failed element also carries its state on itself: data-state="error" and the code in data-error-code. That is enough to hide the button with CSS without listening.
Error codes
| Code | Meaning |
|---|---|
MISSING_API_KEY | No api-key. |
MISSING_OBJECT_ID | No object-id. |
INVALID_TYPE | type is missing or not a mode. |
INVALID_SIZE_TYPE | size-type is neither cm nor inch. |
INVALID_KEY | The key is mistyped, expired, revoked or not a publishable key. |
DOMAIN_NOT_ALLOWED | The page's host is not among the key's allowed domains. |
OBJECT_NOT_FOUND | No object has this object-id. |
VARIANT_NOT_FOUND | The object has no variant with this variant-id. |
MODEL_UNAVAILABLE | The object has no variant to show, or the AR modes need GLB and USDZ models the variant lacks. |
POLICY_DENIED | The key belongs to another product, or the object does not allow one-tap AR (ar-one-click). |
PAYMENT_REQUIRED | The account is out of tokens, so AR does not open; the viewer shows "Viewer temporarily unavailable". Top up on Billing. |
RATE_LIMITED | Too many requests reached Vizbl; the element stays in error until the page reloads. |
SESSION_EXPIRED | After the element started, Vizbl stopped accepting its requests, for example because its access expired. Reload the page. |
NETWORK_ERROR | The request did not reach Vizbl. |
API_UNAVAILABLE | Vizbl's API answered with a server error. |
REQUEST_FAILED | Vizbl's API refused the request for another reason. |
INVALID_RESPONSE | Vizbl's API answered with something the element cannot read. |
VIEWER_UNAVAILABLE | The 3D viewer failed to load after a tap. |
INITIALIZATION_FAILED | Anything else that stopped the element from starting. |
Troubleshooting says what to do about the common ones.