Skip to main content
The widget script (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 the window.AGO object before loading the widget script. These options control authentication, appearance, and behavior.

Panel size

The chat panel is 550px wide by default. Set panelWidth 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:
Precedence: #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

Use sendJwtToAGO() 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.
Unread counts are then checked with the new identity too.

Updating Auth Token at Runtime

Use sendAuthTokenToAGO() 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 the sendMetadataToAGO function to pass context from your application to the widget.
Metadata is a free-form JSON object: choose the field names that fit your application. To show a field to your support team, map it in Support → Settings → Your channels → Widget & SDK → Metadata Fields Mapping.

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:
Good to know:
  • 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. Check event.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 with notifications: true:
The widget then shows a red badge on the chat button. To show the count elsewhere on your page, listen for the event:
If you use JWT authentication, call sendJwtToAGO(token) whenever the token is refreshed so unread counts are checked for the signed-in user.

Complete Example

Set window.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

  1. Call sendMetadataToAGO after the widget script has loaded, or pass the first value in window.AGO.metadata
  2. Check browser console for errors
  3. Verify sendMetadataToAGO is available globally (it is defined by frame.js)
  1. Check origin validation in your event listener
  2. Check that basepath points to your workspace
  3. Check browser console for blocked cross-origin messages
  1. Verify metadata was sent before ticket creation
  2. Check that metadata format is valid JSON
  3. Check that the fields are mapped in Metadata Fields Mapping