Skip to content

Commit b0cde13

Browse files
committed
Merge branch 'main' into juan/sidepanel
2 parents 14ee765 + 6c4534f commit b0cde13

17 files changed

Lines changed: 3275 additions & 427 deletions

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/feature-change.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

package.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@webrecorder/archivewebpage",
33
"productName": "ArchiveWeb.page",
4-
"version": "0.14.2",
4+
"version": "0.15.0",
55
"main": "index.js",
66
"description": "Create Web Archives directly in your browser",
77
"repository": {
@@ -12,31 +12,34 @@
1212
"license": "AGPL-3.0-or-later",
1313
"dependencies": {
1414
"@fortawesome/fontawesome-free": "^5.13.0",
15-
"@ipld/car": "^5.3.1",
15+
"@ipld/car": "^5.3.2",
1616
"@material/web": "^2.3.0",
17-
"@webrecorder/awp-sw": "^0.5.3",
18-
"@webrecorder/wabac": "^2.20.8",
17+
"@ipld/unixfs": "^3.0.0",
18+
"@webrecorder/wabac": "^2.22.16",
1919
"auto-js-ipfs": "^2.3.0",
20-
"browsertrix-behaviors": "^0.6.4",
20+
"browsertrix-behaviors": "^0.8.5",
2121
"btoa": "^1.2.1",
2222
"bulma": "^0.9.3",
23-
"client-zip": "^2.2.2",
23+
"client-zip": "^2.3.0",
24+
"idb": "^7.1.1",
2425
"hash-wasm": "^4.9.0",
2526
"http-status-codes": "^2.1.4",
2627
"keyword-mark-element": "^0.1.2",
2728
"node-fetch": "2.6.7",
29+
"p-queue": "^8.0.1",
2830
"pdfjs-dist": "2.2.228",
2931
"pretty-bytes": "^5.6.0",
30-
"replaywebpage": "^2.2.5",
32+
"replaywebpage": "^2.3.7",
3133
"stream-browserify": "^3.0.0",
3234
"tsconfig-paths-webpack-plugin": "^4.1.0",
3335
"unused-filename": "^4.0.1",
34-
"uuid": "^8.3.2",
35-
"warcio": "^2.4.2"
36+
"uuid": "^9.0.0",
37+
"warcio": "^2.4.4"
3638
},
3739
"devDependencies": {
3840
"@typescript-eslint/eslint-plugin": "^6.15.0",
3941
"@typescript-eslint/parser": "^6.15.0",
42+
"@types/uuid": "^10.0.0",
4043
"copy-webpack-plugin": "^9.0.1",
4144
"css-loader": "^6.2.0",
4245
"electron": "^32.2.0",
@@ -59,13 +62,13 @@
5962
"ts-loader": "^9.5.1",
6063
"ts-migrate": "^0.1.35",
6164
"typescript": "^5.3.3",
62-
"webpack": "^5.91.0",
65+
"webpack": "^5.99.7",
6366
"webpack-cli": "^5.1.4",
6467
"webpack-dev-server": "^5.0.4",
6568
"webpack-extension-reloader": "^1.1.4"
6669
},
6770
"resolutions": {
68-
"@webrecorder/wabac": "^2.20.8"
71+
"@webrecorder/wabac": "^2.22.16"
6972
},
7073
"files": [
7174
"src/",

src/ext/browser-recorder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ class BrowserRecorder extends Recorder {
254254
// @ts-expect-error - TS2339 - Property 'behaviorState' does not exist on type 'BrowserRecorder'.
255255
if (this.behaviorState === BEHAVIOR_RUNNING) {
256256
title = "Archiving: Autopilot Running!";
257-
color = "#0891b2";
258-
text = "";
257+
color = "#0096ff";
258+
text = " ";
259259
// @ts-expect-error - TS2339 - Property 'numPending' does not exist on type 'BrowserRecorder'.
260260
} else if (this.numPending === 0) {
261261
title = "Archiving: No URLs pending, can continue";

src/localstorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function setLocalOption(name, value) {
1919
}
2020

2121
// ===========================================================================
22-
export function getLocalOption(name: string) : Promise<string | null> {
22+
export function getLocalOption(name: string): Promise<string | null> {
2323
// @ts-expect-error - TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'. | TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'.
2424
if (self.chrome?.storage) {
2525
return new Promise<string>((resolve) => {

src/recorder.ts

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import {
2222
} from "./consts";
2323
import { getLocalOption } from "./localstorage";
2424

25-
// @ts-expect-error - TS2554 - Expected 0 arguments, but got 1.
26-
const encoder = new TextEncoder("utf-8");
25+
const encoder = new TextEncoder();
2726

2827
const MAX_CONCURRENT_FETCH = 6;
2928

@@ -58,6 +57,9 @@ type FetchEntry = {
5857
class Recorder {
5958
archiveStorage = false;
6059
archiveCookies = false;
60+
archiveFlash = false;
61+
archiveScreenshots = false;
62+
archivePDF = false;
6163

6264
_fetchQueue: FetchEntry[] = [];
6365

@@ -155,8 +157,11 @@ class Recorder {
155157
}
156158

157159
async initOpts() {
158-
this.archiveCookies = (await getLocalOption("archiveCookies") === "1");
159-
this.archiveStorage = (await getLocalOption("archiveStorage") === "1");
160+
this.archiveCookies = (await getLocalOption("archiveCookies")) === "1";
161+
this.archiveStorage = (await getLocalOption("archiveStorage")) === "1";
162+
this.archiveFlash = (await getLocalOption("archiveFlash")) === "1";
163+
this.archiveScreenshots = (await getLocalOption("archiveScreenshots")) === "1";
164+
this.archivePDF = (await getLocalOption("archivePDF")) === "1";
160165
}
161166

162167
// @ts-expect-error - TS7006 - Parameter 'autorun' implicitly has an 'any' type.
@@ -190,8 +195,8 @@ class Recorder {
190195
this.behaviorInitStr
191196
});
192197
193-
window.addEventListener("beforeunload", () => {});` +
194-
this.getFlashInjectScript()
198+
window.addEventListener("beforeunload", () => {});\n` +
199+
(this.archiveFlash ? this.getFlashInjectScript() : "")
195200
);
196201
}
197202

@@ -550,8 +555,6 @@ class Recorder {
550555

551556
await this.send("Page.enable");
552557

553-
await this.send("Runtime.enable");
554-
555558
await this.send("DOMSnapshot.enable");
556559

557560
await this.initPixRatio();
@@ -632,7 +635,6 @@ class Recorder {
632635

633636
async sessionClose(sessions = []) {
634637
await this.send("Page.disable");
635-
await this.send("Runtime.disable");
636638
await this.send("DOMSnapshot.disable");
637639

638640
await this.send("Debugger.disable");
@@ -932,6 +934,98 @@ class Recorder {
932934
return success;
933935
}
934936

937+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
938+
async savePDF(pageInfo: any) {
939+
// @ts-expect-error: ignore param
940+
await this.send("Emulation.setEmulatedMedia", {type: "screen"});
941+
942+
// @ts-expect-error: ignore param
943+
const resp = await this.send("Page.printToPDF", {printBackground: true});
944+
945+
// @ts-expect-error: ignore param
946+
await this.send("Emulation.setEmulatedMedia", {type: ""});
947+
948+
const payload = Buffer.from(resp.data, "base64");
949+
const mime = "application/pdf";
950+
951+
const fullData = {
952+
url: "urn:pdf:" + pageInfo.url,
953+
ts: new Date().getTime(),
954+
status: 200,
955+
statusText: "OK",
956+
pageId: pageInfo.id,
957+
mime,
958+
respHeaders: {"Content-Type": mime, "Content-Length": payload.length + ""},
959+
reqHeaders: {},
960+
payload,
961+
extraOpts: {resource: true},
962+
};
963+
964+
console.log("pdf", payload.length);
965+
966+
// @ts-expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
967+
await this._doAddResource(fullData);
968+
}
969+
970+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
971+
async saveScreenshot(pageInfo: any) {
972+
973+
// View Screenshot
974+
const width = 1920;
975+
const height = 1080;
976+
977+
// @ts-expect-error: ignore param
978+
await this.send("Emulation.setDeviceMetricsOverride", {width, height, deviceScaleFactor: 0, mobile: false});
979+
// @ts-expect-error: ignore param
980+
const resp = await this.send("Page.captureScreenshot", {format: "png"});
981+
982+
const payload = Buffer.from(resp.data, "base64");
983+
const blob = new Blob([payload], {type: "image/png"});
984+
985+
await this.send("Emulation.clearDeviceMetricsOverride");
986+
987+
const mime = "image/png";
988+
989+
const fullData = {
990+
url: "urn:view:" + pageInfo.url,
991+
ts: new Date().getTime(),
992+
status: 200,
993+
statusText: "OK",
994+
pageId: pageInfo.id,
995+
mime,
996+
respHeaders: {"Content-Type": mime, "Content-Length": payload.length + ""},
997+
reqHeaders: {},
998+
payload,
999+
extraOpts: {resource: true},
1000+
};
1001+
1002+
const thumbWidth = 640;
1003+
const thumbHeight = 360;
1004+
1005+
const bitmap = await self.createImageBitmap(blob, {resizeWidth: thumbWidth, resizeHeight: thumbHeight});
1006+
1007+
const canvas = new OffscreenCanvas(thumbWidth, thumbWidth);
1008+
const context = canvas.getContext("bitmaprenderer")!;
1009+
context.transferFromImageBitmap(bitmap);
1010+
1011+
const resizedBlob = await canvas.convertToBlob({type: "image/png"});
1012+
1013+
const thumbPayload = new Uint8Array(await resizedBlob.arrayBuffer());
1014+
1015+
const thumbData = {...fullData,
1016+
url: "urn:thumbnail:" + pageInfo.url,
1017+
respHeaders: {"Content-Type": mime, "Content-Length": thumbPayload.length + ""},
1018+
payload: thumbPayload
1019+
};
1020+
1021+
// @ts-expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
1022+
await this._doAddResource(fullData);
1023+
1024+
1025+
// @ts-expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
1026+
await this._doAddResource(thumbData);
1027+
}
1028+
9351029
async getFullText(finishing = false) {
9361030
// @ts-expect-error - TS2339 - Property 'pageInfo' does not exist on type 'Recorder'. | TS2339 - Property 'pageInfo' does not exist on type 'Recorder'.
9371031
if (!this.pageInfo?.url) {
@@ -1191,6 +1285,14 @@ class Recorder {
11911285
// @ts-expect-error - TS2339 - Property 'pageInfo' does not exist on type 'Recorder'.
11921286
const pageInfo = this.pageInfo;
11931287

1288+
if (this.archiveScreenshots) {
1289+
await this.saveScreenshot(pageInfo);
1290+
}
1291+
1292+
if (this.archivePDF) {
1293+
await this.savePDF(pageInfo);
1294+
}
1295+
11941296
const [domSnapshot, favIcon] = await Promise.all([
11951297
this.getFullText(),
11961298
// @ts-expect-error - TS2339 - Property 'getFavIcon' does not exist on type 'Recorder'.

0 commit comments

Comments
 (0)