fix(extension): harden target and chat recovery

This commit is contained in:
Timo
2026-08-17 21:44:41 +02:00
parent bce582b568
commit 8eaf026487
5 changed files with 49 additions and 24 deletions
+20 -21
View File
@@ -2658,9 +2658,6 @@ async function activateTargetTab(tabId, tabTitle, {
let injectedContentTarget = { frameId: 0, documentId: null, hasVideo: false };
try {
if (previousTabId && previousTabId !== selectedTabId) {
await deactivateTargetTab(previousTabId);
}
if (activationGeneration !== targetActivationGeneration) {
return { status: 'superseded' };
}
@@ -2696,26 +2693,26 @@ async function activateTargetTab(tabId, tabTitle, {
);
throw error;
}
currentTabId = null;
currentTabTitle = null;
clearCurrentContentTarget();
lastContentHeartbeatAt = null;
if (currentRoom) roomIdleSince = Date.now();
const failedContentTarget = error?.contentTarget || injectedContentTarget;
await deactivateTargetTab(selectedTabId, failedContentTarget);
if (previousTabId && (previousTabId !== selectedTabId
|| !sameContentTarget(previousContentTarget, failedContentTarget))) {
await deactivateTargetTab(previousTabId, previousContentTarget);
if (previousTabId === null) {
currentTabId = null;
currentTabTitle = null;
clearCurrentContentTarget();
lastContentHeartbeatAt = null;
if (currentRoom) roomIdleSince = Date.now();
await chrome.storage.session.set({
currentTabId: null,
currentTabTitle: null,
currentTargetFrameId: 0,
currentTargetDocumentId: null,
currentTargetHasVideo: false,
roomIdleSince,
lastContentHeartbeatAt: null
});
} else {
addLog(`Target switch to tab ${selectedTabId} failed; keeping tab ${previousTabId} selected`, 'warn');
}
await chrome.storage.session.set({
currentTabId: null,
currentTabTitle: null,
currentTargetFrameId: 0,
currentTargetDocumentId: null,
currentTargetHasVideo: false,
roomIdleSince,
lastContentHeartbeatAt: null
});
if (activationGeneration !== targetActivationGeneration) {
return { status: 'superseded' };
}
@@ -2765,7 +2762,9 @@ async function activateTargetTab(tabId, tabTitle, {
if (currentTabId !== selectedTabId) await deactivateTargetTab(selectedTabId, injectedContentTarget);
return { status: 'superseded' };
}
if (previousTabId === selectedTabId
if (previousTabId && previousTabId !== selectedTabId) {
await deactivateTargetTab(previousTabId, previousContentTarget);
} else if (previousTabId === selectedTabId
&& !sameContentTarget(previousContentTarget, injectedContentTarget)) {
await deactivateTargetTab(previousTabId, previousContentTarget, { deactivateMonitor: false });
}