Skip to Content

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.

EventWhen
core-ar-readyThe 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-errorThe 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

CodeMeaning
MISSING_API_KEYNo api-key.
MISSING_OBJECT_IDNo object-id.
INVALID_TYPEtype is missing or not a mode.
INVALID_SIZE_TYPEsize-type is neither cm nor inch.
INVALID_KEYThe key is mistyped, expired, revoked or not a publishable key.
DOMAIN_NOT_ALLOWEDThe page's host is not among the key's allowed domains.
OBJECT_NOT_FOUNDNo object has this object-id.
VARIANT_NOT_FOUNDThe object has no variant with this variant-id.
MODEL_UNAVAILABLEThe object has no variant to show, or the AR modes need GLB and USDZ models the variant lacks.
POLICY_DENIEDThe key belongs to another product, or the object does not allow one-tap AR (ar-one-click).
PAYMENT_REQUIREDThe account is out of tokens, so AR does not open; the viewer shows "Viewer temporarily unavailable". Top up on Billing.
RATE_LIMITEDToo many requests reached Vizbl; the element stays in error until the page reloads.
SESSION_EXPIREDAfter the element started, Vizbl stopped accepting its requests, for example because its access expired. Reload the page.
NETWORK_ERRORThe request did not reach Vizbl.
API_UNAVAILABLEVizbl's API answered with a server error.
REQUEST_FAILEDVizbl's API refused the request for another reason.
INVALID_RESPONSEVizbl's API answered with something the element cannot read.
VIEWER_UNAVAILABLEThe 3D viewer failed to load after a tap.
INITIALIZATION_FAILEDAnything else that stopped the element from starting.

Troubleshooting says what to do about the common ones.

On this page