> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Using PostHog for browser extensions Canonical URL: https://posthog.com/docs/advanced/browser-extension > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.i.posthog.com` instead of `https://us.i.posthog.com` (ingestion host). ## On this page - [Setup for Chrome, Safari & Firefox extensions](#setup-for-chrome-safari--firefox-extensions) - [Manifest v3 compatibility](#manifest-v3-compatibility) - [Persistence in browser extensions](#persistence-in-browser-extensions) - [PostHog usage across extension contexts](#posthog-usage-across-extension-contexts) - [Using product analytics](#using-product-analytics) - [Using error tracking](#using-error-tracking) - [Debugging](#debugging) Do you have a Firefox, Safari, or Chrome browser extension and want to understand how it's being used? PostHog is the perfect way to do just that. ## Setup for Chrome, Safari & Firefox extensions **Extension APIs namespace** Browsers expose web extension APIs using different global variables, namely `browser` and/or `chrome`. There are slight [differences in implementations](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Differences_between_API_implementations) but the APIs we're using here are cross-browser compatible. We're going to use `chrome` namespace throughout this guide due to wider support, but you can substitute it with `browser` for platforms that support it. Start by installing the PostHog [JavaScript web SDK](https://posthog.com/docs/libraries/js.md). ### npm ```bash npm install --save posthog-js@1 ``` ### Yarn ```bash yarn add posthog-js@1 ``` ### pnpm ```bash pnpm add posthog-js@1 ``` ### Bun ```bash bun add posthog-js@1 ``` > **If your site sets a Content-Security-Policy**, it needs to allow PostHog. This applies to the snippet and to package installs alike: the SDK lazy-loads extra bundles (session replay, surveys) from PostHog's CDN, and sends events to the ingestion host. PostHog serves from subdomains of `posthog.com` that change over time, so allow the wildcard: > > ``` > script-src 'self' https://*.posthog.com; > connect-src 'self' https://*.posthog.com; > worker-src 'self' blob: data:; > ``` > > `script-src` covers the snippet and the lazy-loaded bundles, `connect-src` covers event ingestion and feature flags, and `worker-src` covers session replay. The [toolbar needs a few more](https://posthog.com/docs/advanced/content-security-policy.md), or use a [reverse proxy](https://posthog.com/docs/advanced/proxy.md) so everything is first-party. Failing to do so causes silent failures where `capture` and `identify` calls never send, so the integration looks complete while zero events arrive. Remember `connect-src` falls back to `default-src`, so `default-src 'self'` blocks event delivery even when the script itself is bundled. **Bundling** Browser extensions can block your imports. If your extension throws errors when trying to import PostHog, use a bundler like [Rollup](https://rollupjs.org/) to bundle your JavaScript and import it in a single `