Theme
Method Reference
The methods you can use to control the widget — listed separately for the CDN (the global window.Webfon) and npm (named exports / the instance).
Global window.Webfon (CDN)
Defined automatically once the CDN bundle loads:
| Method | Description |
|---|---|
Webfon.init(config) | Mounts the widget manually (instead of automatic mounting). |
Webfon.open() | Opens the panel. |
Webfon.close() | Closes the panel (minimizes it). |
Webfon.logout() | Returns to visitor mode and clears the token cache. |
Webfon.onEvent(event, handler) | Subscribes to an event; returns a function that unsubscribes. |
Webfon.offEvent(event, handler) | Unsubscribes. |
js
window.Webfon.open();
window.Webfon.logout();
const off = window.Webfon.onEvent('message', (m) => console.log('new message', m));
off();TIP
You can find which events are emitted and their payloads on the Events page.
npm named exports
js
import {
initWebfon, // same as the default export; returns an instance
destroyWidget, // removes the active widget
toggleApp, // open/close the panel: toggleApp(true) / toggleApp(false)
onEvent, // subscribe to an event
offEvent, // unsubscribe
logout, // return to visitor mode
} from '@webfon/client';Instance methods
The object returned by initWebfon() / Webfon.init():
| Member | Type | Description |
|---|---|---|
widget.open() | () => void | Open the panel. |
widget.close() | () => void | Close the panel. |
widget.logout() | () => void | Return to visitor mode. |
widget.destroy() | () => void | Remove the widget from the DOM entirely. |
widget.host / .shadow / .root | HTMLElement / ShadowRoot | Advanced DOM access. |
TIP
See the Authentication page for details on member login (getToken).