Message types overview
GBGBridge uses three message types, all sharing the sameBridgeMessage 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.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 viauseBridgeHostEvent (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 — topendingRequests plus delegate.onUnhandledRequest.
Using useBridgeCapability (React)
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)
Usedelegate.onUnhandledRequest for catch-all logic — for example, when you have a single coordinator object handling many request types.
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 inpendingRequests (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
reason becomes the error.message field in the response (with code: "CANCELLED", recoverable: true).
Unsupported action
cancelled, but with code: "UNSUPPORTED" and recoverable: false.
Acknowledged (async processing)
For long-running operations, send an interimacknowledged 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
Usedelegate.onMessage to see every validated inbound message (the delegate fires after origin and envelope checks pass).
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 automaticerrorresponse withcode: "HANDLER_FAILURE"andrecoverable: falseis sent so the journey isn’t left waiting. - Outbound send failures — Resolving
targetOriginfailed, the iframe’scontentWindowis null, orpostMessagethrew. The send is dropped with aconsole.warn;lastErroris set. - Delegate exceptions — Your
onMessage,onUnhandledRequest, oronMessageSentcallback threw. Routed toonError. A throw fromonErroritself is logged viaconsole.warnand 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.