Skip to content

TryonUIPlugin API Reference

TryonUIPlugin is the ready-made overlay for the try-on session. It listens to RingTryonPlugin and renders three things over the canvas:

  • a loading box with a title, optional subheader, optional logo and a progress bar, shown while hand tracking initialises;
  • a hand prompt - an outlined hand and a line of copy - once try-on is live but no hand has been detected yet;
  • error messages for every camera and startup failure the plugin can report.

Using it is optional. Everything it does can be built from the plugin's events, but it saves you writing loading and error states for a dozen camera failure modes.

javascript
const tryon = await viewer.addPlugin(ij_vto.RingTryonPlugin);
await viewer.addPlugin(ij_vto.TryonUIPlugin);

Add it after the try-on plugin

TryonUIPlugin looks for a try-on plugin on the viewer when it is added, and throws if there isn't one. Always add RingTryonPlugin first.

Alias

The plugin is exported both as ij_vto.TryonUIPlugin and as ij_vto.RingTryonUIPlugin. They are the same class - the second name exists for older integrations.

Configuring

Pass a config to the constructor, or update it later with configure(). Both take a deep-partial object that is merged onto the defaults, so you only specify what you want to change.

javascript
await viewer.addPlugin(new ij_vto.TryonUIPlugin({
  loading: {
    title: "Preparing your try-on",
    subText: null,                          // hide the subheader
    logo: "https://example.com/logo.svg",
    align: "center",
    background: "#111",
    textColor: "#fff",
    progressColor: "linear-gradient(90deg, #c9a227, #f0d878)",
  },
  handPrompt: {
    text: "Show the back of your hand",
  },
}));

configure(partial)

Merges a partial config onto the current one and re-applies it to the live DOM immediately - safe to call while try-on is running.

javascript
const ui = viewer.getPlugin(ij_vto.TryonUIPlugin);

// Switch to a different message mid-session.
ui.configure({ handPrompt: { text: "Move your hand a little closer" } });

config

The full, resolved config object. Read it to inspect current values; mutate through configure() so changes reach the DOM.

enabled: boolean

Set to false to suppress the whole overlay without removing the plugin.

loading

The box shown while hand tracking initialises.

PropertyTypeDefaultDescription
enabledbooleantrueRender the loading box at all. Set to false if you show your own loading state.
titlestring"Loading..."Main heading.
subTextstring | null"Loading models..."Subheader. null or '' hides it.
logostring | nullnullLogo above the title. Either an image URL / data-URI, or a raw SVG or HTML string.
size'card' | 'half' | 'full''card'Preset box size - a centered card, roughly half the container, or a full-canvas overlay.
widthstring | nullnullExplicit CSS width, e.g. '320px' or '60vw'. Takes precedence over size.
align'start' | 'center' | 'end''start'Horizontal alignment of logo, title and subheader.
backgroundstringwhite, near-opaqueAny valid CSS background value.
textColorstring'#000000'Title colour.
subTextColorstring'#4a4a4a'Subheader colour.
showProgressBarbooleantrueShow the progress bar.
progressColorstringdark gradientCSS colour or gradient for the progress fill.
javascript
// Full-bleed dark loading screen with a logo and no subheader.
ui.configure({
  loading: {
    size: "full",
    align: "center",
    background: "#0b0b0b",
    textColor: "#ffffff",
    subText: null,
    logo: "https://example.com/logo-light.svg",
  },
});

handPrompt

The overlay shown once try-on is live but no hand has been detected yet.

PropertyTypeDefaultDescription
enabledbooleantrueShow the prompt.
textstring | null"Show your hand to start"Prompt copy. null or '' leaves just the outline.
showHandOutlinebooleantrueDraw the outlined hand graphic.
handSvgstringbuilt-in outlineReplace the outline with your own SVG markup.
colorstringnear-whiteColour of the prompt text.

showHandPrompt() / hideHandPrompt()

Show or hide the prompt imperatively. showHandPrompt() respects handPrompt.enabled and does nothing when the prompt is disabled.

javascript
// Text-only prompt, no outline.
ui.configure({
  handPrompt: { showHandOutline: false, text: "Hold your hand up to the camera" },
});

messages

Every user-facing string the plugin can display. Override any subset - for translation, or to match your store's tone.

PropertyDescription
initializationLoading title (mirrors loading.title).
initializationSubTextLoading subheader.
error.noSupportThe browser has no webcam API.
error.permissionDeniedThe user declined camera access.
error.startupFailedInitialisation failed for a non-camera reason.
error.mediaDevicesErrorGeneric camera start failure.
error.runtimeErrorTry-on failed while already running.
error.abortErrorCamera access was aborted.
error.invalidStateErrorThe page was inactive when access was requested.
error.notFoundErrorNo camera matched the requested constraints.
error.notReadableErrorThe camera is in use by another application.
error.overconstrainedErrorThe camera can't satisfy the requested settings.
error.securityErrorCamera access is blocked by security settings.
error.typeErrorThe camera request was rejected as invalid.
error.unknownFallback for unrecognised failures.
error.unknownCameraErrorFallback for unrecognised camera failures.
javascript
// Localise the strings users are most likely to see.
ui.configure({
  messages: {
    initialization: "Chargement…",
    initializationSubText: "Préparation de l'essayage virtuel.",
    error: {
      permissionDenied: "Vous avez refusé l'accès à la caméra. Autorisez-le puis réessayez.",
      notReadableError: "Votre caméra est utilisée par une autre application.",
    },
  },
});

Full example

javascript
const tryon = await viewer.addPlugin(ij_vto.RingTryonPlugin);

const ui = await viewer.addPlugin(new ij_vto.TryonUIPlugin({
  loading: {
    title: "Preparing your try-on",
    subText: "This takes a few seconds the first time.",
    logo: "https://example.com/logo.svg",
    size: "full",
    align: "center",
    background: "#0b0b0b",
    textColor: "#ffffff",
    subTextColor: "#a0a0a0",
    progressColor: "linear-gradient(90deg, #c9a227, #f0d878)",
  },
  handPrompt: {
    text: "Show the back of your hand",
    color: "#ffffff",
  },
}));

await tryon.start();