Skip to content

Commit 372ec0c

Browse files
committed
disable csp for chromium >= 94 to deal with https://bugs.chromium.org/p/chromium/issues/detail?id=1245803
fixes #53 bump to 0.7.3
1 parent d73d94c commit 372ec0c

File tree

7 files changed

+69
-10
lines changed

7 files changed

+69
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "archiveweb.page",
3-
"version": "0.7.2",
3+
"version": "0.7.3",
44
"main": "index.js",
55
"description": "Create Web Archives directly in your browser",
66
"repository": "https://github.com/webrecorder/archiveweb.page",

src/ext/bg.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const openWinMap = new Map();
1818

1919
const collLoader = new CollectionLoader();
2020

21+
const disabledCSPTabs = new Set();
22+
2123
let ipfsClient = null;
2224

2325

@@ -312,6 +314,10 @@ chrome.runtime.onMessage.addListener(async (message, /*sender, sendResponse*/) =
312314
newRecCollId = message.collId;
313315
chrome.tabs.create({url: "about:blank"});
314316
break;
317+
318+
case "disableCSP":
319+
disableCSPForTab(message.tabId);
320+
break;
315321
}
316322
});
317323

@@ -327,3 +333,31 @@ async function initIpfs() {
327333
}
328334

329335
initIpfs();
336+
337+
// ===========================================================================
338+
async function disableCSPForTab(tabId) {
339+
if (disabledCSPTabs.has(tabId)) {
340+
return;
341+
}
342+
343+
await new Promise((resolve) => {
344+
chrome.debugger.attach({tabId}, "1.3", () => { resolve(); });
345+
});
346+
347+
await new Promise((resolve) => {
348+
chrome.debugger.sendCommand({tabId}, "Page.setBypassCSP", {enabled: true}, (resp) => resolve(resp));
349+
});
350+
351+
disabledCSPTabs.add(tabId);
352+
353+
// hacky: don't detach if any recorders are running, otherwise will disconnect
354+
for (const rec of Object.values(self.recorders)) {
355+
if (rec.running) {
356+
return;
357+
}
358+
}
359+
360+
await new Promise((resolve) => {
361+
chrome.debugger.detach({tabId}, () => { resolve();});
362+
});
363+
}

src/ui/app.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class ArchiveWebApp extends ReplayWebApp
8080
}
8181

8282
getLoadInfo(sourceUrl) {
83+
this.disableCSP();
84+
8385
if (this.loadInfo) {
8486
return this.loadInfo;
8587
}
@@ -89,6 +91,29 @@ class ArchiveWebApp extends ReplayWebApp
8991
return {customColl};
9092
}
9193

94+
async disableCSP() {
95+
// necessary for chrome 94> up due to new bug introduced
96+
//
97+
if (!self.chrome || !self.chrome.runtime) {
98+
return;
99+
}
100+
101+
const m = navigator.userAgent.match(/Chrome\/([\d]+)/);
102+
if (!m || Number(m[1]) < 94) {
103+
return;
104+
}
105+
106+
console.log("attempt to disable CSP to ensure replay works");
107+
let tabId = await new Promise((resolve) => {
108+
chrome.tabs.getCurrent((msg) => resolve(msg.id));
109+
});
110+
111+
chrome.runtime.sendMessage({
112+
msg: "disableCSP",
113+
tabId
114+
});
115+
}
116+
92117
static get styles() {
93118
return wrapCss(ArchiveWebApp.appStyles);
94119
}

wr-ext/bg.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wr-ext/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Webrecorder ArchiveWeb.page",
33
"description": "Create high-fidelity web archives directly in your browser",
4-
"version": "0.7.2",
4+
"version": "0.7.3",
55
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
66
"permissions": [
77
"debugger",

wr-ext/replay/sw.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wr-ext/replay/ui.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)