Skip to content

Commit af7dc7a

Browse files
authored
Electron app loading improvements + Windows paths fix (#429)
- Electron no longer allows Windows paths in URLs (https://www.electronjs.org/docs/latest/breaking-changes#behavior-changed-custom-protocol-url-handling-on-windows), fixes with help of wabac.js to replace `C:\path\to\file` with `C//path/to/file` - Electron app cleanup: replace deprecated protocol handlers with new protocol.handle() method, update types - Electron app: ensure just filename is displayed on index page, consistent with other platforms - Update to wabac.js 2.23.2 - Update to Electron 36.3.2 - Fixes #427 - bump to 2.3.12
1 parent e4daded commit af7dc7a

12 files changed

+289
-332
lines changed

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
## CHANGES
44

5+
v2.3.12
6+
7+
- App: Cleanup Electron app code and add typing
8+
- App: fix loading files from disk on Windows, existing files should continue to load
9+
- Fidelity: Fix meta refresh rewriting (via wabac.js 2.23.2)
10+
511
v2.3.11
12+
613
- Fidelity: Fix to importmaps (via wabac.js 2.23.1)
714

815
v2.3.10
16+
917
- Dependencies: Update Electron dependencies
1018

1119
v2.3.9
20+
1221
- Loading: Avoid unnecessary reloads of multiWACZ JSON, prune expired (via wabac.js 2.23.0)
1322
- Fidelity: Fix CSP issue with iframes in Firefox (via wabac.js 2.23.0)
1423
- Testing: Add testing for CSP handling and embeds in Firefox and Webkit

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "replaywebpage",
33
"productName": "ReplayWeb.page",
4-
"version": "2.3.11",
4+
"version": "2.3.12",
55
"description": "Serverless Web Archive Replay",
66
"repository": "https://github.com/webrecorder/replayweb.page",
77
"homepage": "https://replayweb.page/",
@@ -22,20 +22,19 @@
2222
"dependencies": {
2323
"@fortawesome/fontawesome-free": "^5.15.4",
2424
"@shoelace-style/shoelace": "~2.15.1",
25-
"@webrecorder/wabac": "^2.23.1",
25+
"@webrecorder/wabac": "^2.23.2",
2626
"bulma": "^0.9.3",
2727
"electron-log": "^4.4.1",
28-
"electron-updater": "^6.3.9",
28+
"electron-updater": "^6.6.2",
2929
"fetch-ndjson": "^1.1.6",
3030
"flexsearch": "^0.7.31",
3131
"keyword-mark-element": "^0.2.0",
3232
"lit": "3.1.1",
3333
"marked": "^4.0.10",
3434
"micromark": "^4.0.1",
3535
"micromark-extension-gfm-strikethrough": "^2.1.0",
36-
"mime-types": "^2.1.32",
36+
"mime-types": "^3.0.1",
3737
"minimist": "^1.2.5",
38-
"node-fetch": "^3.3.0",
3938
"pretty-bytes": "^5.6.0",
4039
"process": "^0.11.10",
4140
"register-service-worker": "^1.7.2",
@@ -47,11 +46,14 @@
4746
"@playwright/test": "^1.52.0",
4847
"@types/flexsearch": "^0.7.3",
4948
"@types/lodash": "^4.17.5",
49+
"@types/mime-types": "^2.1.4",
50+
"@types/minimist": "^1.2.5",
51+
"@types/node": "^22.15.18",
5052
"@typescript-eslint/eslint-plugin": "^6.12.0",
5153
"@typescript-eslint/parser": "^6.12.0",
5254
"copy-webpack-plugin": "^9.0.1",
5355
"css-loader": "^6.2.0",
54-
"electron": "^36.2.1",
56+
"electron": "^36.3.2",
5557
"electron-builder": "^26.0.12",
5658
"electron-notarize": "^1.2.2",
5759
"eslint": "^8.56.0",

playwright.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export default defineConfig({
66
projects: [
77
{
88
name: "chrome",
9-
use: { ...devices['Desktop Chrome'], channel: "chrome" },
9+
use: { ...devices["Desktop Chrome"], channel: "chrome" },
1010
},
1111
{
12-
name: 'firefox',
13-
use: { ...devices['Desktop Firefox'] },
12+
name: "firefox",
13+
use: { ...devices["Desktop Firefox"] },
1414
},
1515
{
16-
name: 'webkit',
17-
use: { ...devices['Desktop Safari'] },
16+
name: "webkit",
17+
use: { ...devices["Desktop Safari"] },
1818
},
1919
],
2020
webServer: [

src/appmain.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,6 @@ export class ReplayWebApp extends LitElement {
639639
if (this.pageParams.get("swName")) {
640640
this.swName = this.pageParams.get("swName") || undefined;
641641
}
642-
643-
if (IS_APP && this.sourceUrl.startsWith("file://")) {
644-
this.loadInfo = {
645-
sourceUrl: this.sourceUrl,
646-
loadUrl: this.sourceUrl.replace("file://", "file2://"),
647-
};
648-
}
649642
}
650643

651644
// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.

src/chooser.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +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-
path: string;
8+
path?: string;
99
}
1010

1111
declare let window: Window & {
1212
electron?: {
13-
getPath: (file: File) => string;
13+
getPaths: (file: File) => {
14+
loadUrl: string;
15+
sourceUrl: string;
16+
};
1417
};
1518
};
1619

@@ -94,12 +97,13 @@ export class Chooser extends LitElement {
9497

9598
setFile(file: FileWithPath) {
9699
this.file = file;
97-
// file.path only available in electron app
98-
if (IS_APP && window.electron?.getPath) {
99-
this.file.path = window.electron.getPath(this.file);
100+
if (IS_APP && window.electron?.getPaths) {
101+
const { loadUrl, sourceUrl } = window.electron.getPaths(this.file);
102+
this.file.path = loadUrl;
103+
this.fileDisplayName = sourceUrl;
104+
} else {
105+
this.fileDisplayName = "file://" + file.name;
100106
}
101-
102-
this.fileDisplayName = "file://" + (file.path || file.name);
103107
}
104108

105109
async onChooseNativeFile() {
@@ -149,9 +153,11 @@ export class Chooser extends LitElement {
149153

150154
if (this.file) {
151155
loadInfo.isFile = true;
152-
// file.path only available in electron app
156+
// should only be set in Electron app
153157
if (this.file.path) {
154-
loadInfo.loadUrl = "file2://" + this.file.path;
158+
loadInfo.loadUrl = this.file.path;
159+
loadInfo.sourceUrl = this.fileDisplayName;
160+
loadInfo.name = this.file.name;
155161
loadInfo.noCache = true;
156162
} else if (this.fileHandle) {
157163
loadInfo.loadUrl = this.fileDisplayName;
@@ -163,7 +169,9 @@ export class Chooser extends LitElement {
163169
loadInfo.noCache = false;
164170
}
165171
loadInfo.size = this.file.size;
166-
loadInfo.name = this.fileDisplayName;
172+
if (!loadInfo.name) {
173+
loadInfo.name = this.fileDisplayName;
174+
}
167175
}
168176

169177
this.dispatchEvent(

src/electron-preload.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,34 @@
33
import { CollectionLoader } from "@webrecorder/wabac/swlib";
44
import { type IpcRendererEvent } from "electron";
55

6-
const { ipcRenderer, contextBridge, webUtils } = require("electron");
6+
import { sep as pathSep } from "node:path";
7+
8+
import { ipcRenderer, contextBridge, webUtils } from "electron";
9+
10+
const FILE_SCHEME = "file://";
11+
const CUSTOM_FILE_SCHEME = "file2://";
12+
13+
function rewriteLoadUrl(loadUrl: string) {
14+
if (pathSep !== "/") {
15+
// for windows, will replace such that C:\path\to\file becomes C//path/to/file
16+
loadUrl = loadUrl.replaceAll(pathSep, "/").replace(":", "/");
17+
}
18+
return CUSTOM_FILE_SCHEME + loadUrl;
19+
}
720

821
contextBridge.exposeInMainWorld("electron", {
922
IS_APP: true,
10-
getPath(file: File) {
11-
return webUtils.getPathForFile(file);
23+
getPaths(file: File) {
24+
const url = webUtils.getPathForFile(file);
25+
const sourceUrl = FILE_SCHEME + url;
26+
const loadUrl = rewriteLoadUrl(url);
27+
return { loadUrl, sourceUrl };
28+
},
29+
getFileLoadUrl(sourceUrl: string) {
30+
if (!sourceUrl.startsWith(FILE_SCHEME)) {
31+
return sourceUrl;
32+
}
33+
return rewriteLoadUrl(sourceUrl.slice(FILE_SCHEME.length));
1234
},
1335
});
1436

0 commit comments

Comments
 (0)