Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 67 additions & 12 deletions src/ext/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let newRecCollId = null;
// @ts-expect-error - TS7034 - Variable 'defaultCollId' implicitly has type 'any' in some locations where its type cannot be determined.
let defaultCollId = null;
let autorun = false;
let isRecordingEnabled = false;

const openWinMap = new Map();

Expand Down Expand Up @@ -159,16 +160,49 @@ function sidepanelHandler(port) {
}

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);
}

Comment on lines 162 to +175

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Suggested change
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);
}

port.postMessage({
type: "status",
recording: true,
autorun,
// @ts-expect-error - defaultCollId implicitly has an 'any' type.
collId: defaultCollId,
});
});

break;
}

case "stopRecording":
// @ts-expect-error - TS7005 - Variable 'tabId' implicitly has an 'any' type.
stopRecorder(tabId);
case "stopRecording": {
isRecordingEnabled = false;

for (const [tabIdStr, rec] of Object.entries(self.recorders)) {
const tabId = parseInt(tabIdStr);
stopRecorder(tabId);
}

port.postMessage({
type: "status",
recording: false,
autorun,
// @ts-expect-error - defaultCollId implicitly has an 'any' type.
collId: defaultCollId,
});

break;
}

case "toggleBehaviors":
// @ts-expect-error - TS7005 - Variable 'tabId' implicitly has an 'any' type.
Expand Down Expand Up @@ -203,6 +237,21 @@ chrome.debugger.onDetach.addListener((tab, reason) => {
}
});

// @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);
}
Comment on lines +240 to +252

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Suggested change
// @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
}
});

});

// ===========================================================================
// @ts-expect-error - TS7006 - Parameter 'tab' implicitly has an 'any' type.
chrome.tabs.onCreated.addListener((tab) => {
Expand Down Expand Up @@ -278,14 +327,20 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
return;
}
}
} else if (changeInfo.url && openWinMap.has(changeInfo.url)) {
const collId = openWinMap.get(changeInfo.url);
openWinMap.delete(changeInfo.url);
if (!tabId || !isValidUrl(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, 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);
}
}
Comment on lines +330 to 344

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Suggested change
} 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);
}
}

});

Expand Down
47 changes: 20 additions & 27 deletions src/sidepanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,39 +301,32 @@ class ArgoViewer extends LitElement {
<md-divider></md-divider>
<div style="padding:1rem; display:flex; align-items:center; justify-content:space-between;">
${
// @ts-expect-error - TS2339 - Property 'canRecord' does not exist on type 'RecPopup'.
this.canRecord
// @ts-expect-error - TS2339 - Property 'recording' does not exist on type 'RecPopup'.
!this.recording
? html`
${
// @ts-expect-error - TS2339 - Property 'recording' does not exist on type 'RecPopup'.
!this.recording
? html`
<md-filled-button
style="
<md-filled-button
style="
--md-sys-color-primary-container: #7b1fa2;
color: white;
border-radius: 9999px;
"
?disabled=${this.actionButtonDisabled}
@click=${this.onStart}
>
<md-icon slot="icon" style="color:white">public</md-icon>
Resume Archiving
</md-filled-button>
`
: html`
<md-outlined-button
style="--md-sys-color-primary: #b00020; --md-sys-color-outline: #b00020; border-radius: 9999px;"
?disabled=${this.actionButtonDisabled}
@click=${this.onStop}
>
<md-icon slot="icon" style="color:#b00020">pause</md-icon>
Pause Archiving
</md-outlined-button>
`
}
?disabled=${this.actionButtonDisabled}
@click=${this.onStart}
>
<md-icon slot="icon" style="color:white">public</md-icon>
Resume Archiving
</md-filled-button>
`
: html`
<md-outlined-button
style="--md-sys-color-primary: #b00020; --md-sys-color-outline: #b00020; border-radius: 9999px;"
?disabled=${this.actionButtonDisabled}
@click=${this.onStop}
>
<md-icon slot="icon" style="color:#b00020">pause</md-icon>
Pause Archiving
</md-outlined-button>
`
: html`<span></span>`
}

<md-icon-button aria-label="Settings">
Expand Down
Loading