Skip to content
4 changes: 2 additions & 2 deletions src/argo-archive-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ export class ArgoArchiveList extends LitElement {
width: 20px !important;
height: 20px !important;
flex: 0 0 auto;
object-fit: cover;
object-fit: contain;
border-radius: 4px;
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

summary {
Expand Down
4 changes: 2 additions & 2 deletions src/argo-shared-archive-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export class ArgoSharedArchiveList extends LitElement {
width: 20px !important;
height: 20px !important;
flex: 0 0 auto;
object-fit: cover;
object-fit: contain;
border-radius: 4px;
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

.title-url {
Expand Down
56 changes: 37 additions & 19 deletions src/ext/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
setLocalOption,
getSharedArchives,
} from "../localstorage";
import { isValidUrl } from "../utils";
// ===========================================================================
self.recorders = {};
self.newRecId = null;
Expand All @@ -22,6 +23,7 @@ let newRecCollId = null;
let defaultCollId = null;
let autorun = false;
let isRecordingEnabled = false;
let skipDomains = [] as string[];

const openWinMap = new Map();

Expand All @@ -32,6 +34,11 @@ 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;

(async function loadSkipDomains() {
// @ts-expect-error
skipDomains = (await getLocalOption("skipDomains")) || [];
})();

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

function main() {
Expand Down Expand Up @@ -136,7 +143,7 @@ function sidepanelHandler(port) {
//@ts-expect-error tabs has any type
async (tabs) => {
for (const tab of tabs) {
if (!isValidUrl(tab.url)) continue;
if (!isValidUrl(tab.url, skipDomains)) continue;

await startRecorder(
tab.id,
Expand Down Expand Up @@ -217,6 +224,13 @@ chrome.runtime.onMessage.addListener(
(message /*sender, sendResponse*/) => {
console.log("onMessage", message);
switch (message.msg) {
case "optionsChanged":
for (const rec of Object.values(self.recorders)) {
rec.initOpts();
rec.doUpdateStatus();
}
break;

case "startNew":
(async () => {
newRecUrl = message.url;
Expand Down Expand Up @@ -256,7 +270,7 @@ chrome.tabs.onActivated.addListener(async ({ tabId }) => {
chrome.tabs.get(tabId, resolve),
);

if (!isValidUrl(tab.url)) return;
if (!isValidUrl(tab.url, skipDomains)) return;
if (!self.recorders[tabId]) {
await startRecorder(
tabId,
Expand Down Expand Up @@ -296,7 +310,7 @@ chrome.tabs.onCreated.addListener((tab) => {
newRecCollId = null;
} else if (
tab.openerTabId &&
(!tab.pendingUrl || isValidUrl(tab.pendingUrl)) &&
(!tab.pendingUrl || isValidUrl(tab.pendingUrl, skipDomains)) &&
// @ts-expect-error - TS2339 - Property 'running' does not exist on type 'BrowserRecorder'.
self.recorders[tab.openerTabId]?.running
) {
Expand All @@ -311,7 +325,7 @@ chrome.tabs.onCreated.addListener((tab) => {
}

if (start) {
if (openUrl && !isValidUrl(openUrl)) {
if (openUrl && !isValidUrl(openUrl, skipDomains)) {
return;
}
startRecorder(
Expand All @@ -337,9 +351,20 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
openWinMap.delete(changeInfo.url);
}

if (changeInfo.url && !isValidUrl(changeInfo.url, skipDomains)) {
stopRecorder(tabId);
delete self.recorders[tabId];
// let the side-panel know the ’canRecord’/UI state changed
// @ts-expect-error
if (sidepanelPort) {
sidepanelPort.postMessage({ type: "update" });
}
return;
}

// @ts-expect-error - TS2339 - Property 'waitForTabUpdate' does not exist on type 'BrowserRecorder'.
if (recorder.waitForTabUpdate) {
if (isValidUrl(changeInfo.url)) {
if (isValidUrl(changeInfo.url, skipDomains)) {
recorder.attach();
} else {
// @ts-expect-error - TS2339 - Property 'waitForTabUpdate' does not exist on type 'BrowserRecorder'.
Expand All @@ -349,9 +374,13 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
}
}
} else if (changeInfo.url) {
// @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 &&
isValidUrl(changeInfo.url) &&
isValidUrl(changeInfo.url, skipDomains) &&
!self.recorders[tabId]
) {
// @ts-expect-error - TS2554 - Expected 2 arguments, but got 3.
Expand All @@ -361,7 +390,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (openWinMap.has(changeInfo.url)) {
const collId = openWinMap.get(changeInfo.url);
openWinMap.delete(changeInfo.url);
if (!tabId || !isValidUrl(changeInfo.url)) return;
if (!tabId || !isValidUrl(changeInfo.url, skipDomains)) return;

// @ts-expect-error - TS2554 - Expected 2 arguments, but got 3.
startRecorder(tabId, { collId, autorun }, changeInfo.url);
Expand All @@ -386,7 +415,7 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {

case "toggle-rec":
if (!isRecording(tab.id)) {
if (isValidUrl(tab.url)) {
if (isValidUrl(tab.url, skipDomains)) {
// @ts-expect-error - TS2554 - Expected 2 arguments, but got 1.
startRecorder(tab.id);
}
Expand Down Expand Up @@ -457,17 +486,6 @@ function isRecording(tabId) {
return self.recorders[tabId]?.running;
}

// ===========================================================================
// @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:"))
);
}

// ===========================================================================
// @ts-expect-error - TS7006 - Parameter 'tabId' implicitly has an 'any' type.
async function disableCSPForTab(tabId) {
Expand Down
16 changes: 12 additions & 4 deletions src/ext/browser-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { BEHAVIOR_RUNNING } from "../consts";
import { Recorder } from "../recorder";
import { isValidUrl } from "../utils";
import { getLocalOption } from "../localstorage";

// ===========================================================================
const DEBUG = false;
Expand Down Expand Up @@ -333,18 +335,24 @@ class BrowserRecorder extends Recorder {

return writtenSize;
}

// @ts-expect-error - TS7006 - Parameter 'pageInfo' implicitly has an 'any' type.
_doAddPage(pageInfo) {
async _doAddPage(pageInfo: { url?: string; [key: string]: any }) {
if (!pageInfo.url) {
console.warn("Empty Page, Skipping");
return;
}

// @ts-expect-error
const skipDomains: string[] = (await getLocalOption("skipDomains")) || [];

if (!isValidUrl(pageInfo.url, skipDomains)) {
console.log("Skipping by policy:", pageInfo.url);
return;
}

// @ts-expect-error - TS2339 - Property 'db' does not exist on type 'BrowserRecorder'.
if (this.db) {
// @ts-expect-error - TS2339 - Property 'db' does not exist on type 'BrowserRecorder'.
const result = this.db.addPage(pageInfo);

chrome.runtime.sendMessage({ type: "pageAdded" });
return result;
}
Expand Down
21 changes: 13 additions & 8 deletions src/recorder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RequestResponseInfo } from "./requestresponseinfo";

import { isValidUrl, isUrlInSkipList } from "./utils";
import {
getCustomRewriter,
rewriteDASH,
Expand Down Expand Up @@ -60,6 +60,7 @@ class Recorder {
archiveFlash = false;
archiveScreenshots = false;
archivePDF = false;
skipDomains: string[] = [];

_fetchQueue: FetchEntry[] = [];

Expand Down Expand Up @@ -163,6 +164,8 @@ class Recorder {
this.archiveScreenshots =
(await getLocalOption("archiveScreenshots")) === "1";
this.archivePDF = (await getLocalOption("archivePDF")) === "1";
// @ts-expect-error
this.skipDomains = (await getLocalOption("skipDomains")) || [];
}

// @ts-expect-error - TS7006 - Parameter 'autorun' implicitly has an 'any' type.
Expand Down Expand Up @@ -1111,6 +1114,9 @@ class Recorder {

// @ts-expect-error - TS7006 - Parameter 'currPage' implicitly has an 'any' type. | TS7006 - Parameter 'domSnapshot' implicitly has an 'any' type. | TS7006 - Parameter 'finished' implicitly has an 'any' type.
commitPage(currPage, domSnapshot, finished) {
if (isUrlInSkipList(currPage?.url, this.skipDomains)) {
return;
}
if (!currPage?.url || !currPage.ts || currPage.url === "about:blank") {
return;
}
Expand All @@ -1135,6 +1141,10 @@ class Recorder {

// @ts-expect-error - TS7006 - Parameter 'data' implicitly has an 'any' type. | TS7006 - Parameter 'pageInfo' implicitly has an 'any' type.
async commitResource(data, pageInfo) {
if (isUrlInSkipList(data.url, this.skipDomains)) {
return;
}

const payloadSize = data.payload.length;
// @ts-expect-error - TS2339 - Property 'pageInfo' does not exist on type 'Recorder'.
pageInfo = pageInfo || this.pageInfo;
Expand Down Expand Up @@ -1552,11 +1562,6 @@ class Recorder {
return !status || status === 204 || (status >= 300 && status < 400);
}

// @ts-expect-error - TS7006 - Parameter 'url' implicitly has an 'any' type.
isValidUrl(url) {
return url && (url.startsWith("https:") || url.startsWith("http:"));
}

// @ts-expect-error - TS7006 - Parameter 'params' implicitly has an 'any' type. | TS7006 - Parameter 'sessions' implicitly has an 'any' type.
async handleLoadingFinished(params, sessions) {
const reqresp = this.removeReqResp(params.requestId);
Expand All @@ -1566,7 +1571,7 @@ class Recorder {
return;
}

if (!this.isValidUrl(reqresp.url)) {
if (!isValidUrl(reqresp.url, this.skipDomains)) {
return;
}

Expand Down Expand Up @@ -1830,7 +1835,7 @@ class Recorder {

// @ts-expect-error - TS7006 - Parameter 'request' implicitly has an 'any' type. | TS7006 - Parameter 'sessions' implicitly has an 'any' type.
doAsyncFetch(request: FetchEntry, sessions) {
if (!request || !this.isValidUrl(request.url)) {
if (!request || !isValidUrl(request.url, this.skipDomains)) {
return;
}

Expand Down
Loading
Loading