BridgeHostProvider, an <iframe>, and one capability handler.
What this example demonstrates
- Instantiating
BridgeHostProviderwith origin allowlist and capabilities - Declaring document-capture support via the
capabilitiesprop - Registering a handler with
useBridgeCapability - Surfacing internal bridge errors via
useBridgeHostError
Complete source
How it works
-
BridgeHostProviderwraps the iframe-rendering subtree. The provider waits foriframeto transition fromnullto a real element, then instantiates the underlyingBridgeHostand snapshotsallowedOrigins,hostVersion, andcapabilities. -
useStatefor the iframe element is required — notuseRef. The provider’s effect depends oniframe, and refs don’t trigger re-renders when the iframe element mounts. -
navigator.permissions.queryreads the current camera permission state. Passing it throughCapabilityInfo.permissionStatelets the journey decide whether to surface a permission prompt before triggering capture. -
useBridgeCapabilityregisters a handler for the"camera.document.capture"action. On mount it callshost.registerHandler; on unmount it deregisters (only if its own proxy is still the active handler). -
useBridgeHostErrorsubscribes to internal SDK errors (handler exceptions, send failures, delegate throws). Lifted into local state so the banner re-renders when an error occurs.
What happens at runtime
Required page configuration
For this minimal example, no special configuration beyond a normal React app is needed. In production, ensure your host page sets:Content-Security-Policy: frame-src https://journey.example.com;— Allow the journey origin in your CSP.<iframe allow="camera">— Delegate camera permission to the iframe context.- HTTPS in production — Mixed content (HTTPS host + HTTP iframe) is silently blocked by browsers.
Next steps
- Two-Way Communication — Send events to the journey and observe inbound traffic.
- Advanced Integration — Production patterns with pre-launch validation, lifecycle, and error states.
- Tutorial — Build the full app with backend token exchange.