Skip to content

Commit 6dc9c15

Browse files
cyfung1031CodFrm
andauthored
🐛 针对 WebExtensions API Changes (Firefox 149-152) 做修正 (#1448)
* 针对 WebExtensions API Changes (Firefox 149-152) 做修正 * 🔒 调整 MV2 内容安全策略 --------- Co-authored-by: 王一之 <yz@ggnb.top>
1 parent b878736 commit 6dc9c15

5 files changed

Lines changed: 24 additions & 21 deletions

File tree

build/assets/template/background.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
<html>
33
<head>
44
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Background</title>
57
</head>
68
<body>
79
<iframe
810
src="/src/sandbox.html"
911
name="sandbox"
10-
sandbox="allow-scripts"
11-
style="display: none"
12+
sandbox="allow-same-origin allow-scripts"
13+
hidden
14+
aria-hidden="true"
15+
tabindex="-1"
1216
></iframe>
1317
</body>
1418
</html>

build/assets/template/options.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
<iframe
1111
src="/src/sandbox.html"
1212
name="sandbox"
13-
sandbox="allow-scripts"
14-
style="display: none"
13+
sandbox="allow-same-origin allow-scripts"
14+
hidden
15+
aria-hidden="true"
16+
tabindex="-1"
1517
></iframe>
1618
</body>
1719
<style>

build/assets/template/sandbox.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,8 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
65
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<script>
8-
// 某些版本浏览器会因为sandbox中引用了dexie执行此方法导致报错,这里mock一个假的
9-
window.BroadcastChannel = function () {
10-
return {
11-
postMessage: function () {},
12-
close: function () {},
13-
};
14-
};
15-
</script>
16-
<title>Document</title>
6+
<title>Sandbox</title>
177
</head>
188
<body></body>
199
</html>

build/pack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const chromeManifest = { ...manifest };
7575
delete chromeManifest.content_security_policy;
7676

7777
delete firefoxManifest.sandbox;
78-
// firefoxManifest.content_security_policy 是为了支持动态组合的 ts.worker.js Blob URL
79-
firefoxManifest.content_security_policy = "script-src 'self' blob:; object-src 'self' blob:";
78+
// 配置 Firefox 的 CSP,以支持在 sandbox 中动态执行 background script 代码
79+
firefoxManifest.content_security_policy = "script-src 'self' blob: 'unsafe-eval'; object-src 'self' blob:";
8080
firefoxManifest.browser_specific_settings = {
8181
gecko: {
8282
id: `{${

src/manifest.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
},
2121
"content_scripts": [
2222
{
23-
"matches": ["<all_urls>"],
24-
"js": ["src/content.js"],
23+
"matches": [
24+
"<all_urls>"
25+
],
26+
"js": [
27+
"src/content.js"
28+
],
2529
"run_at": "document_start",
2630
"all_frames": true
2731
}
@@ -40,6 +44,9 @@
4044
"webRequestBlocking"
4145
],
4246
"sandbox": {
43-
"pages": ["src/sandbox.html"]
44-
}
47+
"pages": [
48+
"src/sandbox.html"
49+
]
50+
},
51+
"content_security_policy": "script-src 'self' blob: 'unsafe-eval'; object-src 'self' blob:"
4552
}

0 commit comments

Comments
 (0)