Skip to main content
This guide explains how to send events to the journey iframe, handle incoming requests, observe the message flow, and use the standard bridge event catalogue.

Message types overview

GBGBridge uses three message types, all sharing the same BridgeMessage envelope with a correlationId for request-response pairing: See API Reference → BridgeMessage for the full envelope shape.

Sending events to the journey

Events are fire-and-forget messages from the host to the journey. Use them to notify the journey of state changes, user actions, or lifecycle transitions.
The SDK generates a fresh correlation ID for every event in the format web-event-{uuid}.

Common host → iframe events

These are events the host can emit to coordinate with the journey. The journey-side SDK subscribes to them. The constants for these are exported as BridgeActions.HOST_THEME_UPDATE, BridgeActions.HOST_NAVIGATION_BACK, etc. Use them rather than magic strings.

Bridge event catalogue (iframe → host)

The journey emits these events. Subscribe via useBridgeHostEvent (React) or delegate.onMessage (direct).

Journey lifecycle

Capture lifecycle

For the canonical payload shapes of each event, refer to the iframe-side SDK (TypeScript Bridge SDK) — it is the source of truth for what data each event carries.

Subscribing in React

Subscribing without React

Handling incoming requests

When the journey sends a request, the host routes it to a registered handler or — if none is registered — to pendingRequests plus delegate.onUnhandledRequest.

Using useBridgeCapability (React)

The hook registers on mount and unregisters on unmount. Setting a handler does not declare the capability — pass an entry in the capabilities prop on the provider, or use host.registerCustomCapability(...) to do both in one call. See Concepts → Declaring vs. Registering.

Using registerHandler / registerCustomCapability directly

Handling via the delegate (catch-all)

Use delegate.onUnhandledRequest for catch-all logic — for example, when you have a single coordinator object handling many request types.
When responding via host.respond({ ... }), the action is resolved from the matching pendingRequests entry if not explicitly provided.

Responding to pending requests manually

If a request arrives with no registered handler, it’s stored in pendingRequests (capped at 50; oldest dropped on overflow). You can respond to it later — for example, after a user interaction.
host.pendingRequests mutates in place rather than emitting React updates. If you need the list to be reactive, mirror it into local state via useBridgeHostEvent or delegate.onUnhandledRequest.

Response patterns

BridgeResponder exposes four terminal methods (success, error, cancelled, unsupported) plus one interim method (acknowledge). Call exactly one terminal method per request — subsequent terminal calls on the same responder are no-ops.

Success with data

Error with details

User cancellation

The optional reason becomes the error.message field in the response (with code: "CANCELLED", recoverable: true).

Unsupported action

Same shape as cancelled, but with code: "UNSUPPORTED" and recoverable: false.

Acknowledged (async processing)

For long-running operations, send an interim acknowledged response immediately. The journey treats acknowledgment as “host received but slow” and waits for the terminal response.
acknowledge is chainable and returns the responder — but calling it after a terminal status is a no-op.

Observing all messages

Use delegate.onMessage to see every validated inbound message (the delegate fires after origin and envelope checks pass).
For React without setting a delegate, subscribe to specific actions via useBridgeHostEvent (events only) — the SDK does not currently expose a hook for “every message.” To inspect the full message buffer, read host.receivedMessages (capped at 200; oldest trimmed on overflow). The buffer mutates in place — it does not trigger React updates.

Error handling

Errors from inside the SDK or your handlers are routed to two places: host.lastError (a single-string snapshot) and the delegate’s onError callback (every error).

Sources of errors

  • Handler exceptions — A registered handler throws or returns a rejecting Promise. The error is routed to onError, and if the handler hadn’t responded, an automatic error response with code: "HANDLER_FAILURE" and recoverable: false is sent so the journey isn’t left waiting.
  • Outbound send failures — Resolving targetOrigin failed, the iframe’s contentWindow is null, or postMessage threw. The send is dropped with a console.warn; lastError is set.
  • Delegate exceptions — Your onMessage, onUnhandledRequest, or onMessageSent callback threw. Routed to onError. A throw from onError itself is logged via console.warn and swallowed to prevent recursion.

Subscribing to errors in React

Subscribing without React

host.lastError is a snapshot of the most recent error string — useful for debugging but not for telemetry (you’d miss intermediate errors). Use delegate.onError for every-error visibility.

Next steps

  • Capability Handling — Declare capabilities, register handlers, manage dynamic state.
  • Embedding — React, framework-agnostic, and SSR integration patterns.
  • API Reference — Detailed method signatures and parameters.