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
1 change: 0 additions & 1 deletion src/argo-archive-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class ArgoArchiveList extends LitElement {
height: 100%;
}


img.favicon {
width: 20px !important;
height: 20px !important;
Expand Down
80 changes: 51 additions & 29 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 Down Expand Up @@ -63,10 +67,12 @@ chrome.runtime.onConnect.addListener((port) => {
}
});


// @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 Down Expand Up @@ -110,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 @@ -171,8 +184,6 @@ function sidepanelHandler(port) {
self.recorders[tabId].port = null;
}
});


}
// ===========================================================================
chrome.runtime.onMessage.addListener(
Expand Down Expand Up @@ -208,20 +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.
await startRecorder(tabId, { collId: defaultCollId, port: null, autorun }, tab.url);
await startRecorder(
tabId,
{ collId: defaultCollId, port: null, autorun },
tab.url,
);
}
});

Expand Down Expand Up @@ -301,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 @@ -363,7 +383,6 @@ async function startRecorder(tabId, opts) {
}
const { waitForTabUpdate } = opts;


// @ts-expect-error - TS2339 - Property 'running' does not exist on type 'BrowserRecorder'.
if (!waitForTabUpdate && !self.recorders[tabId].running) {
try {
Expand Down Expand Up @@ -409,11 +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:"))
);
}



// ===========================================================================
// @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
59 changes: 38 additions & 21 deletions src/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class Recorder {
this.archiveCookies = (await getLocalOption("archiveCookies")) === "1";
this.archiveStorage = (await getLocalOption("archiveStorage")) === "1";
this.archiveFlash = (await getLocalOption("archiveFlash")) === "1";
this.archiveScreenshots = (await getLocalOption("archiveScreenshots")) === "1";
this.archiveScreenshots =
(await getLocalOption("archiveScreenshots")) === "1";
this.archivePDF = (await getLocalOption("archivePDF")) === "1";
}

Expand Down Expand Up @@ -943,13 +944,13 @@ class Recorder {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async savePDF(pageInfo: any) {
// @ts-expect-error: ignore param
await this.send("Emulation.setEmulatedMedia", {type: "screen"});
await this.send("Emulation.setEmulatedMedia", { type: "screen" });

// @ts-expect-error: ignore param
const resp = await this.send("Page.printToPDF", {printBackground: true});
const resp = await this.send("Page.printToPDF", { printBackground: true });

// @ts-expect-error: ignore param
await this.send("Emulation.setEmulatedMedia", {type: ""});
await this.send("Emulation.setEmulatedMedia", { type: "" });

const payload = Buffer.from(resp.data, "base64");
const mime = "application/pdf";
Expand All @@ -961,10 +962,13 @@ class Recorder {
statusText: "OK",
pageId: pageInfo.id,
mime,
respHeaders: {"Content-Type": mime, "Content-Length": payload.length + ""},
respHeaders: {
"Content-Type": mime,
"Content-Length": payload.length + "",
},
reqHeaders: {},
payload,
extraOpts: {resource: true},
extraOpts: { resource: true },
};

console.log("pdf", payload.length);
Expand All @@ -975,21 +979,25 @@ class Recorder {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async saveScreenshot(pageInfo: any) {

// View Screenshot
const width = 1920;
const height = 1080;

// @ts-expect-error: ignore param
await this.send("Emulation.setDeviceMetricsOverride", {width, height, deviceScaleFactor: 0, mobile: false});
await this.send("Emulation.setDeviceMetricsOverride", {
width,
height,
deviceScaleFactor: 0,
mobile: false,
});
// @ts-expect-error: ignore param
const resp = await this.send("Page.captureScreenshot", {format: "png"});
const resp = await this.send("Page.captureScreenshot", { format: "png" });

const payload = Buffer.from(resp.data, "base64");
const blob = new Blob([payload], {type: "image/png"});
const blob = new Blob([payload], { type: "image/png" });

await this.send("Emulation.clearDeviceMetricsOverride");

const mime = "image/png";

const fullData = {
Expand All @@ -999,35 +1007,44 @@ class Recorder {
statusText: "OK",
pageId: pageInfo.id,
mime,
respHeaders: {"Content-Type": mime, "Content-Length": payload.length + ""},
respHeaders: {
"Content-Type": mime,
"Content-Length": payload.length + "",
},
reqHeaders: {},
payload,
extraOpts: {resource: true},
extraOpts: { resource: true },
};

const thumbWidth = 640;
const thumbHeight = 360;

const bitmap = await self.createImageBitmap(blob, {resizeWidth: thumbWidth, resizeHeight: thumbHeight});

const bitmap = await self.createImageBitmap(blob, {
resizeWidth: thumbWidth,
resizeHeight: thumbHeight,
});

const canvas = new OffscreenCanvas(thumbWidth, thumbWidth);
const context = canvas.getContext("bitmaprenderer")!;
context.transferFromImageBitmap(bitmap);

const resizedBlob = await canvas.convertToBlob({type: "image/png"});
const resizedBlob = await canvas.convertToBlob({ type: "image/png" });

const thumbPayload = new Uint8Array(await resizedBlob.arrayBuffer());

const thumbData = {...fullData,
const thumbData = {
...fullData,
url: "urn:thumbnail:" + pageInfo.url,
respHeaders: {"Content-Type": mime, "Content-Length": thumbPayload.length + ""},
payload: thumbPayload
respHeaders: {
"Content-Type": mime,
"Content-Length": thumbPayload.length + "",
},
payload: thumbPayload,
};

// @ts-expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
await this._doAddResource(fullData);


// @ts-expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
await this._doAddResource(thumbData);
}
Expand Down
Loading
Loading