Skip to content
Closed
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
7 changes: 3 additions & 4 deletions src/argo-archive-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export class ArgoArchiveList extends LitElement {
padding: 0;
overflow: visible;
}
.card-container {
padding: 0 1rem;
}

md-elevated-card > details {
border-radius: inherit;
Expand Down Expand Up @@ -56,10 +59,6 @@ export class ArgoArchiveList extends LitElement {
height: 100%;
}

.card-container {
padding: 0 1rem;
}

img.favicon {
width: 20px !important;
height: 20px !important;
Expand Down
189 changes: 85 additions & 104 deletions src/ext/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { CollectionLoader } from "@webrecorder/wabac/swlib";

import { listAllMsg } from "../utils";

import { getLocalOption, removeLocalOption, setLocalOption } from "../localstorage";
import {
getLocalOption,
removeLocalOption,
setLocalOption,
} from "../localstorage";

// ===========================================================================
self.recorders = {};
Expand All @@ -26,6 +30,9 @@ const collLoader = new CollectionLoader();

const disabledCSPTabs = new Set();

// @ts-expect-error - TS7034 - Variable 'sidepanelPort' implicitly has type 'any' in some locations where its type cannot be determined.
let sidepanelPort = null;

// ===========================================================================

function main() {
Expand Down Expand Up @@ -54,75 +61,18 @@ chrome.sidePanel
// @ts-expect-error - TS7006 - Parameter 'port' implicitly has an 'any' type.
chrome.runtime.onConnect.addListener((port) => {
switch (port.name) {
case "popup-port":
popupHandler(port);
break;
case "sidepanel-port":
sidepanelHandler(port);
break;
}
});

// @ts-expect-error - TS7006 - Parameter 'port' implicitly has an 'any' type.
function popupHandler(port) {
if (!port.sender || port.sender.url !== chrome.runtime.getURL("popup.html")) {
return;
}

// @ts-expect-error - TS7034 - Variable 'tabId' implicitly has type 'any' in some locations where its type cannot be determined.
let tabId = null;

// @ts-expect-error - TS7006 - Parameter 'message' implicitly has an 'any' type.
port.onMessage.addListener(async (message) => {
switch (message.type) {
case "startUpdates":
tabId = message.tabId;
if (self.recorders[tabId]) {
// @ts-expect-error - TS2339 - Property 'port' does not exist on type 'BrowserRecorder'.
self.recorders[tabId].port = port;
self.recorders[tabId].doUpdateStatus();
}
port.postMessage(await listAllMsg(collLoader));
break;

case "startRecording": {
const { collId, autorun } = message;
// @ts-expect-error - TS2554 - Expected 2 arguments, but got 3.
startRecorder(tabId, { collId, port, autorun }, message.url);
break;
}

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

case "toggleBehaviors":
// @ts-expect-error - TS7005 - Variable 'tabId' implicitly has an 'any' type.
toggleBehaviors(tabId);
break;

case "newColl": {
const { name } = await collLoader.initNewColl({ title: message.title });
defaultCollId = name;
port.postMessage(await listAllMsg(collLoader, { defaultCollId }));
await setLocalOption("defaultCollId", defaultCollId);
break;
}
}
});

port.onDisconnect.addListener(() => {
// @ts-expect-error - TS2538 - Type 'null' cannot be used as an index type.
if (self.recorders[tabId]) {
// @ts-expect-error - TS2538 - Type 'null' cannot be used as an index type.
self.recorders[tabId].port = null;
}
});
}
// @ts-expect-error - TS7006 - Parameter 'port' implicitly has an 'any' type.
function sidepanelHandler(port) {
if (!port.sender || port.sender.url !== chrome.runtime.getURL("sidepanel.html")) {
if (
!port.sender ||
port.sender.url !== chrome.runtime.getURL("sidepanel.html")
) {
return;
}

Expand All @@ -134,6 +84,7 @@ function sidepanelHandler(port) {
switch (message.type) {
case "startUpdates":
tabId = message.tabId;
sidepanelPort = port;
if (self.recorders[tabId]) {
// @ts-expect-error - TS2339 - Property 'port' does not exist on type 'BrowserRecorder'.
self.recorders[tabId].port = port;
Expand Down Expand Up @@ -165,22 +116,29 @@ function sidepanelHandler(port) {
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);
}

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

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

break;
}
Expand Down Expand Up @@ -227,7 +185,29 @@ function sidepanelHandler(port) {
}
});
}
// ===========================================================================
chrome.runtime.onMessage.addListener(
// @ts-expect-error - TS7006 - Parameter 'message' implicitly has an 'any' type.
(message /*sender, sendResponse*/) => {
console.log("onMessage", message);
switch (message.msg) {
case "startNew":
(async () => {
newRecUrl = message.url;
newRecCollId = message.collId;
autorun = message.autorun;
defaultCollId = await getLocalOption("defaultCollId");
chrome.tabs.create({ url: "about:blank" });
})();
break;

case "disableCSP":
disableCSPForTab(message.tabId);
break;
}
return true;
},
);
// ===========================================================================
// @ts-expect-error - TS7006 - Parameter 'tab' implicitly has an 'any' type. | TS7006 - Parameter 'reason' implicitly has an 'any' type.
chrome.debugger.onDetach.addListener((tab, reason) => {
Expand All @@ -239,16 +219,25 @@ chrome.debugger.onDetach.addListener((tab, reason) => {

// @ts-expect-error - TS7006 - Parameter 'tab' implicitly has an 'any' type.
chrome.tabs.onActivated.addListener(async ({ tabId }) => {
// @ts-expect-error - TS7034 - Variable 'err' implicitly has type 'any' in some locations where its type cannot be determined.
if (sidepanelPort) {
sidepanelPort.postMessage({ type: "update" });
}
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));
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);
await startRecorder(
tabId,
{ collId: defaultCollId, port: null, autorun },
tab.url,
);
}
});

Expand Down Expand Up @@ -328,7 +317,11 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
}
}
} else if (changeInfo.url) {
if (isRecordingEnabled && isValidUrl(changeInfo.url) && !self.recorders[tabId]) {
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;
Expand Down Expand Up @@ -384,7 +377,10 @@ async function startRecorder(tabId, opts) {
}

let err = null;

// @ts-expect-error - TS7034 - Variable 'sidepanelPort' implicitly has type 'any' in some locations where its type cannot be determined.
if (sidepanelPort) {
sidepanelPort.postMessage({ type: "update" });
}
const { waitForTabUpdate } = opts;

// @ts-expect-error - TS2339 - Property 'running' does not exist on type 'BrowserRecorder'.
Expand Down Expand Up @@ -432,29 +428,14 @@ function isRecording(tabId) {
// ===========================================================================
// @ts-expect-error - TS7006 - Parameter 'url' implicitly has an 'any' type.
function isValidUrl(url) {
return url && (url === "about:blank" || url.startsWith("https:") || url.startsWith("http:"));
return (
url &&
(url === "about:blank" ||
url.startsWith("https:") ||
url.startsWith("http:"))
);
}

// ===========================================================================
chrome.runtime.onMessage.addListener(
// @ts-expect-error - TS7006 - Parameter 'message' implicitly has an 'any' type.
async (message /*sender, sendResponse*/) => {
switch (message.msg) {
case "startNew":
newRecUrl = message.url;
newRecCollId = message.collId;
autorun = message.autorun;
defaultCollId = await getLocalOption("defaultCollId");
chrome.tabs.create({ url: "about:blank" });
break;

case "disableCSP":
disableCSPForTab(message.tabId);
break;
}
},
);

// ===========================================================================
// @ts-expect-error - TS7006 - Parameter 'tabId' implicitly has an 'any' type.
async function disableCSPForTab(tabId) {
Expand Down
12 changes: 9 additions & 3 deletions src/ext/browser-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ class BrowserRecorder extends Recorder {
}

if (numOtherRecorders > 0) {
console.log(`closing session, not detaching, ${numOtherRecorders} other recording tab(s) left`);
console.log(
`closing session, not detaching, ${numOtherRecorders} other recording tab(s) left`,
);
return this.sessionClose([]);
} else {
console.log("detaching debugger, already tabs stopped");
Expand Down Expand Up @@ -234,7 +236,9 @@ class BrowserRecorder extends Recorder {
this.doUpdateStatus();
} catch (msg) {
// @ts-expect-error - TS2339 - Property 'failureMsg' does not exist on type 'BrowserRecorder'.
this.failureMsg = chrome.runtime.lastError ? chrome.runtime.lastError.message : msg;
this.failureMsg = chrome.runtime.lastError
? chrome.runtime.lastError.message
: msg;
this.doUpdateStatus();
throw msg;
}
Expand Down Expand Up @@ -371,7 +375,9 @@ class BrowserRecorder extends Recorder {
prr.resolve(res);
} else {
// @ts-expect-error - TS7005 - Variable 'prr' implicitly has an 'any' type.
prr.reject(chrome.runtime.lastError ? chrome.runtime.lastError.message : "");
prr.reject(
chrome.runtime.lastError ? chrome.runtime.lastError.message : "",
);
}
};

Expand Down
Loading
Loading