我使用了几个在content.js和popup.js之间共享的常量。如何将它们放在一个文件中并在两者之间共享?
这不起作用,global.js包含常量
{
"manifest_version": 2,
"name": "Test Extension",
"version": "0.0",
"background": {
"persistent": false,
"scripts": ["global.js", "background.js"]
},
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["global.js", "content.js"],
"run_at": "document_end"
}],
"browser_action": {
"default_title": "Test Extension",
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
]
}
global.js
var TEST = "test"
content.js / popup.js:
console.log(TEST)
在popup.js中打印TEST is not defined
答案 0 :(得分:0)
您仍需要将<script type="text/javascript" src="global.js"></script>
添加到HTML文件中。我认为在manifest.json