Browser Extension
This package contains functions for interacting with the Salesloft browser extension.
Extension Status
Send a Request to Check Installed Status
We can send an asynchronous request to check if the extension is installed.
import { sendIsInstalledRequest } from '@shared/browser-extension'
async function asyncCheck() {
const isInstalled = await sendIsInstalledRequest()
console.log(`Is the extension installed? ${isInstalled ? 'Yes' : 'No'}`)
}
Checking the Extension Installed Status
You can do a synchronous check to see if the extension is currently installed. This function should be used after a call to sendIsInstalledRequest has completed.
import { checkIsInstalled } from '@shared/browser-extension'
function syncCheck() {
const isInstalled = checkIsInstalled()
console.log(`Is the extension installed? ${isInstalled ? 'Yes' : 'No'}`)
}
Extension Communication
Broadcasting a Message
We can broadcast a message to the extension. This function is safe to call even if the extension isn't installed.
import { broadcastMessage } from '@shared/browser-extension'
function broadcastCallStarted(callSid: string) {
broadcastMessage('callStarted', { callSid })
}
Adding an Event Listener
We can listen to events broadcast from the extension. This function is safe to call even if the extension isn't installed.
import { addEventListener } from '@shared/browser-extension'
addEventListener('impersonationStarted', () => {
console.log('Impersonation has begun!')
})
Opening the Extension's Store Page
There are times when we need to direct the user to the Chrome web store page for the extension. We can use openWebStorePage to do so.
import { openWebStorePage } from '@shared/browser-extension'
function WebStoreOpener() {
return <button onClick={() => openWebStorePage()}>Go to extension</button>
}