diff --git a/extensions/ab-connect/background.js b/extensions/ab-connect/background.js index e519090..a137a31 100644 --- a/extensions/ab-connect/background.js +++ b/extensions/ab-connect/background.js @@ -199,10 +199,31 @@ async function handleForwardCdpCommand(msg) { } // Everything else → chrome.debugger on the resolved tab. - const tabId = - (sessionId ? tabForSession(sessionId) : null) ?? - (typeof params?.targetId === 'string' ? tabForTarget(params.targetId) : null) ?? - anyConnectedTab() + // + // A daemon-supplied sessionId/targetId MUST resolve to a real attached tab. + // The old code fell through to anyConnectedTab() when it didn't, which + // silently ran the command (eval/screenshot/network) on an arbitrary tab — + // exactly the "ran on the wrong page with no warning" failure in issue #8.1, + // and the blank-screenshot symptom after a service-worker restart (#8.2). + // Fail loudly instead so the agent sees an actionable error, not bad data. + let tabId + if (sessionId) { + tabId = tabForSession(sessionId) + if (!tabId) { + throw new Error( + `stale sessionId ${sessionId} for ${method}: its tab is gone (closed, ` + + `navigated across processes, or lost after an extension restart). ` + + `Re-attach by re-opening your target URL before retrying.`, + ) + } + } else if (typeof params?.targetId === 'string') { + tabId = tabForTarget(params.targetId) + if (!tabId) throw new Error(`no attached tab for targetId ${params.targetId} (${method})`) + } else { + // No session/target specified — a browser-level command that legitimately + // applies to any attached tab. + tabId = anyConnectedTab() + } if (!tabId) throw new Error(`no attached tab for ${method}`) const dbg = { tabId } diff --git a/extensions/ab-connect/manifest.json b/extensions/ab-connect/manifest.json index 74ed496..47a1fc5 100644 --- a/extensions/ab-connect/manifest.json +++ b/extensions/ab-connect/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "agent-browser-stealth", - "version": "0.4.1", + "version": "0.4.2", "description": "Let agent-browser drive your logged-in Chrome \u2014 install once, no token, no per-use confirmation.", "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6vQIyscGIPYPZdSpPwPL0+0gxUROyRgCpmvCSDoc8XUm4qm97VbKnD9Ijc1lV22lNWZtE78gaRjt6BeSfuMgnBymnhLKjN1gU6AI5QUU0mrJyeHdWKvrKQR5FmsM2A7Xr1ykE2SiiS8zNUS3Y/6O5l+Nva7wrVy6E4a2dkBVQkOsu+DV+nEZvhIyuDY5D5SPXqNwUTWTaglwj5mjvHz36xSwCWlPmrtJ+ED0AUyrb2z4GIOmvk4kqtBVrh/UD058klLo4CkYOnIybB5aV6WYuwarfPY4bF/dLggPem+ewLNTUNBuwrxj/A4nUv0LJTuRO8rR7f8WR9qnRCY0Ic5saQIDAQAB", "icons": {