Skip to content

Commit a778aba

Browse files
committed
MV3 support work:
rename chrome.browserAction -> chrome.action include ext/bg.js in sw/main.js (addresses #131) move replay root to ./ from ./replay/ dynamically import sw.js from bg.js, use bg.js as service-worker entrypoint ipfs: add Origin header overrides via declarative-net-request rules, also add as permission via brave-ipfs.json rules bump version to 0.10.0
1 parent 351f6fb commit a778aba

File tree

13 files changed

+111
-42
lines changed

13 files changed

+111
-42
lines changed

dist/embed/replay/sw.js renamed to dist/embed/sw.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/embed/ui.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@webrecorder/archivewebpage",
33
"productName": "ArchiveWeb.page",
4-
"version": "0.9.7",
4+
"version": "0.10.0",
55
"main": "index.js",
66
"description": "Create Web Archives directly in your browser",
77
"repository": "https://github.com/webrecorder/archiveweb.page",

src/electron/app-popup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ class AppRecPopup extends RecPopup
7575
}
7676

7777
getHomePage() {
78-
return "replay/index.html";
78+
return "index.html";
7979
}
8080

8181
get extRoot() {
8282
return "";
8383
}
8484
}
8585

86-
customElements.define("wr-app-popup", AppRecPopup);
86+
customElements.define("wr-app-popup", AppRecPopup);

src/electron/electron-recorder-app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ElectronRecorderApp extends ElectronReplayApp
9292
}
9393

9494
get mainWindowUrl() {
95-
return "replay/index.html";
95+
return "index.html";
9696
}
9797

