Skip to content

Commit e49ae7c

Browse files
committed
electron app:
- switch back to <webview> instead of browser window for recording window to avoid crash on pages with iframes - rename locationbar.js -> rec-window.js, load app-popup in same window - rec-window uses context isolation for messaging - always leave space for icon, to avoid weird resize - move popup.js to base src from ext general: - ui: start recording modal: dropdown uses native select, show current URL as default if starting from replay - recorder: send request headers, not response headers for async fetch! bump to 0.5.8
1 parent 2c5cc85 commit e49ae7c

File tree

17 files changed

+294
-295
lines changed

17 files changed

+294
-295
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"name": "ArchiveWeb.page",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"main": "index.js",
55
"description": "Create Web Archives directly in your browser",
66
"repository": "https://github.com/webrecorder/archiveweb.page",
77
"author": "Webrecorder Software",
88
"license": "AGPL-3.0-or-later",
99
"dependencies": {
10-
"@electron/remote": "^1.0.2",
1110
"@fortawesome/fontawesome-free": "^5.13.0",
1211
"@webrecorder/wabac": "github:webrecorder/wabac.js",
1312
"bulma": "^0.9.1",

src/electron/app-popup.html

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

src/electron/app-popup.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ipcRenderer } from "electron";
2-
import { RecPopup } from "../ext/popup";
1+
//import { ipcRenderer } from "electron";
2+
import { RecPopup } from "../popup";
33

44
import { CollectionLoader } from '@webrecorder/wabac/src/loaders';
55
import { listAllMsg } from "../utils";
@@ -13,14 +13,17 @@ class AppRecPopup extends RecPopup
1313

1414
this.collLoader = new CollectionLoader();
1515

16-
this.tabId = window.location.hash && Number(window.location.hash.slice(1));
16+
//this.tabId = 0;//window.location.hash && Number(window.location.hash.slice(1));
1717

1818
this.allowCreate = false;
19+
20+
this.msg = null;
1921
}
2022

2123
static get properties() {
2224
return {
23-
...RecPopup.properties
25+
...RecPopup.properties,
26+
msg: { type: Object },
2427
}
2528
}
2629

@@ -32,10 +35,18 @@ class AppRecPopup extends RecPopup
3235
});
3336
}
3437

38+
updated(changedProperties) {
39+
super.updated(changedProperties);
40+
41+
if (changedProperties.has("msg")) {
42+
this.onMessage(this.msg);
43+
}
44+
}
45+
3546
registerMessages() {
36-
ipcRenderer.on("popup", (event, message) => {
37-
this.onMessage(message);
38-
});
47+
// ipcRenderer.on("popup", (event, message) => {
48+
// this.onMessage(message);
49+
// });
3950
}
4051

4152
sendMessage(message) {
@@ -44,7 +55,8 @@ class AppRecPopup extends RecPopup
4455
return;
4556
}
4657

47-
ipcRenderer.send("popup-msg-" + this.tabId, message);
58+
//ipcRenderer.send("popup-msg-" + this.tabId, message);
59+
this.dispatchEvent(new CustomEvent("send-msg", {detail: message}));
4860
}
4961

5062
async makeNewColl(message) {

src/electron/electron-recorder-app.js

Lines changed: 49 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {app, session, BrowserWindow, BrowserView, ipcMain, dialog} from 'electron';
1+
import {app, session, BrowserWindow, BrowserView, ipcMain, dialog, autoUpdater} from 'electron';
22
import { ElectronRecorder } from './electron-recorder';
33

44
import { ElectronReplayApp, STATIC_PREFIX } from 'replaywebpage/src/electron-replay-app';
@@ -9,9 +9,13 @@ import { PassThrough } from 'stream';
99
import fs from 'fs';
1010
import util from 'util';
1111

12+
1213
import { checkPins, ipfsAddWithReplay, ipfsUnpinAll } from '../utils';
1314

1415

16+
app.commandLine.appendSwitch('disable-features', 'CrossOriginOpenerPolicy');
17+
18+
1519
// ===========================================================================
1620
class ElectronRecorderApp extends ElectronReplayApp
1721
{
@@ -55,7 +59,7 @@ class ElectronRecorderApp extends ElectronReplayApp
5559
this.ipfsUnpin(event, reqId, pinList);
5660
});
5761

