Context API

The plugin SDK exposes an API to interact with Front.
Because the interactions are depending on the current context, the API is defined on the context received via Front.contextUpdates.

While it is recommended to use the functions from the context, you can also call the functions directly on the main Front object.

📘

When calling an API function on Front, the latest context will be used.

const button = document.getElementById('example-button');

/*
 * Bad.
 */
let latestContext;
Front.contextUpdates.subscribe(context => {
  latestContext = context;
});
button.addEventListener('click', () => {
  if (!latestContext)
    throw new Error('Cannot process before receiving a context');

  latestContext.openUrl('https://example.com');
}

/*
 * Good.
 */
button.addEventListener('click', () => Front.openUrl('https://example.com'));