WEARFITS Integration Guide
Hosted virtual try-on, secure catalog handshake, and optional estimated size fitting.
Sign upChoose an integration path
| You need | Use |
|---|---|
| A complete storefront experience, dynamic catalog, or estimated size fitting | Hosted iframe + postMessage (recommended) |
| Your own backend and UI | Direct API, with credentials kept server-side; see the API reference |
| A simple link with a static catalog | Standalone URL; use the iframe handshake when products change dynamically |
| To work from this repository's source | The source-only modal SDK in src/embed/; it is unpublished and is not a plug-and-play CDN package |
Try the public integration demo. Its first section is a deterministic UI preview using demo data and never calls the sizing API. The separate CTA opens the real hosted try-on and sends the charted demo catalog after WEARFITS_READY.
How the hosted experience works
- The shopper creates a reusable digital twin from either a selfie plus gender, height, and clothing size, or a selfie plus a full-body photo.
- The shopper selects garments from the catalog supplied by the host.
- WEARFITS renders the look and emits
WEARFITS_COMPLETEwhile keeping its result UI open. - With
?sizeFitting=true, an eligible measurements/clothing-size twin whose stored profile contains the required body data can provide estimated size guidance. The twin may be newly created or reused. Unavailable guidance does not break try-on.
Supported product categories are top, bottom, fullBody, and shoes. Size fitting applies to charted clothing products (top, bottom, and fullBody).
Copy-paste iframe integration
This example uses a public WEARFITS demo image and a valid one-row body chart. Replace the product ID, image, metadata, and illustrative measurements with your own catalog before production.
<iframe
id="wearfits"
title="Virtual try-on"
sandbox="allow-scripts allow-same-origin allow-forms allow-downloads"
allow="camera https://tryon.wearfits.com; web-share https://tryon.wearfits.com"
style="width:100%;height:100vh;border:0"
></iframe>
<script>
const appOrigin = 'https://tryon.wearfits.com';
const frame = document.getElementById('wearfits');
const apiKey = '<public-merchant-key>'; // Your merchant integration key.
const products = [{
id: 'merchant-top-1',
name: 'Merchant Top',
category: 'top',
default: true,
images: ['https://tryon.wearfits.com/products/tops/00881044251-a1.jpg'],
sizeChart: {
version: 1,
basis: 'body',
unit: 'cm',
sizes: [{
label: 'M',
measurements: {
chest: { min: 88, max: 95 },
waist: { min: 69, max: 77 }
}
}]
}
}];
window.addEventListener('message', (event) => {
if (event.source !== frame.contentWindow || event.origin !== appOrigin) return;
switch (event.data?.type) {
case 'WEARFITS_READY':
frame.contentWindow.postMessage(
{ type: 'WEARFITS_INIT', payload: { products, apiKey } },
appOrigin
);
break;
case 'WEARFITS_COMPLETE':
console.log(event.data.payload); // Keep the result UI open.
break;
case 'WEARFITS_ERROR':
console.error(event.data.payload); // Keep retry/error UI open.
break;
case 'WEARFITS_CLOSE':
frame.remove(); // The only teardown signal.
break;
}
});
// Set src only after the READY listener is installed.
frame.src = `${appOrigin}/?sizeFitting=true`;
</script>
The message order is WEARFITS_READY → WEARFITS_INIT → WEARFITS_COMPLETE or WEARFITS_ERROR. COMPLETE and ERROR keep the iframe open. Only WEARFITS_CLOSE authorizes teardown. After the READY/INIT handshake teaches the app the exact host origin, pressing Escape inside the embedded app emits CLOSE to that origin. A no-handshake URL embed has no learned safe origin for Escape/CLOSE, and standalone Escape does not emit a host event.
The public merchant apiKey attributes usage to your merchant. Without it the Worker uses the deployment fallback. Prefer the iframe INIT transport over a URL parameter; do not log the key or send it to analytics.
Always validate both event.source and the exact event.origin, and send messages to the exact appOrigin instead of *.
Product and size-chart shape
Each product needs a unique id, display name, supported category, and one or two public HTTPS images. Set default: true to preselect it.
Size fitting is an explicit opt-in with ?sizeFitting=true. A qualifying sizeChart uses:
version: 1,basis: "body", andunit: "cm"or"in";- unique size labels and
{ min, max }ranges; chestandwaistfor tops;waist,hip, andinseamfor bottoms;chest,waist,hip, andheightfor full-body garments.
The M chart in the iframe example is a complete, copyable chart row. Custom products without a valid chart remain usable for visual try-on but do not qualify for size guidance. Size recommendations are estimated, may be unavailable when a stored twin lacks the required profile data, and never replace a brand's fit policy. See the API reference for the full strict schema and request limits.
Event lifecycle
| Event | Direction | Host action |
|---|---|---|
WEARFITS_READY | App → host | Send one WEARFITS_INIT with the current catalog |
WEARFITS_INIT | Host → app | Supplies payload.products |
WEARFITS_SET_PRODUCTS | Host → app | Replaces products after initialization |
WEARFITS_COMPLETE | App → host | Read the result; keep the iframe open |
WEARFITS_ERROR | App → host | Log or display host feedback; keep the iframe open |
WEARFITS_CLOSE | App → host | Close/remove the host iframe or modal |
WEARFITS_COMPLETE contains the result image URL and only the existing basic product fields. Body measurements are not included in host messages.
Optional Add to Cart
The host owns variant selection and cart mutation. Send cart: { enabled: true, label: 'Add to Cart' } in WEARFITS_INIT to show the button. On WEARFITS_ADD_TO_CART, add one item without navigating and answer with WEARFITS_ADD_TO_CART_RESULT: { ok: true } or { ok: false, reason: 'variant' | 'unavailable' | 'failed' }.
The app supplies shopper-facing messages. If no reply arrives in ten seconds, it says the add could not be confirmed; check the cart before retrying. A late reply is still accepted. The full contract is in the SDK reference.
Standalone URL
For a fixed catalog, link directly to https://tryon.wearfits.com/ and use supported URL parameters such as productsUrl or avatarId. A hosted iframe with the READY → INIT handshake is recommended when the catalog is page-specific or changes during the session; it avoids oversized URLs and initialization races.
Supported URL parameters
| Parameter | Purpose |
|---|---|
products | URL-encoded product array/object, or a public catalog URL |
productsUrl | Public URL returning a product array or { "products": [...] } |
avatarId | Existing reusable digital-twin ID |
sizeFitting=true | Opt in to estimated size guidance for eligible completed looks |
step, session, and launch are internal/debug controls, not storefront integration parameters. A normal public embed should use only ?sizeFitting=true and let persisted twins resume.
Product, image, and selection rules
- A product has a unique
id,name,category, one or two public HTTPSimages, optionaldefault, and optionalsizeChart. - Garment image URLs must be reachable by the backend without merchant cookies. Use clear, high-resolution product views on neutral backgrounds; the app sends at most two URLs per garment.
- A valid look is either top + bottom, or one full-body garment. Shoes are optional. Selecting
fullBodyclears top/bottom; selecting a top or bottom clearsfullBody. default: truepreselects a product. If a catalog omits a required counterpart, the app may add its built-in gap-fill garment; send a complete default selection when exact merchant control matters.WEARFITS_SET_PRODUCTSreplaces the catalog after initialization and uses the same product shape asINIT.
Results, errors, and persistence
WEARFITS_COMPLETE includes an absolute resultImageUrl and selectedProducts containing only basic product fields (id, name, category). Size charts, body ranges, and dimension scores are never sent to the host. WEARFITS_ERROR contains a stable code and human-readable message; keep the iframe mounted because the app owns its retry UI.
Existing error codes include:
TWIN_CREATION_FAILED: the digital twin could not be created;FITTING_FAILED: virtual garment rendering failed;INVALID_IMAGE: an input image is invalid or unsupported;NETWORK_ERROR: the service could not be reached;TIMEOUT: processing exceeded its allowed time.
Reusable digital-twin IDs are stored in the wearfits_twin cookie with a 30-day TTL. On HTTPS it is written SameSite=None; Secure; Partitioned, so its CHIPS partition is scoped to the embedding storefront; plain-HTTP local development falls back to SameSite=Lax. Pending generation and the last completed result also use local browser storage and can resume after reload. Hosts should not clear app storage or force a cold session during a normal launch.
Direct API
Use the direct API when you are building your own backend and UI rather than embedding the hosted experience. API credentials and privileged calls belong on your server, never in storefront JavaScript. Start with the WEARFITS API reference.
Modal SDK status
The JavaScript modal implementation in src/embed/ is source-only and unpublished. No public script URL or npm package is built from this repository, so it is not a plug-and-play integration. Hosted storefronts should use the iframe contract above.
Troubleshooting
- No initialization: wait for
WEARFITS_READY, verify bothevent.sourceand exact origin, then sendWEARFITS_INITtohttps://tryon.wearfits.com. - Camera does not open: serve the host over HTTPS and retain
allow="camera https://tryon.wearfits.com; web-share https://tryon.wearfits.com"plus the documented sandbox permissions. - Size button is absent: confirm
sizeFitting=true, an eligible measurements/clothing-size twin with the required stored profile data, and at least one selected clothing product with a valid body-based chart. The twin may be newly created or reused. Selected uncharted products are omitted from recommendations; unavailable/error responses intentionally hide the feature. - Host closes too early: do not tear down on
WEARFITS_COMPLETEorWEARFITS_ERROR; only close onWEARFITS_CLOSE. - Dynamic products are stale: send
WEARFITS_SET_PRODUCTSafter initialization or reopen with a fresh catalog.
For integration support, contact support@wearfits.com.