58-
require('@electron/remote/main').initialize();
62+
//require('@electron/remote/main').initialize();
5963

6064
super.onAppReady();
6165
}
@@ -112,73 +116,35 @@ class ElectronRecorderApp extends ElectronReplayApp
112116

113117
const recWindow = new BrowserWindow({
114118
width: this.screenSize.width,
115-
height: this.screenSize.height - 1,
119+
height: this.screenSize.height,
116120
isMaximized: true,
117121
show: true,
118122
webPreferences: {
119-
enableRemoteModule: true,
120-
nodeIntegration: true,
121-
contextIsolation: false
122-
}
123-
});
124-
125-
const view = new BrowserView({webPreferences: {
126-
partition: "persist:wr",
127-
plugins: false,
128123
contextIsolation: true,
124+
webviewTag: true,
125+
preload: path.join(__dirname, "rec-preload.js")
129126
}
130127
});
131128

132-
const id = view.webContents.id;
133-
134-
recWindow.loadURL(STATIC_PREFIX + "locbar.html#" + id);
135-
136-
const HEADER_HEIGHT = 73;
137-
recWindow.addBrowserView(view);
138-
view.setBounds({ x: 0, y: HEADER_HEIGHT, width: this.screenSize.width, height: this.screenSize.height - HEADER_HEIGHT });
139-
view.setAutoResize({width: true, height: true});
140-
recWindow.setSize(this.screenSize.width, this.screenSize.height);
141-
142-
recWindow.maximize();
143-
144-
const popupView = new BrowserView({webPreferences: {
145-
nodeIntegration: true,
146-
contextIsolation: false
147-
}});
129+
recWindow.webContents.on("did-attach-webview", (event, contents) => {
130+
this.initRecorder(recWindow, contents, url, collId, startRec);
131+
});
148132

149-
let popupShown = false;
133+
recWindow.loadURL(STATIC_PREFIX + "rec-window.html");
150134

151-
function setPopupBounds() {
152-
const bounds = recWindow.getBounds();
153-
popupView.setBounds({ x: bounds.width - 400, y: HEADER_HEIGHT - 22, width: 400, height: 300 });
154-
//popupView.webContents.openDevTools();
155-
}
135+
return recWindow;
136+
}
156137

157-
ipcMain.on("popup-toggle-" + id, (event) => {
158-
if (!popupShown) {
159-
recWindow.addBrowserView(popupView);
160-
setPopupBounds();
161-
popupView.webContents.loadURL(STATIC_PREFIX + "app-popup.html#" + id).then(() => {
162-
popupView.webContents.send("popup", {
163-
type: "status",
164-
recording: false,
165-
collId,
166-
pageUrl: url});
167-
});
168-
} else {
169-
recWindow.removeBrowserView(popupView);
170-
}
171-
popupShown = !popupShown;
172-
});
138+
checkUpdates() {
139+
autoUpdater.allowPrerelease = true;
140+
super.checkUpdates();
141+
}
173142

174-
recWindow.on('resize', (event) => {
175-
if (popupShown) {
176-
setPopupBounds();
177-
}
178-
});
143+
async initRecorder(recWindow, recWebContents, url, collId, startRec, popupView = null) {
144+
const id = recWebContents.id;
179145

180146
const recorder = new ElectronRecorder({
181-
recWC: view.webContents,
147+
recWC: recWebContents,
182148
appWC: this.mainWindow.webContents,
183149
recWindow,
184150
collId,
@@ -194,7 +160,9 @@ class ElectronRecorderApp extends ElectronReplayApp
194160
});
195161
});
196162

