我在嘗試從彈出窗口向我的內容發送消息時出現此錯誤。我想要做的是從我的content.js中獲取當前選項卡的文檔並將其發送到彈出窗口。我該如何解決這個錯誤?Chrome擴展端口錯誤:無法建立連接。接收結束不存在
{
"manifest_version": 2,
"name": "Chrome Snapshot",
"description": "Save images and screenshots of sites to Dropbox.",
"version": "1.0",
"permissions": [
"<all_urls>",
"tabs"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "html/popup.html"
},
"background": {
"scripts": [
"vendor/dropbox.min.js",
"vendor/jquery-2.0.2.min.js"
],
"persistant": false
},
"content_scripts" : [{
"all_frames": true,
"matches" : ["*://*/*"],
"js" : ["js/content.js"],
"run_at": "document_end"
}]
}
JS/popup.js
chrome.runtime.sendMessage({message: 'hi'}, function(response) {
console.log(response);
});
JS/content.js
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
console.log('message', message);
sendResponse({farewell: 'goodbye'});
});
編輯#1仍然得到同樣的錯誤Port error: Could not establish connection. Receiving end does not exist. miscellaneous_bindings:235 chromeHidden.Port.dispatchOnDisconnect
固定拼寫錯誤「持久'清單
個更新JS/popup.js
chrome.tabs.query({'active': true,'currentWindow':true}, function(tab){
console.log('from tab', tab[0]);
chrome.tabs.sendMessage(tab[0].id, {message: 'hi'}, function(response){
console.log(JSON.stringify(response));
});
});