JavaScript API
The script exposes a single global, PeriscaleChat, with two methods.
PeriscaleChat.init(config)
Mounts the widget on the page. Calling it twice is a no-op (a warning is logged).
js
PeriscaleChat.init({
apiKey: "sb_live_xxx",
primaryColor: "#20808D",
});See Configuration for all options.
PeriscaleChat.destroy()
Removes the widget from the page. Useful when you need to swap configuration or hide the widget on certain routes.
js
PeriscaleChat.destroy();
PeriscaleChat.init({ apiKey: "sb_live_xxx", agentName: "Sales" });SPA route changes
The widget mounts to a fixed shadow root and persists across in-app route changes. You typically only need to call init() once, on first paint.
If you need to hide the widget on a specific route, use CSS on the host element:
css
#periscale-chat-widget { display: none; }…or call destroy() when entering the route and init() when leaving.