fix(connect): stable per-tab relay session id — re-attach auto-recovers (#17)
When a tab's chrome.debugger session was torn down and re-established (cross-process navigation, MV3 service-worker restart wiping the in-memory maps, DevTools stealing the debugger), the extension minted a brand-new monotonic `cb-tab-N` for the same tab. The daemon stays bound to the old id and the relay consumes attach/detach events without telling it to rebind, so the session was orphaned permanently → `stale sessionId / tab is gone`, and re-open never recovered. Derive the session id from the STABLE Chrome tabId (`cb-tab-<tabId>`) instead. Any re-attach of the same tab now restores the SAME session the daemon already holds, so eval/snapshot transparently follow the new page after a navigation. Extension 0.4.3 → 0.4.4. Adds a relay unit test for the detach→reattach-same- session recovery contract.
This commit is contained in:
@@ -24,7 +24,6 @@ let port = null
|
||||
/** Whether the native-messaging host (the local chrome-use CLI) is linked.
|
||||
* Read by the popup status page. */
|
||||
let hostConnected = false
|
||||
let nextSession = 1
|
||||
/** tabId -> { sessionId, targetId } */
|
||||
const tabs = new Map()
|
||||
/** sessionId -> tabId (main session per tab) */
|
||||
@@ -261,7 +260,16 @@ async function attachTab(tabId) {
|
||||
const targetInfo = info?.targetInfo
|
||||
const targetId = String(targetInfo?.targetId || '')
|
||||
if (!targetId) throw new Error('attachTab: no targetId')
|
||||
const sessionId = `cb-tab-${nextSession++}`
|
||||
// Derive the session id from the STABLE Chrome tabId, not a monotonic counter
|
||||
// (issue #17). A tab's chrome.debugger session can be torn down and
|
||||
// re-established — cross-process navigation, a service-worker restart wiping
|
||||
// these in-memory maps, DevTools stealing the debugger — and each time the tab
|
||||
// re-attaches. With a counter, re-attach minted a BRAND-NEW `cb-tab-N`, which
|
||||
// orphaned the daemon's binding (it's still pinned to the old id and the relay
|
||||
// never tells it to rebind) → permanent "stale sessionId / tab is gone". The
|
||||
// tabId is stable across all of that, so `cb-tab-<tabId>` restores the SAME
|
||||
// session the daemon already holds → eval/snapshot auto-follow the new page.
|
||||
const sessionId = `cb-tab-${tabId}`
|
||||
const entry = { sessionId, targetId }
|
||||
tabs.set(tabId, entry)
|
||||
sessionToTab.set(sessionId, tabId)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "chrome-use",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"description": "Let chrome-use 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": {
|
||||
|
||||
Reference in New Issue
Block a user