← Back to Docs

Chrome Extension Starter

Manifest V3 boilerplate with a background service worker that authenticates against the Meridian API.

manifest.json

{
  "manifest_version": 3,
  "name": "Meridian Starter",
  "version": "1.0.0",
  "background": {
    "service_worker": "background.js"
  },
  "host_permissions": [
    "https://api.getnimbus.net/*"
  ],
  "permissions": ["storage"]
}

background.js

chrome.runtime.onInstalled.addListener(() => {
  chrome.storage.local.set({ token: null });
});

async function authenticate() {
  const res = await fetch(
    "https://api.getnimbus.net/v1/auth/chrome",
    {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        extension_id: chrome.runtime.id
      })
    }
  );
  const { token } = await res.json();
  await chrome.storage.local.set({ token });
  return token;
}

chrome.runtime.onMessage.addListener(
  (msg, sender, sendResponse) => {
    if (msg.type === "AUTH") {
      authenticate().then(sendResponse);
      return true;
    }
  }
);

Next Steps

  • 1.Load the unpacked extension at chrome://extensions
  • 2.Add a popup that requests the AUTH message on mount.
  • 3.Attach the token to all Meridian API calls via Authorization: Bearer