postMessage to the host page. You must register a listener on the host page to handle that intent.
Embed the widget (iframe + optional listener)
Navigation deeplinks only work when both parts are on your page:- The iframe: loads the chat UI from Chatropic.
- A host script: defines
setupChatropicNavigationListenerand wires it to your router orlocation.assign.
Full embed example
Use the iframesrc from the Embed tab on Deploy > Chat widget. Current web snippets use https://chatropic.com/embed/key/{publishable-key}.
Website widget (floating launcher)
The snippet from Copy website widget code on the Embed tab includessetupChatropicLauncherHostListener and embed wake scripts. The iframe src includes mode=launcher.
When integrating manually, register one navigation listener per page. A single listener handles navigation messages from either embed layout.
setupChatropicLauncherHostListener
The website widget posts chatropic:launcher-state messages when chat opens or closes on mobile. The host listener resizes the iframe between a compact closed footprint and full viewport when open.
Paste this from the copied website widget snippet rather than hand-rolling iframe sizing on mobile.
setupChatropicNavigationListener
This is the function integrators install on the host page (the page that contains the iframe, not inside the iframe).
What it does
- Subscribes to
window.messageon the host page. - Accepts messages only when
event.origin === widgetOrigin. - Handles messages where
event.data.type === "chatropic:navigate". - Validates
event.data.pathis a relative URL (starts with/, nojavascript:orhttps://). - Calls your
onNavigate(path)callback, or falls back towindow.location.assign(path).
Message protocol
When the user clicks a Navigation card inside the iframe, the widget posts towindow.parent:
SPA integration
Pass a customonNavigate callback instead of relying on location.assign:
Reuse the listener on multiple pages
Define the function once in a shared bundle or layout, then callsetupChatropicNavigationListener on every page that embeds the iframe:
Security
UI payload shape
Sync responses andagent:done events may include:
onNavigate; see React Native SDKOn mobile, the React Native SDK delivers the same payload through onNavigate; see React Native SDK.
Click analytics (optional)
The widget dispatcheschatropic:nav-card-clicked on the iframe window when the user taps the card. Listen from host instrumentation if needed:
Web embed
Copy website widget or inline panel snippets from Deploy, Chat widget.
Navigation routes
Configure destinations for the agent.