我正在使用js开发chrome扩展程序。我正在使用发送消息功能从myWebsite.com发送消息。在background.js文件中,我使用chrome.runtime.onMessageExternal.addListener添加了一个eventListener。
但是,我在控制台中收到错误:
“未选中的runtime.lastError:无法建立连接。接收端不存在。”
我的manifest.js文件:
{
"manifest_version": 1,
"name": "myname",
"short_name": "myname",
"description": "test",
"author": "myname",
"version": "1.0.0",
"minimum_chrome_version": "22",
"offline_enabled": false,
"icons": {
"16": "icons/icon-16x16.png",
"48": "icons/icon-48x48.png",
"128": "icons/icon-128x128.png"
},
"browser_action": {
"default_icon": "icons/icon-128x128.png"
},
"background": {
"scripts": [ "background.js" ]
},
"externally_connectable": {
"matches": [ "*://*.mywebsite.com/*"]
},
"permissions": [
"nativeMessaging",
"tabs",
"cookies",
"*://*.mywebsite.com/"
]
}
我的background.js文件:
chrome.runtime.onMessageExternal.addListener(function (request, sender, sendResponse) {
console.log(request);
})
我在mywebsite中的代码(其中键是扩展名):
chrome.runtime.sendMessage(key, obj, function (response) {
deferred.resolve(response);
});