SapanBaseDevelopers

The widget JavaScript API: events, open state & clearUser

Control and react to the widget programmatically: listen for events, check whether it's open, and clear the identified user.

Beyond the basic embed, widget.js exposes a small JavaScript API for controlling and reacting to the widget from your own code.

Events

Subscribe with on() (and remove a listener with off()) to react to open, close, message, error, and ready events — useful for, say, firing your own analytics event when a visitor opens the widget.

Check open state

isOpen() tells you whether the widget is currently open, if your own UI needs to react to that.

Clear the identified user

Call clearUser() when a user logs out of your site, so the widget stops associating the session with them.

Mobile-friendly by default

The widget respects safe-area insets automatically, so it renders correctly around notches and home indicators in a mobile WebView without extra configuration.