Kevin Burke
Kevin Burke

Reputation: 65024

Chrome extension background.html not logging to console

I'm having trouble getting my content script to communicate with my background page. I'm running an unpacked extension. In my content script send.js I have a line

chrome.extension.sendRequest({message: "hey"}, function(response){});

and my background.html looks like:

<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>

I keep getting a Port error: Could not establish connection error.

Just to try to find the error I changed my background.html to

<script>
console.log("Background html is running!");
</script>

I then reloaded the page and checked the Chrome console but there was no output.

Here's my (abbreviated) 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" ]
}

At this point I'm at a loss to figure out how to get the background.html to run or how to get my content script to communicate with it.

Upvotes: 2

Views: 1341

Answers (1)

Mihai Parparita
Mihai Parparita

Reputation: 4236

Assuming it's not just a transcription error, the manifest key for the background page should be background_page, not background-page.

Upvotes: 1

Related Questions