fix(ab-connect): fail loudly on a stale sessionId instead of routing to a random tab (issue #8.1)
handleForwardCdpCommand fell through to anyConnectedTab() when a
daemon-supplied sessionId didn't map to an attached tab, so eval/screenshot/
network silently ran on an arbitrary tab — the root of "eval ran on the
wrong page, no warning" and the blank-screenshot-after-restart symptom.
Now: a provided sessionId/targetId MUST resolve to a real tab or the command
throws an actionable error ("stale sessionId … re-open your target URL").
anyConnectedTab() is only used for genuinely browser-level commands that
specify neither. Manifest 0.4.1 → 0.4.2 (needs a Chrome Web Store republish
for installed users to pick this up).
This commit is contained in:
@@ -199,10 +199,31 @@ async function handleForwardCdpCommand(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Everything else → chrome.debugger on the resolved tab.
|
// Everything else → chrome.debugger on the resolved tab.
|
||||||
const tabId =
|
//
|
||||||
(sessionId ? tabForSession(sessionId) : null) ??
|
// A daemon-supplied sessionId/targetId MUST resolve to a real attached tab.
|
||||||
(typeof params?.targetId === 'string' ? tabForTarget(params.targetId) : null) ??
|
// The old code fell through to anyConnectedTab() when it didn't, which
|
||||||
anyConnectedTab()
|
// 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}`)
|
if (!tabId) throw new Error(`no attached tab for ${method}`)
|
||||||
const dbg = { tabId }
|
const dbg = { tabId }
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "agent-browser-stealth",
|
"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.",
|
"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",
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6vQIyscGIPYPZdSpPwPL0+0gxUROyRgCpmvCSDoc8XUm4qm97VbKnD9Ijc1lV22lNWZtE78gaRjt6BeSfuMgnBymnhLKjN1gU6AI5QUU0mrJyeHdWKvrKQR5FmsM2A7Xr1ykE2SiiS8zNUS3Y/6O5l+Nva7wrVy6E4a2dkBVQkOsu+DV+nEZvhIyuDY5D5SPXqNwUTWTaglwj5mjvHz36xSwCWlPmrtJ+ED0AUyrb2z4GIOmvk4kqtBVrh/UD058klLo4CkYOnIybB5aV6WYuwarfPY4bF/dLggPem+ewLNTUNBuwrxj/A4nUv0LJTuRO8rR7f8WR9qnRCY0Ic5saQIDAQAB",
|
||||||
"icons": {
|
"icons": {
|
||||||
|
|||||||
Reference in New Issue
Block a user