197-
popupView.webContents.on("new-window", (event, url, frameName, disposition, options, additionalFeatures, referrer) => {
163+
const newWinContents = popupView ? popupView.webContents : recWindow.webContents;
164+
165+
newWinContents.on("new-window", (event, url) => {
198166
event.preventDefault();
199167
if (url.startsWith(STATIC_PREFIX)) {
200168
this.mainWindow.loadURL(url);
@@ -206,7 +174,7 @@ class ElectronRecorderApp extends ElectronReplayApp
206174
switch (msg.type) {
207175
case "startRecording":
208176
await recorder.attach();
209-
view.webContents.reload();
177+
recWebContents.reload();
210178
break;
211179

212180
case "stopRecording":
@@ -215,37 +183,41 @@ class ElectronRecorderApp extends ElectronReplayApp
215183
}
216184
});
217185

218-
view.webContents.on("new-window", (event, url, frameName, disposition, options, additionalFeatures, referrer) => {
186+
recWebContents.on("new-window", (event, url, frameName, disposition, options, additionalFeatures, referrer) => {
219187
event.preventDefault();
220188
event.newGuest = this.createRecordWindow(url, collId, startRec);
221189
console.log("new-window", url, frameName, disposition, options, additionalFeatures, referrer);
222190
});
223191

224-
view.webContents.on("destroyed", () => {
192+
recWebContents.on("destroyed", () => {
225193
this.recorders.delete(id);
226194
});
227195

228-
(async () => {
229-
await view.webContents.loadURL("about:blank");
196+
//await recWebContents.loadURL("about:blank");
230197

231-
view.webContents.clearHistory();
232-
this.recorders.set(id, recorder);
233-
if (startRec) {
234-
await recorder.attach();
235-
}
198+
recWebContents.clearHistory();
236199

237-
if (process.env.NODE_ENV === "development") {
238-
view.webContents.openDevTools();
239-
}
200+
this.recorders.set(id, recorder);
201+
if (startRec) {
202+
await recorder.attach();
203+
} else {
204+
newWinContents.send("stats", {
205+
type: "status",
206+
recording: false,
207+
collId,
208+
pageUrl: url
209+
});
210+
}
240211

241-
try {
242-
view.webContents.loadURL(url);
243-
} catch (e) {
244-
console.warn("Load Failed", e);
245-
}
246-
})();
212+
if (process.env.NODE_ENV === "development") {
213+
//recWebContents.openDevTools();
214+
}
247215

248-
return recWindow;
216+
try {
217+
recWebContents.loadURL(url);
218+
} catch (e) {
219+
console.warn("Load Failed", e);
220+
}
249221
}
250222

251223
async ipfsStart(validPins) {

src/electron/rec-preload.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { ipcRenderer, contextBridge } = require('electron');
2+
3+
ipcRenderer.on("stats", (event, stats) => {
4+
window.postMessage({stats}, window.location.origin);
5+
});
6+
7+
contextBridge.exposeInMainWorld('archivewebpage', {
8+
sendMsg: (id, msg) => {
9+
ipcRenderer.send("popup-msg-" + id, msg);
10+
}
11+
});
12+

src/electron/locbar.html renamed to src/electron/rec-window.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
<head>
44
<style>
55
html, body {
6-
width: 100%;
7-
height: 73px;
6+
width: 100vw;
7+
height: 100vh;
88
overflow-y: hidden;
99
padding: 0px;
1010
margin: 0px;
11+
background-color: white;
1112
}
1213
</style>
13-
<script src="./locationbar.js"></script>
14+
<script src="./rec-window.js"></script>
1415
</head>
1516
<body>
16-
<wr-rec-location></wr-rec-location>
17+
<wr-rec-ui></wr-rec-ui>
1718
</body>
1819
</html>

0 commit comments

Comments
 (0)