Widget API
The Webfuse Widget is a small script module you can embed into any website with a few lines of copy-and-paste code. It works much like a Google Analytics tag. You only have to specify your own Widget Key, which you can generate in the Webfuse Studio application. Through the Widget, you can turn the usual website into the Webfuse-proxied counterpart only if needed. For example, if a user requires assistance after experiencing UI/UX friction.
Widget Button
Section titled “Widget Button”The Widget API allows you to optionally render a Start Session button on top of the underlying website UI. When a user click this button, your website is loaded though the Wefbuse web proxy to, i.a, augment the page, collaborate on the page, or increase security measures.
Widget API
Section titled “Widget API”The Widget API is a JavaScript API that becomes available in the window scope of the underlying website. The key functionality is: rendering the Widget Button to create a Session on click, or otherwise creating a Session programmatically.
Widget Snippet
Section titled “Widget Snippet”To get the widget code with the correct Widget Key and Space ID, Navigate to your space and click on the Share tab. There you will find the widget API snippet you can copy and paste.
Add the widget code to relevant page;s of your web application (ideally within <HEAD>). It will load the Widget API under the globally available webfuse namespace.
The global webfuse object is the entry point for the Webfuse API. It provides methods to initialize and interact with Webfuse Spaces.
isInsideSession
Section titled “isInsideSession”Returns true if the current page is loaded within a Session. This makes it possible to change the page behavior while the page is being augmented. For example, if you have a web application and you want it to display different content when it is run within a Session you can check this property and change the behavior accordingly.
webfuse.isInsideSession: booleanExample
Section titled “Example”if (webfuse.isInsideSession) { console.log('This page is running inside a Webfuse Session');}currentSession
Section titled “currentSession”Inside a Virtual Web Session, this returns a WebfuseSession object referring to the current Session. Otherwise, it returns null. It allows you to detect whether the current page is loaded under Webfuse, and also use the WebfuseSession API for communication.
webfuse.currentSessionExample
Section titled “Example”if (webfuse.isInsideSession) { webfuse.currentSession.on('message', function (session, event) { (event.origin === window.location.origin) ? console.log('outer window says:', event.data) : console.log("outer window has a different origin"); });}initSpace()
Section titled “initSpace()”Initializes a Space with the provided widget key and Space ID. This method must be called before any other API operations.
webfuse.initSpace( widgetKey: string, spaceId: string, integrationSettings?: IntegrationSettings)Parameters
Section titled “Parameters”widgetKey
- Your Webfuse widget key.
spaceId
- The ID of your Webfuse space.
integrationSettings
Returns
Section titled “Returns”A promise that resolves with a Space object when initialization is complete.
Example
Section titled “Example”webfuse.initSpace( '**your widget key here**', '**your space id here**', { block_until_agent_joins: true, metadata: { foo: 'bar' } }).then(space => { console.log('Space initialized:', space.id);}).catch(error => { console.error('Failed to initialize space:', error);});listSessions()
Section titled “listSessions()”Get a list of webfuse Session objects that were created, or restored after the page reload. Inside a Session, the returned array will contain only one object, representing the currently open Session.
webfuse.listSessions(): object[]Returns
Section titled “Returns”A Session object.
Example
Section titled “Example”webfuse.listSessions() .forEach(function(session) { console.log('Found a Session:', session.sessionLink); });Defines a global event handler. If eventName is a Session Event, the handler will affect all Sessions, including the currently created ones.
webfuse.on(eventName: string, callback: (...data: unknown[]) => void)Parameters
Section titled “Parameters”eventName
- Name of a Session Event.
callback
- A function to invoke when the event fires. Depending on the type of event, it will be provided with relevant data.
See Events section for more details.
Returns
Section titled “Returns”A reference to the webfuse object, so chained calls are possible:
Example
Section titled “Example”webfuse .on(/*...*/) .on(/*...*/);// Initialize Webfuse space and create a Session with event listenerswebfuse .initSpace('**your widget key here**', '**your space id here**') .then(async space => { const session = space.session();
// Add event listeners session.on('session_started', session => { console.log('Session has started'); });
session.on('participant_joined', (session, event) => { console.log('A participant joined with client index:', event.clientIndex); });
session.on('session_ended', session => { console.log('Session has ended'); });
// Start the Session await session.start(); }).catch(error => { console.error('Failed to initialize or start Session:', error); });Space Object
Section titled “Space Object”The Space object is returned by webfuse.initSpace() and provides methods for creating Sessions and buttons within that space.
const space = await webfuse .initSpace('**your Widget Key here**', '**your Space IDd here**');Get the space ID.
space.id: stringGet the space slug.
space.slug: stringbutton()
Section titled “button()”Adds a Webfuse button to the current page. When a user clicks the Webfuse Button, it will create a new Session and will render this in a maximized iFrame on the current page, effectively starting the Session.
space.button(buttonSettings?: { position?: "topleft" | "topright" | "bottomleft" | "bottomright";}): objectParameters
Section titled “Parameters”buttonSettings
- Settings that will be applied to the button and Sessions created with it.
Returns
Section titled “Returns”A webfuse button object.
Example
Section titled “Example”space.button({ position: 'bottomleft'});session()
Section titled “session()”space.session(options?:object, link?: string, sessionId?: string): objectCreates a Session object with the provided settings. You can bind callbacks using .on() method to hook on specific events fired during the Session lifetime.
Parameters
Section titled “Parameters”options
- Session settings object.
link - URL string with leader or follower Session Link.
sessionId - Existing Session ID to restore.
Returns
Section titled “Returns”A Eebfuse Session object.
Example
Section titled “Example”// Create a new Sessionconst session = space.session({block_until_agent_joins: true});
// Start the Sessionconst response = await session.start();console.log('Session started:', response);Session Object
Section titled “Session Object”The session object is returned by space.session() and represents a single Session.
const space = await webfuse .initSpace('**your widget key here**', '**your space id here**');const session = space.session();sessionLink
Section titled “sessionLink”Returns the URL that can be used to join the Session. This property is available after calling session.create() or session.start().
session.sessionLink: stringExample
Section titled “Example”const session = space.session();const result = await session.create();console.log('Session link:', session.sessionLink);// Or from the create() result:console.log('Session link:', result.sessionLink);start()
Section titled “start()”Starts the Session. If a selector is provided, the Session will be embedded in the element matching that selector.
session.start(selector?: string): Promise<void>Parameters
Section titled “Parameters”selector
- CSS selector for the element to embed the Session in.
Returns
Section titled “Returns”A promise that resolves with the Session object when the Session is started.
Example
Section titled “Example”const response = await session.start();Use the Session API
Section titled “Use the Session API”You can use all the Session methods available on the Session object.
// Get the recently created Sessionconst session = webfuse.listSessions()[0];
// Open new tabssession.openTab('https://www.example.com');session.openTab('https://www.another-example.com');
// Get all open tabsconst tabs = session.getTabs();console.log('Open tabs:', tabs);Listen for Session Events
Section titled “Listen for Session Events”You can listen to various Session Events using the on method. This allows you to respond to different events that occur during a Session:
// Initialize Webfuse space and create a Session with event listenersconst space = await webfuse.initSpace('<WIDGET_KEY>', '<SPACE_ID>');const session = space.session();
// Add event listenerssession.on('session_started', session => { console.log('Session has started');});
session.on('participant_joined', (session, event) => { console.log('A participant joined with client index:', event.clientIndex);});
session.on('session_ended', session => { console.log('Session has ended');});
// Start the Sessionawait session.start();