Google chrome extension Chrome extension background.html未登录到控制台
我无法让我的内容脚本与背景页面进行通信。我正在运行一个未打包的扩展。在我的内容脚本Google chrome extension Chrome extension background.html未登录到控制台,google-chrome-extension,Google Chrome Extension,我无法让我的内容脚本与背景页面进行通信。我正在运行一个未打包的扩展。在我的内容脚本send.js中,我有一行 chrome.extension.sendRequest({message:“hey”},函数(response){}) 我的background.html看起来像: <script> /* the coffeescript way, but I also tried without the * coffeescript wrappers and got the same
send.js
中,我有一行
chrome.extension.sendRequest({message:“hey”},函数(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>
然后我重新加载了页面并检查了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\u page
,而不是background page
,注意这是旧的,较新的方法是使用“background”:{“page”:“background.html”}
{
"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" ]
}