Vizbl.js reference
The script and the button in your widget code, attribute by attribute.
Vizbl.js is the script in every dashboard's widget code. It defines the <vizbl-button> element, asks Vizbl which widget each button opens and with what data, and loads each widget's own script only when a button on the page needs it.
Install
Add the script once per site, in your theme's <head> or anywhere on the page. data-key holds your publishable key:
<script async src="https://cdn.vizbl.com/@vizbl/loader/dist/vizbl.js" data-key="pk_live_YOUR_PUBLISHABLE_KEY"></script>Never put a secret key, sk_live_…, in data-key. Vizbl.js does not use it, hides every button and, for each <vizbl-button>, says so in the console: replace it with your publishable key and rotate the secret key, because it is now public.
Several products
Each Vizbl product has its own publishable key, and AI Try-On one per widget. If you sell several, keep one script and list one key per product in data-key, separated by spaces:
<script
async
src="https://cdn.vizbl.com/@vizbl/loader/dist/vizbl.js"
data-key="pk_live_YOUR_WALL_ART_KEY pk_live_YOUR_CORE_AR_KEY"
></script>For each button, Vizbl picks the key of the button's product. For AI Try-On, one widget's key serves every type: with several, the first one is used.
The button
<vizbl-button> goes where the button should appear. It stays hidden until Vizbl has found the product and the widget can open, then draws a button that opens it:
<vizbl-button product="wallart" sku="ART-1042"></vizbl-button>| Attribute | Value | For |
|---|---|---|
product | Required. The widget the button opens: see Products. | Every product |
sku, product-url, product-id, object-id | Exactly one: the store product this page shows. See How a button finds the product. | Every product; object-id only Core AR, Rugs, Flooring |
product-variant-id | The platform's id of the variant on screen, next to product-id. | Every product |
label | The button's text. See Labels. | Every product |
unstyled | Draws the button without Vizbl's styles. See Style the button. | Every product |
room-id | The room the viewer opens in. See Initial room. | Wall Art, Rugs, Flooring |
type | wallcovering opens a Flooring product on the walls. See Wallcovering. | Flooring |
mode | ar-viewer, ar-one-click or advanced-ar. See Modes. | Core AR |
variant-id | The model's material variant. See Variants and camera. | Core AR |
camera-orbit, min-camera-orbit, max-camera-orbit | The camera's start and limits. See Variants and camera. | Core AR |
The button follows its attributes: when your store's script changes product-variant-id as the shopper picks a colour or a size, the button asks again and opens the variant on screen.
Products
product takes one of five values. Each opens a widget whose package section documents what the shopper sees:
product | Opens | Default label |
|---|---|---|
wallart | Room Viewer, wall art | View on your wall |
rugs | Room Viewer, rugs | View in your room |
flooring | Room Viewer, flooring | View in your room |
flooring with type="wallcovering" | Room Viewer, wallcovering | View on your wall |
core-ar | Core AR | The mode's own: View in 3D & AR, View in AR or View in advanced AR |
ai-try-on | AI Try-On | Try it on |
Default labels are in English whatever the widget's language; to show another, write the text inside the tag.
How a button finds the product
A button names your store's product in one of four ways. Use the one your store already has on the product page:
| Attribute | Value | Use it when |
|---|---|---|
sku | The product's SKU in your store. | Your template can print the SKU, as the Wall Art and AI Try-On dashboards suggest. |
product-url | The full address of the product page, https://…. The query string and fragment are ignored. | Your products have no SKU. |
product-id | Your platform's own id of the product, for example Shopify's product id. Add product-variant-id for the variant on screen. | Your store is connected to Vizbl and has variants. |
object-id | The id of the Vizbl object, from the dashboard. | You sell Core AR, Rugs or Flooring and pick the object yourself, as their dashboards do. |
sku, product-url and product-id find the Vizbl object through the product's link in the dashboard's Store products. Wall Art and AI Try-On also take the picture, the title and the size or product type from that link, so link the product there before you add its button.
Labels
Without a label, the button shows its product's default label. To replace it, in order of precedence:
- Write the text, or your own elements, inside the tag:
<vizbl-button product="wallart" sku="ART-1042">See it on your wall</vizbl-button>. - Set the
labelattribute:<vizbl-button product="wallart" sku="ART-1042" label="See it on your wall"></vizbl-button>.
Style the button
Vizbl.js styles its button with zero specificity, so any rule of your theme wins. To change a single value, set its CSS variable on the button or any of its parents:
vizbl-button {
--vizbl-button-background: #111827;
--vizbl-button-border-color: #111827;
--vizbl-button-color: #ffffff;
--vizbl-button-border-radius: 9999px;
}| Variable | Default |
|---|---|
--vizbl-button-background | #3556f0 |
--vizbl-button-border-color | #3556f0 |
--vizbl-button-color | #ffffff |
--vizbl-button-border-radius | 0.5rem |
--vizbl-button-font-family | inherit |
--vizbl-button-font-size | 0.875rem |
--vizbl-button-font-weight | 500 |
--vizbl-button-padding | 0.375rem 0.75rem |
With unstyled, the button has no Vizbl styles at all: style vizbl-button button with your theme's classes. A Core AR button is the Core AR element itself: see Customization.
Hidden buttons
A button that cannot open its widget draws nothing. The <vizbl-button> element then carries data-state="hidden" and the reason in data-reason, and the browser console says why:
[vizbl] <vizbl-button> is not shown (missing_key): the vizbl.js script tag has no data-key.| Reason | What happened | Fix |
|---|---|---|
missing_key | The script has no data-key. | Copy the script again from your dashboard. |
invalid_key | No key in data-key is a valid, active publishable key. | Copy the key again from your dashboard. It starts with pk_live_. |
secret_key | data-key holds a secret key, sk_…. | Use your publishable key and rotate the secret key. |
domain_not_allowed | The page's host is not on your allowed domains. | Add the host exactly as the address bar shows it. |
product_not_enabled | None of the keys belongs to the button's product, or that product's key is revoked or not allowed on this host. | Add that product's key to data-key. See Several products. |
unsupported_product | product is missing or is not one of the five values. | Fix the spelling. |
missing_identifier | The button names none of sku, product-url, product-id and object-id, or more than one, or product-variant-id without product-id. | Keep exactly one. |
product_not_linked | No Vizbl object is linked to this store product. | Link the product in the dashboard's Store products, or name the object with object-id. |
object_not_found | The object does not exist or belongs to another account, or, for Core AR, it has no variant with this variant-id. | Copy the object id and the variant id again from the dashboard. |
object_not_ready | The object was rejected or hidden by moderation in the dashboard, or, for Core AR, the model is still processing. | Check the object's status in the dashboard, or wait for the model to finish processing. |
product_data_incomplete | The product's link lacks data the widget needs, such as an AI Try-On product type. | Complete the product in the dashboard. |
out_of_tokens | Core AR only: the account ran out of tokens when a shopper tapped AR. | Top up your balance on the dashboard's Billing page. |
resolver_required | This button needs a Vizbl service that is not available yet. | Name the product with object-id, or try again later. |
unavailable | Vizbl refused the request, for example a product-url that is not a full address, or the widget's script could not load. | Check the button's attributes, your connection and your Content Security Policy. |
Automatic mode
On a page with the script and no <vizbl-button>, Vizbl.js places the buttons itself:
- It checks that the page is a product page: it has a JSON-LD
Product, anog:typeofproduct, or a Shopify, WooCommerce or BigCommerce product id. On any other page it does nothing. - It names the product the ways it can: the page's address, its canonical address, the SKU of its JSON-LD
Product(a GTIN or MPN matches only when your store uses it as the SKU), and the platform's product id. - It asks Vizbl for every product linked to it, and puts their buttons in a row right after Add to cart. It finds that button on Shopify, WooCommerce, BigCommerce, Wix Stores and Tilda themes, and any button with the name or class
add-to-cart.
The row is a <div data-vizbl-auto> of ordinary <vizbl-button> elements, which your theme can style or move. If the page has no Add to cart it finds, the console says so: place <vizbl-button> in your template instead.
A Flooring product meant for walls needs its own <vizbl-button product="flooring" type="wallcovering"> in your template.
A single <vizbl-button> anywhere on the page turns automatic mode off for that page, so a button you place yourself always wins.
Content Security Policy
If your site sends a Content Security Policy, add the sources Vizbl.js and the widgets it loads need:
| Directive | Sources | Why |
|---|---|---|
script-src | https://cdn.vizbl.com 'wasm-unsafe-eval' | Vizbl.js and the widgets' scripts. The 3D decoders of Room Viewer and Core AR run as WebAssembly. |
connect-src | https://api.vizbl.com https://cdn.vizbl.com blob: | Vizbl's API, and the 3D models, rooms and lighting it points to. |
img-src | https://cdn.vizbl.com data: blob: | Room photos, textures and the widgets' own images. |
style-src | 'unsafe-inline' | Vizbl.js and every widget add their own <style> elements. |
font-src | https://cdn.vizbl.com https://fonts.gstatic.com | The widgets' typeface, and a second typeface for some languages. |
worker-src | blob: | The 3D decoders run in a worker. |
Some features need one more source:
- Core AR on a computer shows a QR code that continues on the phone: add
https://viewer.vizbl.comtoscript-srcandimg-src, andhttps://fonts.googleapis.comtostyle-src. - Core AR's AR on Android loads its AR engine from
https://8wall.vizbl.comand, for rugs and floor coverings, a floor-segmentation runtime fromhttps://cdn.jsdelivr.net: add both toscript-srcandconnect-src. - Compressed models (Draco geometry, or KTX2 textures in Core AR) load their decoders from
https://www.gstatic.com: add it toconnect-src. - Wall Art and AI Try-On load the product's image from wherever your store hosts it: add that host to
img-srcandconnect-src. It must also allow other sites to load the image, with anAccess-Control-Allow-Originheader.
AI Try-On also uploads the shopper's photo to a storage address Vizbl's API returns. Before you enforce a policy, send it as Content-Security-Policy-Report-Only and open each widget you use, on a computer and on a phone: the browser console names any source the policy would block.