我试图为 Firefox 构建一个扩展并且正在阅读Mozilla 的教程,但是很快就卡住了,现在我需要一些说明。
因此,我正在考虑添加一个侧边栏,其中将包含许多按钮(例如,它将是一个表情符号选择器,当用户按下它时,每个按钮都会向特定字段添加一个表情符号)和其他东西。
清单.json:
{
"manifest_version": 2,
"name": "Test extension",
"description": "Just a test extension.",
"version": "1.0",
"browser_specific_settings": {
"gecko": {
"strict_min_version": "54.0a1"
}
},
"sidebar_action": {
"default_icon": "icons/star.png",
"default_title" : "Test sidebar",
"default_panel": "ui/sidebar.html"
},
"permissions": ["storage", "tabs"],
"commands": {
"_execute_sidebar_action": {
"suggested_key": {
"default": "Ctrl+Shift+Y"
}
}
}
}
边栏.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="panel.css"/>
<title>Test sidebar</title>
<script src="panel.js"></script>
</head>
<body>
<input type="text" id="textField"/>
<input type="button" onclick="addText()" value="Add Text"/>
</body>
</html>
面板.js:
function addText() {
document.getElementById("textField").value += "Text";
}
但是,事实证明,由于某种原因,我侧边栏中的 JavaScript 不起作用(我单击了一个按钮,但没有任何反应),而在像 Codepen这样的网站上却可以,但我不明白为什么:它是扩展的限制吗? 难道我做错了什么?因此,我们将不胜感激有什么问题的提示。谢谢。