端口错误:无法建立连接.接收端不存在.在铬 [英] Port error: Could not establish connection. Receiving end does not exist. In Chromiume
问题描述
我正在 Chrome 中开发一个扩展程序,但出现了问题.在我的 inject.js
中,我提出如下请求:
I'm developing an extension in Chrome, and there's a problem. In my inject.js
, I make a request like:
chrome.extension.sendRequest({command:'skip'},callback)
在我的 `background.js 中,我只是添加了一个请求监听器,如:
and in my `background.js I simply add a request Listener like:
chrome.extension.onrequest.addListener(function(req,sender,res){console.log("procession"})
但是有一个错误:
端口错误:无法建立连接.接收端不存在
这似乎是 chrome 中的一个错误?PS:
我的 manifest.json 的一部分
It seems a bug in chrome?
PS:
part of my manifest.json
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["< all_urls >"],
"js": ["inject.js"]
}
],
我在 Chromium 17 中,我尝试重新加载扩展程序,重新打开浏览器......什么也没发生
有人有一些想法吗?
I'm in Chromium 17, and I tried reloading the extension, reopening the browser... nothing happened
some one get some ideas?
推荐答案
我发现自己遇到了与您在此处描述的问题相同的问题.我发现对我有用的解决方案是使用背景页面而不是背景脚本,如下所示:
I found myself having the same issue as you describe here. The solution I found that works for me is to use a backgroundpage instead of a background script, like so:
"background_page": "src/background.html",
// maybe this seems to work instead of background { scripts [] }
/* this gives a Port error: Could not ...
"background": {
"scripts": ["src/background.js"]
},
*/
我希望这对你也有用.
这篇关于端口错误:无法建立连接.接收端不存在.在铬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!