Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(toolbar): meet store requirements in the extension manifest (#125152)

Rafael Audibert3da3d14d4404
diff --git a/frontend/public/icons/posthog-128x128.png b/frontend/public/icons/posthog-128x128.png
new file mode 100644
index 000000000000..570534952d4e
Binary files /dev/null and b/frontend/public/icons/posthog-128x128.png differ
diff --git a/frontend/src/toolbar/extension/README.md b/frontend/src/toolbar/extension/README.md
index a77a8817348c..7c3c532c163f 100644
--- a/frontend/src/toolbar/extension/README.md
+++ b/frontend/src/toolbar/extension/README.md
@@ -28,7 +28,7 @@ Download the `toolbar-extension` artifact from the run to install that build wit
After a rebuild, click the reload icon on the extension card, then close and open the side panel.
-### Firefox (128 or later)
+### Firefox (140 or later)
1. Open `about:debugging#/runtime/this-firefox`.
2. Click **Load Temporary Add-on** and select `frontend/dist/toolbar-extension/firefox/manifest.json`, or the Firefox zip from the artifact.
@@ -54,6 +54,23 @@ Both browsers let the user take site access back from an extension.
When the extension can't reach the PostHog host, the panel asks for access to it.
When it can't reach the site, the panel asks the user to reload the page and try again.
+## Data collection
+
+Firefox shows the extension's data collection at install, from `data_collection_permissions` in the Firefox manifest (`buildToolbarExtensionManifest` in `frontend/toolbar-config.mjs`).
+The Chrome Web Store asks for the same facts in the item's privacy tab.
+Update both when the extension starts to send new data.
+
+| Category | What the extension sends | Where |
+| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
+| `authenticationInfo` (required) | The PostHog session cookie, and the OAuth code, PKCE verifier and access and refresh tokens of the toolbar sign-in. | The user's PostHog host |
+| `browsingActivity` (required) | The active tab's URL, when the panel connects the toolbar to a project and when it loads heatmap and web vitals data for the page. | The user's PostHog host |
+| `websiteContent` (required) | Element selectors and text in a saved action, variant HTML in a saved experiment, and page screenshots in a saved heatmap or event screenshot. | The user's PostHog host |
+| `technicalAndInteraction` (optional) | Usage events from the panel, such as the tools the user opens, with the user's PostHog distinct ID. | PostHog's usage analytics |
+
+The panel sends usage events only when the user allows `technicalAndInteraction`.
+Firefox lets the user change this in the add-on's settings, and the panel applies the change right away.
+The content script never sends usage events or logs, because it mounts the toolbar without `instrument`.
+
## How the page tools work
The page tools run the floating toolbar's own logics in the content script, and draw its overlays in the content script's shadow root:
diff --git a/frontend/src/toolbar/extension/browser/extensionBrowser.ts b/frontend/src/toolbar/extension/browser/extensionBrowser.ts
index 1d3db2e59c03..bbac3bb7b035 100644
--- a/frontend/src/toolbar/extension/browser/extensionBrowser.ts
+++ b/frontend/src/toolbar/extension/browser/extensionBrowser.ts
@@ -86,6 +86,10 @@ interface ExtensionBrowserApi {
permissions: {
contains: (permissions: ExtensionPermissions) => Promise<boolean>
request: (permissions: ExtensionPermissions) => Promise<boolean>
+ // Firefox adds `data_collection`, and Chrome leaves it out.
+ getAll: () => Promise<ExtensionPermissions & { data_collection?: string[] }>
+ onAdded: ExtensionEvent<() => void>
+ onRemoved: ExtensionEvent<() => void>
}
action: {
onClicked: ExtensionEvent<() => void>
@@ -183,6 +187,26 @@ export async function requestHostPermission(url: string): Promise<boolean> {
return await extensionBrowser.permissions.request(originPattern(url))
}
+/**
+ * Firefox asks the user at install whether the extension may send usage data, from the manifest's
+ * `data_collection_permissions`. Chrome has no such choice, so usage data is allowed there.
+ */
+export async function canSendUsageData(): Promise<boolean> {
+ const { data_collection } = await extensionBrowser.permissions.getAll()
+ // pinned: Firefox data collection category, the manifest declares the same key
+ return !data_collection || data_collection.includes('technicalAndInteraction')
+}
+
+/** Firefox fires these when the user changes the data collection choice in the add-on's settings. */
+export function onPermissionsChange(handler: () => void): () => void {
+ extensionBrowser.permissions.onAdded.addListener(handler)
+ extensionBrowser.permissions.onRemoved.addListener(handler)
+ return () => {
+ extensionBrowser.permissions.onAdded.removeListener(handler)
+ extensionBrowser.permissions.onRemoved.removeListener(handler)
+ }
+}
+
// pinned: extension message, the panel and an already injected content script must agree on it
const CONTENT_SCRIPT_PING = 'posthog-toolbar-extension-ping'
diff --git a/frontend/src/toolbar/extension/components/panel/__mocks__/fakeExtensionBrowser.ts b/frontend/src/toolbar/extension/components/panel/__mocks__/fakeExtensionBrowser.ts
index dc5cd550ee41..81452384eb36 100644
--- a/frontend/src/toolbar/extension/components/panel/__mocks__/fakeExtensionBrowser.ts
+++ b/frontend/src/toolbar/extension/components/panel/__mocks__/fakeExtensionBrowser.ts
@@ -63,6 +63,12 @@ function fakePort(): ExtensionPort {
},
scripting: { executeScript: async () => [{}] },
runtime: { onMessage: fakeEvent(), onConnect: fakeEvent(), getURL: (path: string) => `/${path}` },
- permissions: { contains: async () => true, request: async () => true },
+ permissions: {
+ contains: async () => true,
+ request: async () => true,
+ getAll: async () => ({ origins: [] }),
+ onAdded: fakeEvent(),
+ onRemoved: fakeEvent(),
+ },
action: { onClicked: fakeEvent() },
}
diff --git a/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.ts b/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.ts
index 20c4233ec8e3..c85331546464 100644
--- a/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.ts
+++ b/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.ts
@@ -14,10 +14,12 @@ import { toolbarPosthogJS } from '~/toolbar/shared/toolbarPosthogJS'
import { joinWithUiHost, safeFetch } from '~/toolbar/shared/utils'
import {
+ canSendUsageData,
getActiveTab,
getStoredUiHost,
hasHostPermission,
onActiveTabChange,
+ onPermissionsChange,
openTab,
requestHostPermission,
setStoredUiHost,
@@ -55,6 +57,15 @@ const OPEN_SETTINGS_IN: ExtensionPanelState['kind'][] = [
'error',
]
+async function syncUsageDataConsent(): Promise<void> {
+ // posthog-js keeps an earlier opt-in in localStorage, so a revoked choice needs an explicit opt-out.
+ if (await canSendUsageData()) {
+ toolbarPosthogJS.opt_in_capturing()
+ } else {
+ toolbarPosthogJS.opt_out_capturing()
+ }
+}
+
/** Sends the PostHog session cookie, like the toolbar's own entitlements request. */
async function fetchWithSession(uiHost: string, path: string): Promise<{ status: number; data: unknown }> {
return await readResponse(
@@ -468,7 +479,11 @@ export const extensionPanelLogic = kea<extensionPanelLogicType>([
},
})),
afterMount(({ actions, cache }) => {
- toolbarPosthogJS.opt_in_capturing()
+ // Setup runs again when the panel shows after it was hidden, so it reads the choice again then too.
+ cache.disposables.add(() => {
+ void syncUsageDataConsent()
+ return onPermissionsChange(() => void syncUsageDataConsent())
+ }, 'usageDataConsent')
void getStoredUiHost().then((stored) => actions.setUiHost(canonicalizeUiHost(stored) ?? DEFAULT_UI_HOST))
void getActiveTab().then(
(tab) => actions.setTab(tab?.id ?? null, tab?.url ?? null),
diff --git a/frontend/toolbar-config.mjs b/frontend/toolbar-config.mjs
index c78d43279793..cccb23caed9b 100644
--- a/frontend/toolbar-config.mjs
+++ b/frontend/toolbar-config.mjs
@@ -264,6 +264,7 @@ const TOOLBAR_EXTENSION_BUILD_DIR = 'toolbar-extension-build'
const TOOLBAR_EXTENSION_ICONS = {
16: 'icons/favicon-16x16.png',
32: 'icons/favicon-32x32.png',
+ 128: 'icons/posthog-128x128.png',
192: 'icons/android-chrome-192x192.png',
}
@@ -363,9 +364,19 @@ function buildToolbarExtensionManifest(browser) {
default_icon: TOOLBAR_EXTENSION_ICONS,
open_at_install: false,
}
- // Firefox needs an add-on ID for MV3 storage, and 128 is the first release that grants Manifest V3 host
- // permissions at install.
- manifest.browser_specific_settings = { gecko: { id: '[email protected]', strict_min_version: '128.0' } }
+ // Firefox needs an add-on ID for MV3 storage, and addons.mozilla.org never lets the ID change after the first
+ // upload. 140 is the first release that asks the user at install for the data collection declared here.
+ manifest.browser_specific_settings = {
+ gecko: {
+ strict_min_version: '140.0',
+ // Keep in sync with the "Data collection" section of src/toolbar/extension/README.md.
+ data_collection_permissions: {
+ required: ['authenticationInfo', 'browsingActivity', 'websiteContent'],
+ optional: ['technicalAndInteraction'],
+ },
+ },
+ }
// Firefox runs Manifest V3 background code as an event page, not as a service worker.
manifest.background = { scripts: ['background.js'] }
} else {