Skip to content

iframe Events

This page describes the events the host page can listen for on the iframe DOM element.

How to Listen

js
iframe.addEventListener('eventName', (event) => {
  console.log(event.detail);
});

Except for the browser-native load / error events, plugin events are dispatched as CustomEvent, and business data is read from event.detail.

Event List

Event nameSceneCollectionDescription
loadSupportedSupportediframe page resources finished loading
errorSupportedSupportedloading error, permission failure, and so on
incompatibilitySupportedSupportedpreflight compatibility check failed
readySupportedSupportedbasic scene or collection information is ready
downloadAssetStartSupportedSupportedasset download starts
downloadAssetProgressSupportedSupportedasset download progress changes
downloadAssetEndSupportedSupportedasset download completes
loadSceneStartSupportedSupportedscene content starts loading
loadSceneEndSupportedSupportedscene content finishes loading
sceneStartSupportedSupportedscene starts and the user can enter the experience
trackedSupportedSupportedtarget tracked successfully
lostTrackSupportedSupportedtarget tracking lost
openUrlSupportedSupportedwebpage jump triggered
sceneReadyNot supportedSupporteda concrete scene inside the collection is ready
sceneDestroyNot supportedSupportedprevious scene is destroyed before switching

load

ts
type LoadEvent = Event

Indicates that iframe page resources are loaded. It does not mean assets are finished downloading.

error

ts
interface PluginErrorDetail {
  message: string;
  code?: number;
  isCameraNotFound?: boolean;
  isUserDeniedCamera?: boolean;
  isUserDeniedGyroscope?: boolean;
}

It may also be a plain string.

If the browser's native error event fires instead, the payload is the browser's Error event object.

incompatibility

ts
type IncompatibilityDetail = Record<string, any>

The payload shape is not fully fixed for now. Common cases include:

  • the current browser is not suitable for opening the camera
  • the current mode is unavailable on this client

ready

Scene

ts
interface SceneInfo {
  sceneId: string;
  name: string;
  description: string;
  thumbnailUrl: string;
  type: string;
  collectionId: string;
  collectionName: string;
  firstPage: {
    backgroundImageUrl?: string;
    logoUrl?: string;
    buttonUrl?: string;
    hideLogoAndName?: boolean;
    hideLogoAndSceneName?: boolean;
  };
  metadata: {
    htmlTitle?: string;
    share?: {
      title?: string;
      description?: string;
      picture?: string;
      pictureUrl?: string;
    };
  };
  setting: {
    skipScanMarker?: boolean;
    scanImage?: string;
    scanText?: string;
    hideScanImage?: boolean;
    userMarker?: string;
  };
  objects: Array<{
    id: number;
    name: string;
    type: string;
  }>;
}

interface SceneReadyDetail {
  sceneInfo: SceneInfo;
  api: SceneApi;
}

Collection

ts
interface CollectionInfo {
  collectionId: string;
  name: string;
  description: string;
  thumbnailUrl: string;
  functionType: string;
  firstPage: {
    backgroundImageUrl?: string;
    buttonUrl?: string;
    hideLogoAndName?: boolean;
  };
  sceneList: string[];
  setting: {
    continue_scan?: number;
  };
}

interface CollectionReadyDetail {
  collectionInfo: CollectionInfo;
  api: object;
}

downloadAssetStart

ts
type DownloadAssetStartDetail = undefined

downloadAssetProgress

ts
type DownloadAssetProgressDetail = number

Value range: 0.0 - 1.0.

downloadAssetEnd

ts
type DownloadAssetEndDetail = undefined

loadSceneStart

ts
type LoadSceneStartDetail = undefined

loadSceneEnd

ts
type LoadSceneEndDetail = undefined

sceneStart

ts
type SceneStartDetail = undefined

tracked

ts
type TrackedDetail = undefined

lostTrack

ts
type LostTrackDetail = undefined

openUrl

ts
type OpenUrlDetail = string

detail is the URL about to be opened.

sceneReady

Collections only.

ts
interface SceneReadyDetailInCollection {
  sceneInfo: SceneInfo;
  api: SceneApi;
}

sceneDestroy

Collections only.

ts
interface SceneDestroyDetail {
  sceneId: string;
}

Event Order

Scene

text
load
-> ready
-> downloadAssetStart
-> downloadAssetProgress
-> downloadAssetEnd
-> loadSceneStart
-> loadSceneEnd
-> sceneStart

Collection

text
load
-> ready
-> sceneReady
-> downloadAssetStart
-> downloadAssetProgress
-> downloadAssetEnd
-> loadSceneStart
-> loadSceneEnd
-> sceneStart