如何解决Chrome扩展程序background.html无法登录到控制台
| 我无法让内容脚本与背景页面进行交流。我正在运行一个未打包的扩展程序。在内容脚本send.js
中,有一行
chrome.extension.sendRequest({message: \"hey\"},function(response){});
我的background.html
看起来像:
<script>
/* the coffeescript way,but I also tried without the
* coffeescript wrappers and got the same errors. */
(function() {
var dispatchRequest;
dispatchRequest = function(request,sender,sendResponse) {
console.log(\"request dispatch called\");
}
chrome.extension.onRequest.addListener(dispatchRequest);
}).call(this);
</script>
我不断收到Port error: Could not establish connection
错误。
为了找到错误,我将background.html
更改为
<script>
console.log(\"Background html is running!\");
</script>
然后,我重新加载页面并检查了Chrome控制台,但是没有输出。
这是我的(缩写)manifest.json
:
{
\"background-page\": \"background.html\",\"content_scripts\": [{
\"all_frames\": true,\"css\": [ \"style.css\" ],\"js\": [ \"send.js\" ],\"matches\": [ \"http://mail.google.com/*\",\"https://mail.google.com/*\" ]
}],\"permissions\": [ \"tabs\",\"http://*/\",\"https://*/\",\"cookies\" ]
}
在这一点上,我很茫然地想出如何让background.html
运行或如何让我的内容脚本与之通信。
解决方法
假设这不仅是转录错误,背景页面的清单清单应该是
background_page
,而不是background-page
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。