feat: start archiving new pages as the user starts to visit them with archiving enabled#19
Conversation
… archiving enabled
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
| case "startRecording": { | ||
| const { collId, autorun } = message; | ||
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | ||
| startRecorder(tabId, { collId, port, autorun }, message.url); | ||
| isRecordingEnabled = true; | ||
| defaultCollId = message.collId; | ||
| autorun = message.autorun; | ||
|
|
||
| // @ts-expect-error - tabs doesn't have type definitions | ||
| chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => { | ||
| for (const tab of tabs) { | ||
| if (!isValidUrl(tab.url)) continue; | ||
|
|
||
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | ||
| await startRecorder(tab.id, { collId: defaultCollId, port: null, autorun }, tab.url); | ||
| } | ||
|
|
There was a problem hiding this comment.
Suggestion: The startRecorder function is being called with port: null, but the original code passed the actual port. This could break communication with the recorder. Ensure the port is properly passed to maintain functionality. [possible issue, importance: 8]
| case "startRecording": { | |
| const { collId, autorun } = message; | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId, port, autorun }, message.url); | |
| isRecordingEnabled = true; | |
| defaultCollId = message.collId; | |
| autorun = message.autorun; | |
| // @ts-expect-error - tabs doesn't have type definitions | |
| chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => { | |
| for (const tab of tabs) { | |
| if (!isValidUrl(tab.url)) continue; | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| await startRecorder(tab.id, { collId: defaultCollId, port: null, autorun }, tab.url); | |
| } | |
| case "startRecording": { | |
| isRecordingEnabled = true; | |
| defaultCollId = message.collId; | |
| autorun = message.autorun; | |
| // @ts-expect-error - tabs doesn't have type definitions | |
| chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => { | |
| for (const tab of tabs) { | |
| if (!isValidUrl(tab.url)) continue; | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| await startRecorder(tab.id, { collId: defaultCollId, port, autorun }, tab.url); | |
| } |
| // @ts-expect-error - TS7006 - Parameter 'tab' implicitly has an 'any' type. | ||
| chrome.tabs.onActivated.addListener(async ({ tabId }) => { | ||
| if (!isRecordingEnabled) return; | ||
|
|
||
| // @ts-expect-error - chrome doesn't have type definitions | ||
| const tab = await new Promise<chrome.tabs.Tab>((resolve) => chrome.tabs.get(tabId, resolve)); | ||
|
|
||
| if (!isValidUrl(tab.url)) return; | ||
|
|
||
| if (!self.recorders[tabId]) { | ||
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | ||
| startRecorder(tabId, { collId: defaultCollId, port: null, autorun }, tab.url); | ||
| } |
There was a problem hiding this comment.
Suggestion: The startRecorder function is called with port: null when a tab is activated. This could lead to communication issues. Consider handling the case where the recorder needs to communicate back to the UI. [possible issue, importance: 3]
| // @ts-expect-error - TS7006 - Parameter 'tab' implicitly has an 'any' type. | |
| chrome.tabs.onActivated.addListener(async ({ tabId }) => { | |
| if (!isRecordingEnabled) return; | |
| // @ts-expect-error - chrome doesn't have type definitions | |
| const tab = await new Promise<chrome.tabs.Tab>((resolve) => chrome.tabs.get(tabId, resolve)); | |
| if (!isValidUrl(tab.url)) return; | |
| if (!self.recorders[tabId]) { | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId: defaultCollId, port: null, autorun }, tab.url); | |
| } | |
| // @ts-expect-error - TS7006 - Parameter 'tab' implicitly has an 'any' type. | |
| chrome.tabs.onActivated.addListener(async ({ tabId }) => { | |
| if (!isRecordingEnabled) return; | |
| // @ts-expect-error - chrome doesn't have type definitions | |
| const tab = await new Promise<chrome.tabs.Tab>((resolve) => chrome.tabs.get(tabId, resolve)); | |
| if (!isValidUrl(tab.url)) return; | |
| if (!self.recorders[tabId]) { | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId: defaultCollId, port: null, autorun }, tab.url); | |
| // Notify any connected ports about the new recorder if needed | |
| } | |
| }); |
| } else if (changeInfo.url) { | ||
| if (isRecordingEnabled && isValidUrl(changeInfo.url) && !self.recorders[tabId]) { | ||
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | ||
| startRecorder(tabId, { collId: defaultCollId, autorun }, changeInfo.url); | ||
| return; | ||
| } | ||
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | ||
| startRecorder(tabId, { collId, autorun }, changeInfo.url); | ||
| if (openWinMap.has(changeInfo.url)) { | ||
| const collId = openWinMap.get(changeInfo.url); | ||
| openWinMap.delete(changeInfo.url); | ||
| if (!tabId || !isValidUrl(changeInfo.url)) return; | ||
|
|
||
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | ||
| startRecorder(tabId, { collId, autorun }, changeInfo.url); | ||
| } | ||
| } |
There was a problem hiding this comment.
Suggestion: The port parameter is missing in both startRecorder calls in the URL change handler. This is inconsistent with the original implementation and might cause issues with recorder communication. [possible issue, importance: 7]
| } else if (changeInfo.url) { | |
| if (isRecordingEnabled && isValidUrl(changeInfo.url) && !self.recorders[tabId]) { | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId: defaultCollId, autorun }, changeInfo.url); | |
| return; | |
| } | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId, autorun }, changeInfo.url); | |
| if (openWinMap.has(changeInfo.url)) { | |
| const collId = openWinMap.get(changeInfo.url); | |
| openWinMap.delete(changeInfo.url); | |
| if (!tabId || !isValidUrl(changeInfo.url)) return; | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId, autorun }, changeInfo.url); | |
| } | |
| } | |
| } else if (changeInfo.url) { | |
| if (isRecordingEnabled && isValidUrl(changeInfo.url) && !self.recorders[tabId]) { | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId: defaultCollId, port: null, autorun }, changeInfo.url); | |
| return; | |
| } | |
| if (openWinMap.has(changeInfo.url)) { | |
| const collId = openWinMap.get(changeInfo.url); | |
| openWinMap.delete(changeInfo.url); | |
| if (!tabId || !isValidUrl(changeInfo.url)) return; | |
| // @ts-expect-error - TS2554 - Expected 2 arguments, but got 3. | |
| startRecorder(tabId, { collId, port: null, autorun }, changeInfo.url); | |
| } | |
| } |
User description
This PR solves issue #14 and the bug mentioned by @Shrinks99 .
Now, the "Resume Archiving" and "Pause Archiving" buttons are always visible due to the new behavior, allowing the user to switch between tabs and record them without closing the side panel.
PR Type
Bug fix
Description
Fix sidepanel archiving sync across browser tabs
Enable recording on newly activated tabs
Properly handle tab navigation with recording enabled
Maintain recording state across tab changes
Changes walkthrough 📝
bg.ts
Implement cross-tab archiving synchronizationsrc/ext/bg.ts
isRecordingEnabledflag to track recording state globallystartRecordingto work with active tabs instead of just thesidepanel tab
stopRecordingto stop recording on all tabstabs