Skip to content

Commit 95c9be6

Browse files
authored
Support for import as module, wabac.js 2.20 (#364)
- Extensibility for AWP (customizable toolbar, pass replay iframe messages to parent) - Support export as module, build separate index.js for module in addition to ui.js - Update to wabac.js 2.20.0 - bump to 2.2.0
1 parent 91dd5ad commit 95c9be6

18 files changed

+376
-348
lines changed

CHANGES.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,53 @@
22

33
## CHANGES
44

5+
v2.2.0
6+
- Extensability: additional override options for AWP, make location toolbar more extensible
7+
- Extensability: support importing as module via dist/index.js, separate from ui.js
8+
- Deps: update to wabac.js 2.20.0, typescript support
9+
510
v2.1.5
11+
612
- Fidelity: updated rewriting rules for instagram
713
- Fidelity: disable window online/offline events in replay (via wabac.js)
814
- Dependencies: update to wabac.js 2.19.9 + wombat 3.8.2, electron 32.1.0
915

1016
v2.1.4
17+
1118
- Fidelity: improvements to FB rewriting, eval() rewriting, 'object' tag rewriting (via wabac.js 2.19.7, wombat 3.7.14)
1219

1320
v2.1.3
21+
1422
- Fidelity: edge-case rewriting improvements, avoid rewriting inside of strings, detect old-html framesets (via wabac.js 2.19.5, wombat 3.7.12)
1523

1624
v2.1.2
25+
1726
- Fidelity: Video replay improvements, fix rewriting of DASH manifests (via wabac.js 2.19.4, wombat 3.7.11)
1827

1928
v2.1.1
29+
2030
- Fidelity: fixes to Sharepoint site replay (via wabac.js 2.19.2, wombat 3.7.10)
2131
- UI: default URL resources search to 'prefix' as contains only works after prefix search
2232

2333
v2.1.0
34+
2435
- More fidelity fixes (via wabac.js 2.19.1, wombat 3.7.8)
2536
- Improved messaging: embed tag emits @rwp-page-loading and @rwp-url-change events
2637
- Remove multiTs from hashtag, avoid double history nav as it was being set
2738

2839
v2.0.2
40+
2941
- Fidelity improvements (via wabac.js 2.18.4 and wombat 3.7.7), including improved encoding detection
3042
- Upgrade Shoelace & Lit by @SuaYoo in https://github.com/webrecorder/replayweb.page/pull/329
3143
- Adds multi-resolution ICO file for Windows by @Shrinks99 in https://github.com/webrecorder/replayweb.page/pull/325
3244
- Resource search remove auto-added http prefix by @ikreymer in https://github.com/webrecorder/replayweb.page/pull/334
3345
- Configure package exports explicitly by @emma-sg in https://github.com/webrecorder/replayweb.page/pull/336
3446

3547
v2.0.1
48+
3649
- Fidelity improvements (via wabac.js and wombat), including fixes ebay carousel #326 (via wombat)
3750
- partial fix to error page escaping #323 (via wabac)
38-
fixes to reddit pages #317
51+
- fixes to reddit pages #317
3952
- Fixes to twitter/x replay (via wabac / wombat)
4053
- Build improvements: run mkdocs gh-deploy --force in gh action, instead of publish-docs to avoid accidental updates
4154
- Auto install ruffle from download script, remove from git, add 'update-ruffle' script
@@ -69,7 +82,6 @@ v2.0.0
6982
- build(deps): bump loader-utils from 2.0.0 to 2.0.4 by @dependabot in https://github.com/webrecorder/replayweb.page/pull/316
7083
- 2.0.0 Release by @SuaYoo in https://github.com/webrecorder/replayweb.page/pull/269
7184

72-
7385
v1.8.17
7486

7587
- Dependencies: update to wabac.js 2.17.3, wombat 3.7.3

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ The static assets are placed in the root `index.html`, `sw.js`, and `ui.js`, and
7272

7373
The full site with docs is built using MkDocs. Using the `yarn build-docs` command, the static assets are copied into `mkdocs/site/` and using Markdown in `mkdocs/site/docs`, the final static site is built to `mkdocs/_genhtml`. This is what is published to https://replayweb.page/ via CI.
7474

75-
7675
### Service Worker Requirements
7776

7877
Note that for the 'backend' service worker to work, the static site must be served from either localhost or an HTTPS endpoint.

package.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "replaywebpage",
33
"productName": "ReplayWeb.page",
4-
"version": "2.1.5",
4+
"version": "2.2.0",
55
"description": "Serverless Web Archive Replay",
66
"repository": "https://github.com/webrecorder/replayweb.page",
77
"homepage": "https://replayweb.page/",
@@ -10,19 +10,15 @@
1010
"exports": {
1111
".": {
1212
"types": "./dist/types/index.d.ts",
13-
"default": "./ui.js"
14-
},
15-
"./misc": {
16-
"types": "./dist/types/misc.d.ts",
17-
"default": "./dist/misc.js"
13+
"default": "./dist/index.js"
1814
},
1915
"./src/electron-*": "./src/electron-*.ts",
2016
"./index.html": "./index.html"
2117
},
2218
"dependencies": {
2319
"@fortawesome/fontawesome-free": "^5.15.4",
2420
"@shoelace-style/shoelace": "~2.15.1",
25-
"@webrecorder/wabac": "^2.19.9",
21+
"@webrecorder/wabac": "^2.20.0",
2622
"bulma": "^0.9.3",
2723
"electron-log": "^4.4.1",
2824
"electron-updater": "^6.3.2",
@@ -75,8 +71,7 @@
7571
"webpack-merge": "^5.10.0"
7672
},
7773
"resolutions": {
78-
"**/lit": "3.1.1",
79-
"@webrecorder/wabac": "^2.19.9"
74+
"**/lit": "3.1.1"
8075
},
8176
"files": [
8277
"/dist",

scripts/build-if-not-git-repo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const git = (args) => cp.spawnSync("git", args, { stdio: "inherit" });
2727
// That's why status value needs to be checked explicitly
2828
if (git(["rev-parse"]).status !== 0 || process.argv.includes("--force")) {
2929
l(`git command not found, running build`);
30-
const compiler = webpack(config.map((c) => c()));
30+
const compiler = webpack(config.map((c) => c(process.env, process.argv)));
3131

3232
compiler.run((err) => {
3333
if (err) {

src/appmain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class ReplayWebApp extends LitElement {
7878
swErrorMsg: TemplateResult<1> | string | null = null;
7979

8080
protected swName?: string;
81-
private swmanager: SWManager | null;
81+
protected swmanager: SWManager | null;
8282
private useRuffle = false;
8383

8484
private droppedFile: File | null = null;

src/chooser.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import fasUpload from "@fortawesome/fontawesome-free/svgs/solid/upload.svg";
55
import { customElement, property } from "lit/decorators.js";
66

77
export interface FileWithPath extends File {
8-
readonly path: string;
8+
path: string;
99
}
1010

11+
declare let window: Window & {
12+
electron?: {
13+
getPath: (file: File) => string;
14+
};
15+
};
16+
1117
// ===========================================================================
1218
@customElement("wr-chooser")
1319
export class Chooser extends LitElement {
@@ -89,6 +95,10 @@ export class Chooser extends LitElement {
8995
setFile(file: FileWithPath) {
9096
this.file = file;
9197
// file.path only available in electron app
98+
if (IS_APP && window.electron?.getPath) {
99+
this.file.path = window.electron.getPath(this.file);
100+
}
101+
92102
this.fileDisplayName = "file://" + (file.path || file.name);
93103
}
94104

src/electron-preload.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
/*eslint-env node */
22

3-
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/loaders'. 'node_modules/@webrecorder/wabac/src/loaders.js' implicitly has an 'any' type.
4-
import { CollectionLoader } from "@webrecorder/wabac/src/loaders";
3+
import { CollectionLoader } from "@webrecorder/wabac/swlib";
54
import { type IpcRendererEvent } from "electron";
65

7-
const { ipcRenderer, contextBridge } = require("electron");
6+
const { ipcRenderer, contextBridge, webUtils } = require("electron");
87

9-
contextBridge.exposeInMainWorld("electron", { IS_APP: true });
8+
contextBridge.exposeInMainWorld("electron", {
9+
IS_APP: true,
10+
getPath(file: File) {
11+
return webUtils.getPathForFile(file);
12+
},
13+
});
1014

1115
const dbs = {};
1216

src/electron-replay-app.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616
import path from "path";
1717
import fs from "fs";
1818

19-
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7016 - Could not find a declaration file for module '@webrecorder/wabac/src/rewrite'. 'node_modules/@webrecorder/wabac/src/rewrite/index.js' implicitly has an 'any' type.
20-
import { ArchiveResponse, Rewriter } from "@webrecorder/wabac/src/rewrite";
19+
import { ArchiveResponse, Rewriter } from "@webrecorder/wabac";
2120

2221
import { PassThrough, Readable } from "stream";
2322

@@ -414,7 +413,7 @@ class ElectronReplayApp {
414413
headers = new Headers(headers);
415414
const date = new Date();
416415

417-
let response = new ArchiveResponse({
416+
let response: ArchiveResponse = new ArchiveResponse({
418417
payload,
419418
headers,
420419
status,
@@ -443,6 +442,9 @@ class ElectronReplayApp {
443442
headers = Object.fromEntries(response.headers.entries());
444443

445444
let data = await response.getBuffer();
445+
if (!data) {
446+
data = new Uint8Array();
447+
}
446448

447449
if (status === 206 || status === 200) {
448450
const { statusCode, start, end } = this.parseRange(
@@ -456,9 +458,9 @@ class ElectronReplayApp {
456458
status = statusCode;
457459
}
458460

459-
data = this._bufferToStream(data);
461+
const result = this._bufferToStream(data);
460462

461-
callback({ statusCode: status, headers, data });
463+
callback({ statusCode: status, headers, data: result });
462464
} catch (e) {
463465
console.warn(e);
464466
}

src/embed.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Embed extends LitElement {
8585
replayfile = defaultReplayFile;
8686
mainElementName = "replay-app-main";
8787
appName = "ReplayWeb.page";
88-
customConfig = null;
88+
customConfig: Record<string, string | boolean> | null = null;
8989
reloadCount = 0;
9090

9191
isCrossOrigin: boolean | undefined;
@@ -255,14 +255,11 @@ class Embed extends LitElement {
255255
}
256256

257257
mergeConfigs() {
258-
// TODO: Fix this the next time the file is edited.
259-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
260258
if (!this.customConfig) {
261259
return this.config;
262260
}
263261

264262
if (this.config) {
265-
// @ts-expect-error - TS2339 - Property 'customConfig' does not exist on type 'Embed'. | TS2339 - Property 'config' does not exist on type 'Embed'.
266263
const config = { ...this.customConfig, ...JSON.parse(this.config) };
267264
return JSON.stringify(config);
268265
} else {

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Pages } from "./pages";
1010
import { PageEntry } from "./pageentry";
1111
import { Replay } from "./replay";
1212
import { Sorter } from "./sorter";
13+
import { SWManager } from "./swmanager";
1314
import { URLResources } from "./url-resources";
1415
import { Embed } from "./embed";
1516
import "./shoelace";
@@ -41,6 +42,9 @@ export {
4142
Sorter,
4243
URLResources,
4344
Embed,
45+
SWManager,
4446
};
4547

4648
export type { ItemType, URLResource } from "./types";
49+
50+
export * from "./misc";

0 commit comments

Comments
 (0)