JavaScript API Overview
Control the UserBoost widget programmatically
The UserBoost widget exposes a JavaScript API on window.UserBoost for programmatic control.
Availability
The API is available after the widget script loads. Since the script loads asynchronously, wrap calls in a check:
// Wait for the widget to be ready
if (window.UserBoost) {
window.UserBoost.open();
}
Or use the script's onload callback:
<script
src="https://userboost.ai/widget.js"
data-cid="YOUR_DOMAIN_ID"
async
onload="UserBoost.open()"
></script>
Methods
| Method | Description |
|---|---|
open() | Open the chat panel |
close() | Close the chat panel |
toggle() | Toggle the chat panel open/closed |
sendMessage(text) | Send a message programmatically |
setVisibility(visible) | Show or hide the entire widget |
createPopup(config) | Show a popup message above the launcher |
on(event, callback) | Listen for widget events |
off(event, callback) | Remove an event listener |
destroy() | Remove the widget from the page |
See Methods for detailed documentation of each method.