google-chrome-extension

Port error: Could not establish connection. Receiving end does not exist. In Chromiume


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)

and in my `background.js I simply add a request Listener like:

chrome.extension.onrequest.addListener(function(req,sender,res){console.log("procession"})

But there's an error:

Port error: Could not establish connection. Receiving end does not exist

It seems a bug in chrome? PS:
part of my manifest.json

"background": {
    "scripts": ["background.js"]
},
"content_scripts": [
  {
    "matches": ["< all_urls >"], 
    "js": ["inject.js"]
  }
],

I'm in Chromium 17, and I tried reloading the extension, reopening the browser... nothing happened
some one get some ideas?


Solution

  • 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"]
      },
      */
    

    I hope this works for you too.