: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
refactor(toolbar): build the extension for chrome only (#127542)
Rafael Audibert1e8e654b11ca
diff --git a/.agents/skills/building-the-toolbar/SKILL.md b/.agents/skills/building-the-toolbar/SKILL.mdindex 51137d664e5a..768fe58b8f26 100644--- a/.agents/skills/building-the-toolbar/SKILL.md+++ b/.agents/skills/building-the-toolbar/SKILL.md@@ -1,6 +1,6 @@---name: building-the-toolbar-description: Builds, watches, checks and verifies the PostHog toolbar in both of its forms, the floating toolbar that posthog-js loads on customer pages and the browser extension that shows the toolbar in a Chrome side panel or Firefox sidebar. Use when changing anything under frontend/src/toolbar/ (floating toolbar or extension), frontend/toolbar-config.mjs, or the toolbar build and guard scripts, or when asked to build, watch, load unpacked, or test the toolbar or the toolbar extension in a browser. Covers `pnpm build:toolbar-all` and `pnpm watch:toolbar-all`, the check-toolbar-size, check-toolbar-graph and check-toolbar-csp-eval guards, why both forms must be built and kept in sync, and how to check each one in a real browser.+description: Builds, watches, checks and verifies the PostHog toolbar in both of its forms, the floating toolbar that posthog-js loads on customer pages and the browser extension that shows the toolbar in a Chrome side panel. Use when changing anything under frontend/src/toolbar/ (floating toolbar or extension), frontend/toolbar-config.mjs, or the toolbar build and guard scripts, or when asked to build, watch, load unpacked, or test the toolbar or the toolbar extension in a browser. Covers `pnpm build:toolbar-all` and `pnpm watch:toolbar-all`, the check-toolbar-size, check-toolbar-graph and check-toolbar-csp-eval guards, why both forms must be built and kept in sync, and how to check each one in a real browser.---# Building the toolbar@@ -8,10 +8,10 @@ description: Builds, watches, checks and verifies the PostHog toolbar in both ofOne source tree, `frontend/src/toolbar/`, ships in two forms.Both builds live in `frontend/toolbar-config.mjs` and share its toolbar module plugin, which swaps app modules for the toolbar's shims and keeps denylisted packages out.-| Form | Entry | Output (under `frontend/dist/`) | Runs in |-| ----------------- | ------------------------------------------------ | --------------------------------------------------- | ------------------------------------------------ |-| Floating toolbar | `src/toolbar/floating/index.tsx` | `toolbar.js` loader, `toolbar/` app chunks | Customer pages, loaded by posthog-js |-| Browser extension | `src/toolbar/extension/panel.tsx`, `content.tsx` | `toolbar-extension/<browser>/`, one zip per browser | Chrome side panel, Firefox sidebar (Manifest V3) |+| Form | Entry | Output (under `frontend/dist/`) | Runs in |+| ----------------- | ------------------------------------------------ | ----------------------------------------------------- | ------------------------------------ |+| Floating toolbar | `src/toolbar/floating/index.tsx` | `toolbar.js` loader, `toolbar/` app chunks | Customer pages, loaded by posthog-js |+| Browser extension | `src/toolbar/extension/panel.tsx`, `content.tsx` | `toolbar-extension/chrome/`, plus a zip for the store | Chrome side panel (Manifest V3) |## Where code goes@@ -91,10 +91,10 @@ pnpm typegen:write # then check that git diff shows no drift in logic typesTests and builds don't show a broken overlay, a missing style, or a CSP refusal. Load the build.-- **Extension.** Load `dist/toolbar-extension/chrome` unpacked in Chrome and `dist/toolbar-extension/firefox` as a temporary add-on in Firefox.+- **Extension.** Load `dist/toolbar-extension/chrome` unpacked in Chrome.The steps are in [the extension README](../../../frontend/src/toolbar/extension/README.md#build-and-install); read it before you load the extension the first time.After a rebuild, reload the extension, then close and open the panel.- Check both browsers when you change the extension, and walk the README's [manual checks](../../../frontend/src/toolbar/extension/README.md#check-the-flows-by-hand) for the tools you touched.+ Walk the README's [manual checks](../../../frontend/src/toolbar/extension/README.md#check-the-flows-by-hand) for the tools you touched.- **Floating toolbar.** Start the dev stack (see `/run-posthog`), open the Toolbar page at `http://localhost:8010/toolbar`, add a test site that loads posthog-js to the authorized URLs, and launch the toolbar on it.`Toolbar.stories.tsx` renders the floating toolbar in Storybook when you only need to look at a component.diff --git a/.github/workflows/ci-toolbar-extension.yml b/.github/workflows/ci-toolbar-extension.ymlindex 482ef430fdc4..e515a91b5157 100644--- a/.github/workflows/ci-toolbar-extension.yml+++ b/.github/workflows/ci-toolbar-extension.yml@@ -1,7 +1,7 @@name: Toolbar extension-# Builds the toolbar browser extension and uploads the Chrome and Firefox zips as a run artifact, so a reviewer can-# install the build from a PR. The workflow never publishes to a browser store.+# Builds the toolbar browser extension and uploads the Chrome zip as a run artifact, so a reviewer can install the+# build from a PR. The workflow never publishes to the Chrome Web Store.on:pull_request:diff --git a/frontend/src/toolbar/extension/README.md b/frontend/src/toolbar/extension/README.mdindex 12ab87f2c02e..0699ed7aeea4 100644--- a/frontend/src/toolbar/extension/README.md+++ b/frontend/src/toolbar/extension/README.md@@ -1,42 +1,31 @@# Toolbar browser extensionThe extension gives the toolbar tools to a page without the floating toolbar.-It opens from the extension button as a side panel in Chrome and as a sidebar in Firefox, and shows `panel.html`.+It opens from the extension button as a side panel in Chrome, and shows `panel.html`.The panel follows the active tab of its window.## Build and install-Build both browser folders from `frontend/`:+Build it from `frontend/`:```shpnpm build:toolbar-extension # one buildpnpm watch:toolbar-extension # rebuild on change```-The build writes `dist/toolbar-extension/chrome/` and `dist/toolbar-extension/firefox/`.-Only `manifest.json` is different between them.-It also zips each folder into `dist/toolbar-extension/posthog-toolbar-<browser>-<version>.zip`.+The build writes `dist/toolbar-extension/chrome/`, and zips it into `dist/toolbar-extension/posthog-toolbar-chrome-<version>.zip` for the Chrome Web Store.A pull request that changes the extension runs the "Toolbar extension" workflow.Download the `toolbar-extension` artifact from the run to install that build without building it yourself.-### Chrome (116 or later)+The extension needs Chrome 116 or later.1. Open `chrome://extensions` and turn on **Developer mode**.-2. Click **Load unpacked** and select `frontend/dist/toolbar-extension/chrome`, or the unzipped Chrome folder from the artifact.+2. Click **Load unpacked** and select `frontend/dist/toolbar-extension/chrome`, or the unzipped folder from the artifact.3. Pin the extension, then click its button to open the side panel.After a rebuild, click the reload icon on the extension card, then close and open the side panel.-### 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.-3. Click the extension button to open the sidebar.--Firefox removes a temporary add-on when it quits.-A permanent install needs an add-on signed by addons.mozilla.org.-## Permissions| Permission | Why |@@ -44,31 +33,28 @@ A permanent install needs an add-on signed by addons.mozilla.org.| `http://*/*`, `https://*/*` | The side panel reads the URL of the active tab and runs scripts in it when the user switches tabs. The same grant calls the PostHog API with your PostHog login, on Cloud and on a self-hosted host. || `scripting` | Injects the content script, and reads the page's posthog-js settings in the page's world. || `storage` | Saves the PostHog host and the toolbar's OAuth tokens for each project. |-| `sidePanel` (Chrome) | Shows the side panel. |+| `sidePanel` | Shows the side panel. |The manifest also lists `content.css` and its fonts in `web_accessible_resources`, because the content script links them into its shadow root on the page.### Site access-Both browsers let the user take site access back from an extension.+Chrome lets 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.+The Chrome Web Store asks what data the extension sends, in the item's privacy tab.+Update the answers there 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 |+| Category | What the extension sends | Where |+| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |+| Authentication information | 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 |+| Web history | 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 |+| Website content | 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 |+| User activity | 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`.## Store listing images@@ -155,7 +141,7 @@ flowchart LR## Check the flows by hand-Use a site in the project's authorized URLs. Do these steps in Chrome and in Firefox.+Use a site in the project's authorized URLs.1. Open the panel on the site. The panel connects the toolbar to the project: a tab opens and closes by itself.2. Click the Inspect icon and hover an element. The panel shows its selector and actions. Click the element to keep it selected.@@ -173,3 +159,24 @@ Use a site in the project's authorized URLs. Do these steps in Chrome and in Fir14. Click **Experiments** and open an experiment. Open a variant: the page shows it. Edit its HTML: the page changes as you type. Close the variant, then go back: the page shows its original state.15. Create an experiment, pick an element for a transformation with **Select element**, edit it, and save it. Open a page whose snippet sets `disable_web_experiments`: **Experiments** shows a warning.16. Switch the browser to dark mode. The panel follows it.++## Future: Firefox++We might publish the extension on addons.mozilla.org (AMO) later. It is Chrome only for now, because AMO's review process blocks it:++- **Source upload.** AMO needs the source code of a bundled or minified add-on, as one archive of at most 200 MB.+ The whole repository is larger than that, so a release would need a trimmed archive that still builds the extension.+- **Identical rebuild.** AMO reviewers build the add-on from that archive and compare the result with the submitted file, and any difference fails the review.+ The extension build isn't reproducible across machines: the minified names in the shared chunks change with the absolute path of the source folder.+ A Firefox release has to be built from the source archive in a fixed folder, with instructions that pin the folder, Node and pnpm.++To bring Firefox back:++- [ ] Make the build output independent of the source folder path, or document a fixed build folder.+- [ ] Script a trimmed source archive under 200 MB, with build instructions, and check that it rebuilds the submitted zip byte for byte.+- [ ] Restore the Firefox manifest: `sidebar_action`, `background.scripts`, and `browser_specific_settings.gecko` with the add-on ID, `strict_min_version: '140.0'` and `data_collection_permissions`.+- [ ] Restore the `sidebarAction.toggle()` fallback in `openPanelFromToolbarButton`.+- [ ] Declare usage events as the optional `technicalAndInteraction` category, and send them only while the user allows it. Opt out again when the user revokes it.+- [ ] Add the Firefox folder and zip back to the build and the CI artifact.++`git log -S sidebar_action -- frontend/toolbar-config.mjs` finds the commits that had the Firefox build.diff --git a/frontend/src/toolbar/extension/browser/extensionBrowser.ts b/frontend/src/toolbar/extension/browser/extensionBrowser.tsindex bbac3bb7b035..1443b153b586 100644--- a/frontend/src/toolbar/extension/browser/extensionBrowser.ts+++ b/frontend/src/toolbar/extension/browser/extensionBrowser.ts@@ -1,6 +1,6 @@import { PAGE_TOOLBAR_PORT, PageToolbarTokens } from '../messaging/pageToolbarBridge'-// Firefox and Chrome both expose the promise-based `chrome.*` namespace to Manifest V3 extensions.+// Chrome exposes the promise-based `chrome.*` namespace to Manifest V3 extensions.// Only the calls the side panel, the background script and the content script make are typed here.interface ExtensionTab {id?: number@@ -86,23 +86,17 @@ 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>}- sidePanel?: {+ sidePanel: {setPanelBehavior: (behavior: { openPanelOnActionClick: boolean }) => Promise<void>}- sidebarAction?: {- toggle: () => Promise<void>- }}-// Firefox puts its own APIs, such as `sidebarAction`, only on `browser`.+// Stories and the store listing images install a fake extension API as `browser`, because every Chrome page already+// has a `chrome` object of its own.const extensionBrowser = ((globalThis as unknown as { browser?: ExtensionBrowserApi }).browser ??(globalThis as unknown as { chrome: ExtensionBrowserApi }).chrome) as ExtensionBrowserApi@@ -112,15 +106,7 @@ const UI_HOST_STORAGE_KEY = 'posthogUiHost'const CONTENT_SCRIPT_FILE = 'content.js'export function openPanelFromToolbarButton(): void {- if (extensionBrowser.sidePanel) {- void extensionBrowser.sidePanel.setPanelBehavior({ openPanelOnActionClick: true })- return- }- const sidebarAction = extensionBrowser.sidebarAction- if (sidebarAction) {- // Firefox opens a sidebar only from a user action, so the toggle must run in the click listener without an await.- extensionBrowser.action.onClicked.addListener(() => void sidebarAction.toggle())- }+ void extensionBrowser.sidePanel.setPanelBehavior({ openPanelOnActionClick: true })}export async function getActiveTab(): Promise<ExtensionTab | null> {@@ -172,7 +158,7 @@ export async function setStoredUiHost(uiHost: string): Promise<void> {}function originPattern(uiHost: string): ExtensionPermissions {- // Match patterns cover every port of a host, and Firefox rejects a pattern that names one.+ // A pattern without a port matches the host on every port.const { protocol, hostname } = new URL(uiHost)return { origins: [`${protocol}//${hostname}/*`] }}@@ -187,26 +173,6 @@ 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 itconst 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.tsindex 81452384eb36..dc5cd550ee41 100644--- a/frontend/src/toolbar/extension/components/panel/__mocks__/fakeExtensionBrowser.ts+++ b/frontend/src/toolbar/extension/components/panel/__mocks__/fakeExtensionBrowser.ts@@ -63,12 +63,6 @@ function fakePort(): ExtensionPort {},scripting: { executeScript: async () => [{}] },runtime: { onMessage: fakeEvent(), onConnect: fakeEvent(), getURL: (path: string) => `/${path}` },- permissions: {- contains: async () => true,- request: async () => true,- getAll: async () => ({ origins: [] }),- onAdded: fakeEvent(),- onRemoved: fakeEvent(),- },+ permissions: { contains: async () => true, request: async () => true },action: { onClicked: fakeEvent() },}diff --git a/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.ts b/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.tsindex c85331546464..20c4233ec8e3 100644--- a/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.ts+++ b/frontend/src/toolbar/extension/logics/panel/extensionPanelLogic.ts@@ -14,12 +14,10 @@ import { toolbarPosthogJS } from '~/toolbar/shared/toolbarPosthogJS'import { joinWithUiHost, safeFetch } from '~/toolbar/shared/utils'import {- canSendUsageData,getActiveTab,getStoredUiHost,hasHostPermission,onActiveTabChange,- onPermissionsChange,openTab,requestHostPermission,setStoredUiHost,@@ -57,15 +55,6 @@ 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(@@ -479,11 +468,7 @@ export const extensionPanelLogic = kea<extensionPanelLogicType>([},})),afterMount(({ actions, cache }) => {- // 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')+ toolbarPosthogJS.opt_in_capturing()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/src/toolbar/extension/logics/panel/extensionPanelState.test.ts b/frontend/src/toolbar/extension/logics/panel/extensionPanelState.test.tsindex 44649190acc4..9f131e802559 100644--- a/frontend/src/toolbar/extension/logics/panel/extensionPanelState.test.ts+++ b/frontend/src/toolbar/extension/logics/panel/extensionPanelState.test.ts@@ -27,7 +27,7 @@ describe('getExtensionPanelState', () => {],['extension store',- { tabUrl: 'https://addons.mozilla.org/en-US/firefox/' },+ { tabUrl: 'https://chromewebstore.google.com/category/extensions' },{ kind: 'unsupported-page', reason: 'extension-store' },],[diff --git a/frontend/src/toolbar/extension/logics/panel/extensionPanelState.ts b/frontend/src/toolbar/extension/logics/panel/extensionPanelState.tsindex 00e8c8cefe6a..97dd546763b9 100644--- a/frontend/src/toolbar/extension/logics/panel/extensionPanelState.ts+++ b/frontend/src/toolbar/extension/logics/panel/extensionPanelState.ts@@ -35,8 +35,8 @@ export interface ExtensionPanelInputs {authorizedUrls: string[] | 'error' | null}-// Browsers block every extension from scripting their own add-on stores.-const EXTENSION_STORE_HOSTNAMES = new Set(['chromewebstore.google.com', 'chrome.google.com', 'addons.mozilla.org'])+// Chrome blocks every extension from scripting the Chrome Web Store.+const EXTENSION_STORE_HOSTNAMES = new Set(['chromewebstore.google.com', 'chrome.google.com'])const LOOPBACK_HOSTNAMES = new Set(['localhost', '127.0.0.1', '[::1]'])diff --git a/frontend/toolbar-config.mjs b/frontend/toolbar-config.mjsindex 57fb5ae85949..86dd5b504f62 100644--- a/frontend/toolbar-config.mjs+++ b/frontend/toolbar-config.mjs@@ -251,14 +251,13 @@ export async function finalizeToolbarBuild(dirname, buildResponse) {})}-// The browser extension ships one panel bundle in a folder per browser. Only the manifest differs:+// The browser extension ships as a folder to load unpacked in Chrome, and as a zip for the Chrome Web Store://-// dist/toolbar-extension/<browser>/manifest.json-// dist/toolbar-extension/<browser>/panel.html, panel.js, panel.css, background.js, content.js, content.css,+// dist/toolbar-extension/chrome/manifest.json+// dist/toolbar-extension/chrome/panel.html, panel.js, panel.css, background.js, content.js, content.css,// assets/, icons/-//-// Load the folder unpacked in Chrome, or as a temporary add-on in Firefox.-const TOOLBAR_EXTENSION_BROWSERS = ['chrome', 'firefox']+// dist/toolbar-extension/posthog-toolbar-chrome-<version>.zip+const TOOLBAR_EXTENSION_OUT_DIR = 'toolbar-extension'const TOOLBAR_EXTENSION_VERSION = '0.1.0'@@ -319,7 +318,7 @@ export function getToolbarExtensionBuildConfig(dirname) {/*** The panel injects content.js into the tab with `scripting.executeScript`, which runs a file as a classic script, and- * Firefox doesn't run a module as a background script. So each of these scripts is one self-contained IIFE.+ * the manifest loads background.js as a classic service worker. So each of these scripts is one self-contained IIFE.*/export function getToolbarExtensionScriptsBuildConfig(dirname) {return {@@ -345,8 +344,8 @@ export function getToolbarExtensionScriptsBuildConfig(dirname) {// Asks for every http and https site, because the panel follows the active tab without a click on the extension// button, which `activeTab` needs.-function buildToolbarExtensionManifest(browser) {- const manifest = {+function buildToolbarExtensionManifest() {+ return {manifest_version: 3,name: 'PostHog',description: 'Use the PostHog toolbar in a side panel next to your website.',@@ -356,67 +355,35 @@ function buildToolbarExtensionManifest(browser) {default_title: 'Open PostHog',default_icon: TOOLBAR_EXTENSION_ICONS,},- permissions: ['scripting', 'storage'],+ permissions: ['scripting', 'storage', 'sidePanel'],host_permissions: ['http://*/*', 'https://*/*'],web_accessible_resources: [{ resources: ['content.css', 'assets/*'], matches: ['http://*/*', 'https://*/*'] }],- }- if (browser === 'firefox') {- manifest.sidebar_action = {- default_title: 'PostHog',- default_panel: 'panel.html',- default_icon: TOOLBAR_EXTENSION_ICONS,- open_at_install: false,- }- // 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: {- id: '[email protected]',- 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 {- manifest.permissions.push('sidePanel')- manifest.side_panel = { default_path: 'panel.html' }+ side_panel: { default_path: 'panel.html' },// 116 is the first release with `sidePanel.setPanelBehavior`, which opens the panel from the toolbar button.- manifest.minimum_chrome_version = '116'- manifest.background = { service_worker: 'background.js' }+ minimum_chrome_version: '116',+ background: { service_worker: 'background.js' },}- return manifest}export function finalizeToolbarExtensionBuild(dirname) {const buildDir = path.resolve(dirname, 'dist', TOOLBAR_EXTENSION_BUILD_DIR)- for (const browser of TOOLBAR_EXTENSION_BROWSERS) {- const outDir = path.resolve(dirname, 'dist', 'toolbar-extension', browser)- fs.rmSync(outDir, { recursive: true, force: true })- fs.cpSync(buildDir, outDir, { recursive: true })- fs.copyFileSync(path.resolve(dirname, 'src/toolbar/extension/panel.html'), path.resolve(outDir, 'panel.html'))- for (const icon of Object.values(TOOLBAR_EXTENSION_ICONS)) {- fs.mkdirSync(path.dirname(path.resolve(outDir, icon)), { recursive: true })- fs.copyFileSync(path.resolve(dirname, 'public', icon), path.resolve(outDir, icon))- }- fs.writeFileSync(- path.resolve(outDir, 'manifest.json'),- JSON.stringify(buildToolbarExtensionManifest(browser), null, 4) + '\n'- )- fs.writeFileSync(- path.resolve(- dirname,- 'dist',- 'toolbar-extension',- `posthog-toolbar-${browser}-${TOOLBAR_EXTENSION_VERSION}.zip`- ),- zipSync(readDirectoryFiles(outDir))- )+ const extensionDir = path.resolve(dirname, 'dist', TOOLBAR_EXTENSION_OUT_DIR)+ const outDir = path.resolve(extensionDir, 'chrome')+ fs.rmSync(extensionDir, { recursive: true, force: true })+ fs.cpSync(buildDir, outDir, { recursive: true })+ fs.copyFileSync(path.resolve(dirname, 'src/toolbar/extension/panel.html'), path.resolve(outDir, 'panel.html'))+ for (const icon of Object.values(TOOLBAR_EXTENSION_ICONS)) {+ fs.mkdirSync(path.dirname(path.resolve(outDir, icon)), { recursive: true })+ fs.copyFileSync(path.resolve(dirname, 'public', icon), path.resolve(outDir, icon))}+ fs.writeFileSync(+ path.resolve(outDir, 'manifest.json'),+ JSON.stringify(buildToolbarExtensionManifest(), null, 4) + '\n'+ )+ fs.writeFileSync(+ path.resolve(extensionDir, `posthog-toolbar-chrome-${TOOLBAR_EXTENSION_VERSION}.zip`),+ zipSync(readDirectoryFiles(outDir))+ )}function readDirectoryFiles(directory) {