frame.js) adds the chat to your page and exposes functions to pass configuration, credentials and context to it. The chat also sends a few events back to your page through the browser’s postMessage API.
Parent to Widget Communication
Window Configuration
When embedding the widget, configure it through thewindow.AGO object before loading the widget script. These options control authentication, appearance, and behavior.
Panel size
The chat panel is 550px wide by default. SetpanelWidth to change it:
Percentages resolve against the viewport, not against any element on your page,
because the panel is positioned
fixed. panelWidth: "50%" on a 1400px screen is 700px.
An invalid value is ignored, the panel stays at 550px, and the reason is logged to the
browser console:
Setting the width from CSS instead
The same value is exposed as a CSS custom property, which lets you vary it with media queries. Set it on#ago-chatbot and it wins over panelWidth — no !important needed:
#ago-chatbot always wins because a value declared on the panel itself takes priority
over one it inherits from the page root, which is where panelWidth writes. Setting it
on #ago-chatbot is the recommended form: it behaves the same either way, so there is
nothing to remember.
Chat content is capped at 768px wide, so a panel wider than that shows empty margins on
either side of the conversation.
Updating JWT at Runtime
UsesendJwtToAGO() to update the JWT token after the widget has loaded. This is useful when the user logs in after the widget is already open, or when the JWT token is refreshed.
Updating Auth Token at Runtime
UsesendAuthTokenToAGO() to pass an external authentication token to the widget. This token is forwarded to agent tools (e.g., HTTP request tool) as the X-Auth-Token header, allowing agents to call your authenticated APIs on behalf of the user.
Sending Metadata
Use thesendMetadataToAGO function to pass context from your application to the widget.
Letting the agent use the metadata to answer
By default the metadata is only used for support tickets: it is mapped to labels in Support → Settings → Your channels → Widget & SDK → Metadata Fields Mapping, and appears in the ticket’s private comment and prefilled fields. The AI agent does not see it. Turn on Send metadata to the agent on the same page to also include the metadata in the agent’s prompt. The agent can then answer using it — for example, replying about the right subscription tier without asking the visitor which plan they are on:- The whole metadata object is sent with every message, so the agent always sees the latest values — reassign it when your app’s state changes.
- The metadata comes from the page embedding the widget, which means a visitor can edit it in their browser. Treat it as information, never as proof: use permissions or a JWT for anything that grants access.
- Keep the payload small (under 10 KB). A larger one is dropped rather than sent to the agent.
- For data the visitor must not be able to change, use an API Data Source instead: AGO fetches it from your API server-side and adds it to the same conversation.
Usage in React Native WebView
If your app shows a web page that loads the widget inside a WebView, call the same function from native code:Widget to Parent Communication
The widget posts two message types to your page. Checkevent.origin before handling them:
CLOSE_CHAT
Sent when the user closes the chat from its header. The widget closes the panel itself; listen for this event only if your page needs to react, for example to restore a layout.UNREAD_STAFF_COUNT
Tells your page how many conversations have replies from your support team that the user hasn’t read. The widget checks every 30 seconds while the chat is closed, and only for visitors who have already opened the chat on this browser. Turn it on withnotifications: true:
sendJwtToAGO(token) whenever the token is refreshed so unread counts are checked for the signed-in user.
Complete Example
Setwindow.AGO before loading frame.js, then send context once the page knows the user:
Metadata in Tickets
Metadata fields you map in Metadata Fields Mapping appear in the conversation sidebar of the admin interface and in the private comment of tickets created from the conversation. With Help Scout, the private comment also lists the metadata as JSON.Security Considerations
Origin Validation
Always validate the message origin:Sensitive Data
- Do not send: Passwords, API keys, tokens, credit card numbers
- Safe to send: User IDs, order IDs, plan names, page context, preferences
Content Security Policy
If your page sets a Content Security Policy, allow the widget frame and script:Troubleshooting
Widget Not Receiving Metadata
Widget Not Receiving Metadata
- Call
sendMetadataToAGOafter the widget script has loaded, or pass the first value inwindow.AGO.metadata - Check browser console for errors
- Verify
sendMetadataToAGOis available globally (it is defined byframe.js)
Messages Not Being Received
Messages Not Being Received
- Check origin validation in your event listener
- Check that
basepathpoints to your workspace - Check browser console for blocked cross-origin messages
Metadata Not Appearing in Tickets
Metadata Not Appearing in Tickets
- Verify metadata was sent before ticket creation
- Check that metadata format is valid JSON
- Check that the fields are mapped in Metadata Fields Mapping
Related
- Widget Authentication - Configure widget security
- Widget Configuration - Widget appearance and behavior
- Ticketing Tool - Ticket creation from conversations
- Mobile Authentication - Native app authentication
