chrome 扩展在浏览器操作中插入内容脚本 [英] chrome extension insert content script on browser action
问题描述
我正在尝试制作一个基本的元素荧光笔 chrome 扩展.工作流程:- 点击浏览器图标- 点击页面- 突出显示点击的元素
I am trying to make basically an element highlighter chrome extension. Workflow: - click on browser icon - click on the page - hightlight the element clicked
我在使用 manifest_version:2 根据浏览器操作运行内容脚本时遇到问题当我检查出现的弹出窗口时,它说:
I am having troubles in running content scripts upon browser action using manifest_version:2 When I inspect the popup that appears it says:
拒绝执行内联脚本,因为它违反了以下内容内容安全策略指令:script-src 'self'chrome-extension-resource:" (popup.html:5).
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:" (popup.html:5).
popup.html 中的内联脚本在哪里,脚本不起作用
Which is where the inline script in popup.html is and the script does not work
我有:
manifest.json:
manifest.json:
{
"browser_action": {
"default_icon": "images/icon.gif",
"default_popup": "popup.html"
},
"manifest_version": 2,
"description": "MEH!",
"name": "My First Extension",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"version": "0.1"
}
popup.html:
popup.html:
<html>
<head>
</head>
<body>
<script>
chrome.tabs.executeScript(null,{
code:"document.body.style.backgroundColor='red'"
});
</script>
<div id='msg' style="width:300px">...</div>
</body>
</html>
非常感谢任何帮助
推荐答案
原来我无法正确读取错误,直到我在这里看到它
Turns out I could not read the error properly until I saw it in here
显然 manifest v2 不允许你有内联脚本,所以你只需要
Apparently manifest v2 does not allow you to have inline scripts, so you just need to
src="path_to_the_file.js"
这篇关于chrome 扩展在浏览器操作中插入内容脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!