WEARFITS Integration Guide

Hosted virtual try-on, secure catalog handshake, and optional estimated size fitting.

Choose an integration path

You needUse
A complete storefront experience, dynamic catalog, or estimated size fittingHosted iframe + postMessage (recommended)
Your own backend and UIDirect API, with credentials kept server-side; see the API reference
A simple link with a static catalogStandalone URL; use the iframe handshake when products change dynamically
To work from this repository's sourceThe 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

  1. 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.
  2. The shopper selects garments from the catalog supplied by the host.
  3. WEARFITS renders the look and emits WEARFITS_COMPLETE while keeping its result UI open.
  4. 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:

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

EventDirectionHost action
WEARFITS_READYApp → hostSend one WEARFITS_INIT with the current catalog
WEARFITS_INITHost → appSupplies payload.products
WEARFITS_SET_PRODUCTSHost → appReplaces products after initialization
WEARFITS_COMPLETEApp → hostRead the result; keep the iframe open
WEARFITS_ERRORApp → hostLog or display host feedback; keep the iframe open
WEARFITS_CLOSEApp → hostClose/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

ParameterPurpose
productsURL-encoded product array/object, or a public catalog URL
productsUrlPublic URL returning a product array or { "products": [...] }
avatarIdExisting reusable digital-twin ID
sizeFitting=trueOpt 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

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:

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.

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

For integration support, contact support@wearfits.com.