开发者

Chrome extension background.html not logging to console

开发者 https://www.devze.com 2023-03-12 12:36 出处:网络
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

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 als开发者_JAVA百科o 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消