Documentation
JavaScript API
Programmatically control the widget after it loads.
Available methods
BXLivechat.open()
Open the chat window programmatically.
// Open the chat window
BXLivechat.open();BXLivechat.close()
Close the chat window.
// Close the chat window
BXLivechat.close();BXLivechat.toggle()
Toggle the chat window between open and closed states.
// Toggle the chat window open or closed
BXLivechat.toggle();BXLivechat.identify(visitor)
Identify the current visitor. This updates the visitor profile visible to agents and can pre-fill the pre-chat form.
| Parameter | Type | Description |
|---|---|---|
name | string | Visitor display name. |
email | string | Visitor email address. |
phone | string | Visitor phone number. |
avatar | string | URL to the visitor’s avatar image. |
BXLivechat.identify({
name: "Jane Doe",
email: "[email protected]",
phone: "+1-555-0100",
avatar: "https://example.com/jane.jpg",
});BXLivechat.setCustomData(data)
Attach arbitrary key-value data to the visitor session. Agents see this data in the chat sidebar.
BXLivechat.setCustomData({
plan: "enterprise",
accountId: "acct_8xk29z",
trialEnds: "2026-06-01",
});BXLivechat.sendMessage(text)
Send a message on behalf of the visitor. Useful for triggering conversations from CTAs or support links.
// Send a message as the visitor
BXLivechat.sendMessage("Hi, I need help with billing.");BXLivechat.destroy()
Completely remove the widget from the page, including its iframe and event listeners.
// Remove the widget from the page entirely
BXLivechat.destroy();Event listeners
Subscribe to widget lifecycle events with BXLivechat.on(event, callback).
ready— fired when the widget has finished loading and is ready for API calls.open— fired when the chat window is opened.close— fired when the chat window is closed.message— fired when a new message is received. Callback receives{ text, sender }.
events.js
BXLivechat.on("ready", () => {
console.log("Widget loaded");
});
BXLivechat.on("open", () => {
console.log("Chat window opened");
});
BXLivechat.on("close", () => {
console.log("Chat window closed");
});
BXLivechat.on("message", (data) => {
console.log("New message:", data.text, "from", data.sender);
});Wait for ready
Always wrap API calls in
BXLivechat.on('ready', ...) to ensure the widget has finished loading before you interact with it.