2011-06-12 53 views
2

我無法讓我的內容腳本與我的背景頁面進行通信。我正在運行一個解壓縮的擴展。在我的內容腳本send.js我有一個線Chrome擴展程序background.html未記錄到控制檯

chrome.extension.sendRequest({message: "hey"}, function(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> 

我不斷收到一個Port error: Could not establish connection錯誤。

只是試圖找到我改變了我的錯誤向background.html

<script> 
console.log("Background html is running!"); 
</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運行或如何讓我的內容腳本與之通信。

回答

1

假設它不只是一個轉錄錯誤,背景頁面的清單鍵應該是background_page而不是background-page

+1

這是一個很棒的地方。我現在覺得自己很愚蠢。 – 2011-06-12 04:19:02

+0

請注意,這是舊的,更新的方法是使用''背景「:{」page「:」background.html「}' – ripper234 2012-11-22 23:56:13

相關問題