9898
createMainWindow(argv) {

src/ext/bg.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const disabledCSPTabs = new Set();
2727
// ===========================================================================
2828

2929
function main() {
30-
chrome.browserAction.setBadgeBackgroundColor({color: "#64e986"});
30+
chrome.action.setBadgeBackgroundColor({color: "#64e986"});
3131

3232
chrome.contextMenus.create({"id": "toggle-rec", "title": "Start Recording", "contexts": ["browser_action"]});
3333
chrome.contextMenus.create({"id": "view-rec", "title": "View Web Archives", "contexts": ["all"]});
@@ -178,7 +178,7 @@ chrome.tabs.onRemoved.addListener((tabId) => {
178178
chrome.contextMenus.onClicked.addListener((info, tab) => {
179179
switch (info.menuItemId) {
180180
case "view-rec":
181-
chrome.tabs.create({ url: chrome.runtime.getURL("replay/index.html") });
181+
chrome.tabs.create({ url: chrome.runtime.getURL("index.html") });
182182
break;
183183

184184
case "toggle-rec":
@@ -296,3 +296,7 @@ async function disableCSPForTab(tabId) {
296296

297297
// ===========================================================================
298298
chrome.runtime.onInstalled.addListener(main);
299+
300+
if (self.importScripts) {
301+
self.importScripts("sw.js");
302+
}

src/ext/browser-recorder.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ class BrowserRecorder extends Recorder {
209209
color = "#64e986";
210210
}
211211

212-
chrome.browserAction.setTitle({title, tabId});
213-
chrome.browserAction.setBadgeBackgroundColor({color, tabId});
214-
chrome.browserAction.setBadgeText({text, tabId});
212+
chrome.action.setTitle({title, tabId});
213+
chrome.action.setBadgeBackgroundColor({color, tabId});
214+
chrome.action.setBadgeText({text, tabId});
215215

216216
if (this.port) {
217217
const status = this.getStatusMsg();

src/ext/manifest.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@
22
"name": "Webrecorder ArchiveWeb.page",
33
"description": "Create high-fidelity web archives directly in your browser",
44
"version": "$VERSION",
5-
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
6-
"permissions": ["debugger", "contextMenus", "tabs", "activeTab", "storage", "unlimitedStorage", "webRequest", "webRequestBlocking", "ipfs", "<all_urls>"],
5+
"permissions": ["debugger", "contextMenus", "tabs", "activeTab", "storage", "unlimitedStorage", "webRequest", "ipfs", "declarativeNetRequest"],
76
"background": {
8-
"scripts": ["bg.js"],
9-
"persistent": true
7+
"service_worker": "bg.js"
108
},
119
"icons": {
1210
"32": "$ICON",
1311
"128": "$ICON"
1412
},
15-
"browser_action": {
13+
"action": {
1614
"default_icon": {
1715
"32": "$ICON"
1816
},
1917
"default_title": "Webrecorder ArchiveWeb.page",
2018
"default_popup": "popup.html"
2119
},
22-
"web_accessible_resources": [
23-
"pdf/*",
24-
"replay/*",
25-
"ruffle/*"
26-
],
27-
"manifest_version": 2
20+
"declarative_net_request": {
21+
"rule_resources": [{
22+
"id": "brave-ipfs",
23+
"enabled": true,
24+
"path": "brave-ipfs.json"
25+
}]
26+
},
27+
"web_accessible_resources": [{
28+
"resources": [
29+
"pdf/*",
30+
"ruffle/*"
31+
],
32+
"matches": ["*://*/*"]
33+
}],
34+
"host_permissions": ["*://*/*"],
35+
"content_security_policy": {
36+
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
37+
},
38+
"manifest_version": 3
2839
}

src/popup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class RecPopup extends LitElement
108108
if (tabs.length) {
109109
this.tabId = tabs[0].id;
110110
this.pageUrl = tabs[0].url;
111-
chrome.browserAction.getTitle({tabId: this.tabId}, (result) => {
111+
chrome.action.getTitle({tabId: this.tabId}, (result) => {
112112
this.recording = (result.indexOf("Recording:") >= 0);
113113
});
114114

@@ -205,7 +205,7 @@ class RecPopup extends LitElement
205205
}
206206

207207
getHomePage() {
208-
return chrome.runtime.getURL("replay/index.html");
208+
return chrome.runtime.getURL("index.html");
209209
}
210210

211211
get extRoot() {

src/static/brave-ipfs.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[
2+
{
3+
"id": 10,
4+
"priority": 2,
5+
"action": {
6+
"type": "modifyHeaders",
7+
"requestHeaders": [
8+
{ "header": "Origin", "operation": "set", "value": "http://localhost:5001" }
9+
]
10+
},
11+
"condition": { "urlFilter": "localhost:5001", "resourceTypes": ["xmlhttprequest"] }
12+
},
13+
{
14+
"id": 1,
15+
"priority": 2,
16+
"action": {
17+
"type": "modifyHeaders",
18+
"requestHeaders": [
19+
{ "header": "Origin", "operation": "set", "value": "http://localhost:45001" }
20+
]
21+
},
22+
"condition": { "urlFilter": "localhost:45001", "resourceTypes": ["xmlhttprequest"] }
23+
},
24+
{
25+
"id": 2,
26+
"priority": 2,
27+
"action": {
28+
"type": "modifyHeaders",
29+
"requestHeaders": [
30+
{ "header": "Origin", "operation": "set", "value": "http://localhost:45002" }
31+
]
32+
},
33+
"condition": { "urlFilter": "localhost:45002", "resourceTypes": ["xmlhttprequest"] }
34+
},
35+
{
36+
"id": 3,
37+
"priority": 2,
38+
"action": {
39+
"type": "modifyHeaders",
40+
"requestHeaders": [
41+
{ "header": "Origin", "operation": "set", "value": "http://localhost:45003" }
42+
]
43+
},
44+
"condition": { "urlFilter": "localhost:45003", "resourceTypes": ["xmlhttprequest"] }
45+
},
46+
{
47+
"id": 4,
48+
"priority": 2,
49+
"action": {
50+
"type": "modifyHeaders",
51+
"requestHeaders": [
52+
{ "header": "Origin", "operation": "set", "value": "http://localhost:45004" }
53+
]
54+
},
55+
"condition": { "urlFilter": "localhost:45004", "resourceTypes": ["xmlhttprequest"] }
56+
},
57+
{
58+
"id": 5,
59+
"priority": 2,
60+
"action": {
61+
"type": "modifyHeaders",
62+
"requestHeaders": [
63+
{ "header": "Origin", "operation": "set", "value": "http://localhost:45005" }
64+
]
65+
},
66+
"condition": { "urlFilter": "localhost:45005", "resourceTypes": ["xmlhttprequest"] }
67+
}
68+
]

0 commit comments

Comments
 (0)