forked from blocksecteam/metasuites
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirefox.js
82 lines (72 loc) · 2.09 KB
/
firefox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
function defineFirefoxManifestV2(manifestPath) {
const manifest = JSON.parse(fs.readFileSync(manifestPath))
manifest.manifest_version = 2
manifest.background = {
page: 'background.html'
}
manifest.web_accessible_resources = manifest.web_accessible_resources
.map(item => item.resources || item)
.flat()
if (manifest.action) {
manifest.browser_action = manifest.action
delete manifest.action
}
if (manifest.host_permissions) {
manifest.permissions = [
...manifest.permissions,
...manifest.host_permissions
]
delete manifest.host_permissions
}
manifest.content_security_policy =
"script-src 'self' 'unsafe-eval' http://localhost:3303; object-src 'self';"
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2))
}
// TODO: replace Function
function defineFirefoxManifestV3(manifestPath) {
const manifest = JSON.parse(fs.readFileSync(manifestPath))
// manifest.background = {
// scripts: ['service-worker-loader.js']
// }
manifest.background = {
page: 'background.html'
}
manifest.browser_specific_settings = {
gecko: {
id: '[email protected]'
}
}
manifest.web_accessible_resources = manifest.web_accessible_resources.map(
item => {
const obj = {}
for (const key in item) {
if (key !== 'use_dynamic_url') {
obj[key] = item[key]
}
}
return obj
}
)
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2))
}
function main() {
// Copy background.html to dist/
fs.cp(
path.join(__dirname, './', 'background.html'),
path.join(__dirname, '../dist/firefox-extension', 'background.html'),
err => {
if (err) throw err
}
)
// Smooth out the differences in the configuration file: chrome v3 => firefox v2
// TODO: Upgrade to firefox v3
defineFirefoxManifestV2(
path.join(__dirname, '../dist/firefox-extension', 'manifest.json')
)
}
main()