Skip to content

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:

MethodDescription
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():

MemberTypeDescription
widget.open()() => voidOpen the panel.
widget.close()() => voidClose the panel.
widget.logout()() => voidReturn to visitor mode.
widget.destroy()() => voidRemove the widget from the DOM entirely.
widget.host / .shadow / .rootHTMLElement / ShadowRootAdvanced DOM access.

TIP

See the Authentication page for details on member login (getToken).

Webfon live-support widget documentation