YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(browser-extension): pick eligible tabs, skip chrome-extension:// pages
Louis Beaumont39f21d03db8d
diff --git a/packages/browser-extension/dist/manifest.json b/packages/browser-extension/dist/manifest.jsonindex c7fbb7e6a..ef1deb276 100644--- a/packages/browser-extension/dist/manifest.json+++ b/packages/browser-extension/dist/manifest.json@@ -2,7 +2,7 @@"manifest_version": 3,"name": "Screenpipe Browser Bridge","description": "Connects your browser to Screenpipe for AI-powered web automation and data sync.",- "version": "0.3.0",+ "version": "0.3.1","background": {"service_worker": "worker.js","type": "module"diff --git a/packages/browser-extension/dist/worker.js b/packages/browser-extension/dist/worker.jsindex 61ba319cb..bb12b9177 100644--- a/packages/browser-extension/dist/worker.js+++ b/packages/browser-extension/dist/worker.js@@ -187,21 +187,31 @@ function stopHeartbeat() {heartbeatTimer = null;}}+function isRestrictedUrl(url) {+ if (!url)+ return true;+ return url.startsWith("chrome://") || url.startsWith("chrome-extension://") || url.startsWith("edge://") || url.startsWith("about:") || url.includes("chromewebstore.google.com");+}async function findTab(urlPattern) {if (urlPattern) {const tabs = await chrome.tabs.query({});- const match = tabs.find((t) => t.url?.includes(urlPattern));+ const match = tabs.find((t) => t.url?.includes(urlPattern) && !isRestrictedUrl(t.url));if (match?.id != null)return match.id;}const [active] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });- if (active?.id != null)+ if (active?.id != null && !isRestrictedUrl(active.url)) {return active.id;- throw new Error("no matching tab found");+ }+ const all = await chrome.tabs.query({});+ const eligible = all.find((t) => t.id != null && !isRestrictedUrl(t.url));+ if (eligible?.id != null)+ return eligible.id;+ throw new Error("no eligible tab found — open a regular web page (not chrome://, chrome-extension://, or the chrome web store)");}async function evalInTab(tabId, code) {const tab = await chrome.tabs.get(tabId);- if (!tab.url || tab.url.startsWith("chrome://") || tab.url.startsWith("chrome-extension://") || tab.url.startsWith("edge://") || tab.url.startsWith("about:") || tab.url.includes("chromewebstore.google.com")) {+ if (isRestrictedUrl(tab.url)) {throw new Error(`cannot execute scripts on ${tab.url}`);}const expression = `(async () => { ${code} })()`;diff --git a/packages/browser-extension/package.json b/packages/browser-extension/package.jsonindex 8c83ab754..ecebab31c 100644--- a/packages/browser-extension/package.json+++ b/packages/browser-extension/package.json@@ -1,6 +1,6 @@{"name": "@screenpipe/browser-extension",- "version": "0.3.0",+ "version": "0.3.1","private": true,"scripts": {"build": "bun build src/worker.ts src/options.ts src/popup.ts --outdir dist --target browser --format esm",diff --git a/packages/browser-extension/src/worker.ts b/packages/browser-extension/src/worker.tsindex e8f681b60..72f125ebc 100644--- a/packages/browser-extension/src/worker.ts+++ b/packages/browser-extension/src/worker.ts@@ -278,17 +278,47 @@ function stopHeartbeat(): void {// Tab finding// ---------------------------------------------------------------------------+/**+ * Tabs we cannot drive: Chrome's privileged scheme pages and the extension's+ * own pages. `chrome.debugger.attach` is rejected on these by the browser, so+ * picking one would surface as an opaque "cannot execute scripts on …" error.+ */+function isRestrictedUrl(url: string | undefined): boolean {+ if (!url) return true;+ return (+ url.startsWith("chrome://") ||+ url.startsWith("chrome-extension://") ||+ url.startsWith("edge://") ||+ url.startsWith("about:") ||+ url.includes("chromewebstore.google.com")+ );+}+async function findTab(urlPattern?: string): Promise<number> {if (urlPattern) {const tabs = await chrome.tabs.query({});- const match = tabs.find((t) => t.url?.includes(urlPattern));+ const match = tabs.find(+ (t) => t.url?.includes(urlPattern) && !isRestrictedUrl(t.url),+ );if (match?.id != null) return match.id;}+ // Prefer the focused active tab when it's eligible — that's almost always+ // what the user means. Otherwise scan every window for the first regular+ // web tab we can drive. This avoids the "test connection failed because+ // your active tab happened to be the extension's options page" trap.const [active] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });- if (active?.id != null) return active.id;+ if (active?.id != null && !isRestrictedUrl(active.url)) {+ return active.id;+ }++ const all = await chrome.tabs.query({});+ const eligible = all.find((t) => t.id != null && !isRestrictedUrl(t.url));+ if (eligible?.id != null) return eligible.id;- throw new Error("no matching tab found");+ throw new Error(+ "no eligible tab found — open a regular web page (not chrome://, chrome-extension://, or the chrome web store)",+ );}// ---------------------------------------------------------------------------@@ -297,14 +327,7 @@ async function findTab(urlPattern?: string): Promise<number> {async function evalInTab(tabId: number, code: string): Promise<unknown> {const tab = await chrome.tabs.get(tabId);- if (- !tab.url ||- tab.url.startsWith("chrome://") ||- tab.url.startsWith("chrome-extension://") ||- tab.url.startsWith("edge://") ||- tab.url.startsWith("about:") ||- tab.url.includes("chromewebstore.google.com")- ) {+ if (isRestrictedUrl(tab.url)) {throw new Error(`cannot execute scripts on ${tab.url}`);}