Skip to content

Commit 2a1783d

Browse files
feat: working settings + skip domains
1 parent 86c4e52 commit 2a1783d

6 files changed

Lines changed: 324 additions & 28 deletions

File tree

src/ext/bg.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
setLocalOption,
1010
getSharedArchives,
1111
} from "../localstorage";
12+
import { isValidUrl } from "../utils";
1213
// ===========================================================================
1314
self.recorders = {};
1415
self.newRecId = null;
@@ -22,6 +23,7 @@ let newRecCollId = null;
2223
let defaultCollId = null;
2324
let autorun = false;
2425
let isRecordingEnabled = false;
26+
let skipDomains = [] as string[];
2527

2628
const openWinMap = new Map();
2729

@@ -32,6 +34,12 @@ const disabledCSPTabs = new Set();
3234
// @ts-expect-error - TS7034 - Variable 'sidepanelPort' implicitly has type 'any' in some locations where its type cannot be determined.
3335
let sidepanelPort = null;
3436

37+
(async function loadSkipDomains() {
38+
// @ts-expect-error
39+
skipDomains = (await getLocalOption("skipDomains")) || [];
40+
console.log("bg.skipDomains:", skipDomains);
41+
})();
42+
3543
// ===========================================================================
3644

3745
function main() {
@@ -136,7 +144,7 @@ function sidepanelHandler(port) {
136144
//@ts-expect-error tabs has any type
137145
async (tabs) => {
138146
for (const tab of tabs) {
139-
if (!isValidUrl(tab.url)) continue;
147+
if (!isValidUrl(tab.url, skipDomains)) continue;
140148

141149
await startRecorder(
142150
tab.id,
@@ -217,6 +225,13 @@ chrome.runtime.onMessage.addListener(
217225
(message /*sender, sendResponse*/) => {
218226
console.log("onMessage", message);
219227
switch (message.msg) {
228+
case "optionsChanged":
229+
for (const rec of Object.values(self.recorders)) {
230+
rec.initOpts();
231+
rec.doUpdateStatus();
232+
}
233+
break;
234+
220235
case "startNew":
221236
(async () => {
222237
newRecUrl = message.url;
@@ -256,7 +271,7 @@ chrome.tabs.onActivated.addListener(async ({ tabId }) => {
256271
chrome.tabs.get(tabId, resolve),
257272
);
258273

259-
if (!isValidUrl(tab.url)) return;
274+
if (!isValidUrl(tab.url, skipDomains)) return;
260275
if (!self.recorders[tabId]) {
261276
await startRecorder(
262277
tabId,
@@ -296,7 +311,7 @@ chrome.tabs.onCreated.addListener((tab) => {
296311
newRecCollId = null;
297312
} else if (
298313
tab.openerTabId &&
299-
(!tab.pendingUrl || isValidUrl(tab.pendingUrl)) &&
314+
(!tab.pendingUrl || isValidUrl(tab.pendingUrl, skipDomains)) &&
300315
// @ts-expect-error - TS2339 - Property 'running' does not exist on type 'BrowserRecorder'.
301316
self.recorders[tab.openerTabId]?.running
302317
) {
@@ -311,7 +326,7 @@ chrome.tabs.onCreated.addListener((tab) => {
311326
}
312327

313328
if (start) {
314-
if (openUrl && !isValidUrl(openUrl)) {
329+
if (openUrl && !isValidUrl(openUrl, skipDomains)) {
315330
return;
316331
}
317332
startRecorder(
@@ -339,7 +354,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
339354

340355
// @ts-expect-error - TS2339 - Property 'waitForTabUpdate' does not exist on type 'BrowserRecorder'.
341356
if (recorder.waitForTabUpdate) {
342-
if (isValidUrl(changeInfo.url)) {
357+
if (isValidUrl(changeInfo.url, skipDomains)) {
343358
recorder.attach();
344359
} else {
345360
// @ts-expect-error - TS2339 - Property 'waitForTabUpdate' does not exist on type 'BrowserRecorder'.
@@ -351,7 +366,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
351366
} else if (changeInfo.url) {
352367
if (
353368
isRecordingEnabled &&
354-
isValidUrl(changeInfo.url) &&
369+
isValidUrl(changeInfo.url, skipDomains) &&
355370
!self.recorders[tabId]
356371
) {
357372
// @ts-expect-error - TS2554 - Expected 2 arguments, but got 3.
@@ -361,7 +376,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
361376
if (openWinMap.has(changeInfo.url)) {
362377
const collId = openWinMap.get(changeInfo.url);
363378
openWinMap.delete(changeInfo.url);
364-
if (!tabId || !isValidUrl(changeInfo.url)) return;
379+
if (!tabId || !isValidUrl(changeInfo.url, skipDomains)) return;
365380

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

387402
case "toggle-rec":
388403
if (!isRecording(tab.id)) {
389-
if (isValidUrl(tab.url)) {
404+
if (isValidUrl(tab.url, skipDomains)) {
390405
// @ts-expect-error - TS2554 - Expected 2 arguments, but got 1.
391406
startRecorder(tab.id);
392407
}
@@ -457,17 +472,6 @@ function isRecording(tabId) {
457472
return self.recorders[tabId]?.running;
458473
}
459474

460-
// ===========================================================================
461-
// @ts-expect-error - TS7006 - Parameter 'url' implicitly has an 'any' type.
462-
function isValidUrl(url) {
463-
return (
464-
url &&
465-
(url === "about:blank" ||
466-
url.startsWith("https:") ||
467-
url.startsWith("http:"))
468-
);
469-
}
470-
471475
// ===========================================================================
472476
// @ts-expect-error - TS7006 - Parameter 'tabId' implicitly has an 'any' type.
473477
async function disableCSPForTab(tabId) {

src/recorder.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RequestResponseInfo } from "./requestresponseinfo";
2-
2+
import { isValidUrl, isUrlInSkipList } from "./utils";
33
import {
44
getCustomRewriter,
55
rewriteDASH,
@@ -60,6 +60,7 @@ class Recorder {
6060
archiveFlash = false;
6161
archiveScreenshots = false;
6262
archivePDF = false;
63+
skipDomains: string[] = [];
6364

6465
_fetchQueue: FetchEntry[] = [];
6566

@@ -163,6 +164,9 @@ class Recorder {
163164
this.archiveScreenshots =
164165
(await getLocalOption("archiveScreenshots")) === "1";
165166
this.archivePDF = (await getLocalOption("archivePDF")) === "1";
167+
// @ts-expect-error
168+
this.skipDomains = (await getLocalOption("skipDomains")) || [];
169+
console.log("recorder.skipDomains", this.skipDomains);
166170
}
167171

168172
// @ts-expect-error - TS7006 - Parameter 'autorun' implicitly has an 'any' type.
@@ -1111,6 +1115,9 @@ class Recorder {
11111115

11121116
// @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.
11131117
commitPage(currPage, domSnapshot, finished) {
1118+
if (isUrlInSkipList(currPage?.url, this.skipDomains)) {
1119+
return;
1120+
}
11141121
if (!currPage?.url || !currPage.ts || currPage.url === "about:blank") {
11151122
return;
11161123
}
@@ -1135,6 +1142,10 @@ class Recorder {
11351142

11361143
// @ts-expect-error - TS7006 - Parameter 'data' implicitly has an 'any' type. | TS7006 - Parameter 'pageInfo' implicitly has an 'any' type.
11371144
async commitResource(data, pageInfo) {
1145+
if (isUrlInSkipList(data.url, this.skipDomains)) {
1146+
return;
1147+
}
1148+
11381149
const payloadSize = data.payload.length;
11391150
// @ts-expect-error - TS2339 - Property 'pageInfo' does not exist on type 'Recorder'.
11401151
pageInfo = pageInfo || this.pageInfo;
@@ -1552,11 +1563,6 @@ class Recorder {
15521563
return !status || status === 204 || (status >= 300 && status < 400);
15531564
}
15541565

1555-
// @ts-expect-error - TS7006 - Parameter 'url' implicitly has an 'any' type.
1556-
isValidUrl(url) {
1557-
return url && (url.startsWith("https:") || url.startsWith("http:"));
1558-
}
1559-
15601566
// @ts-expect-error - TS7006 - Parameter 'params' implicitly has an 'any' type. | TS7006 - Parameter 'sessions' implicitly has an 'any' type.
15611567
async handleLoadingFinished(params, sessions) {
15621568
const reqresp = this.removeReqResp(params.requestId);
@@ -1566,7 +1572,7 @@ class Recorder {
15661572
return;
15671573
}
15681574

1569-
if (!this.isValidUrl(reqresp.url)) {
1575+
if (!isValidUrl(reqresp.url, this.skipDomains)) {
15701576
return;
15711577
}
15721578

@@ -1830,7 +1836,7 @@ class Recorder {
18301836

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

0 commit comments

Comments
 (0)