Detect if AiBrow is installed

AiBrow has two components, the browser extension and the helper binary. Users will need both installed to use a model. After the browser extension is installed, users are prompted to continue the installation and download the helper binary, but you should still be prepared to handle cases where this has not been completed. AiBrow provides some helper utilities to check the current installation state and direct users to download the helper binary when needed.

Take a look at Helping users install AiBrow for tips on a seamless install

Detection & installation from a webpage

You can detect if AiBrow is installed and help the user install the extension from your website

async function checkInstalled () {
  if (!window.aibrow) {
    // The extension is not installed
    console.log(`Install the extension from https://aibrow.ai/install?redirect_to=${window.location.href}`)
    return false
  }
  
  const capabilities = await window.aibrow.capabilities()
  if (!capabilities.helper) {
    // The helper binary is not installed. We can fetch the direct link to the latest
    // version for the current platform
    const helperUrl = await window.aibrow.getHelperDownloadUrl()
    console.log(`Install the helper from ${helperUrl} or https://aibrow.ai/install?redirect_to=${window.location.href}`)
    return false
  }
  
  // We're all installed
  return true
}

checkInstalled()

Detection & installation from an extension

Your extension should pre-bundle the AiBrow library, but it still needs the AiBrow extension and native helper installed. You can help users install from your extension.

import aibrow from '@aibrow/extension'

async function checkInstalled () {  
  const capabilities = await aibrow.capabilities()
  if (!capabilities.extension) {
    // The extension is not installed
    console.log('Install the extension from https://chromewebstore.google.com/detail/aibrow/bbkbjiehfkggfkbampigbbakecijicdm')
    return false
  }
  if (!capabilities.helper) {
    // The helper binary is not installed. We can fetch the direct link to the latest
    // version for the current platform
    const helperUrl = await aibrow.getHelperDownloadUrl()
    console.log(`Install the helper from ${helperUrl}`)
    return false
  }
  
  // We're all installed
  return true
}

checkInstalled()

Detect if AiBrow is polyfilling window.ai

If window.ai is not available in the current browser, AiBrow will automatically polyfill the API. You can detect if this has happened

if (window.ai && window.ai.aibrow === true) {
  // AiBrow is polyfilling the window.AI API
  console.log('You\'re all set to go!')
}

Last updated