Я следую официальному Do c https://developer.chrome.com/extensions/messaging, но это не сработало. он сообщает об ошибке, что принимающая сторона не закрывается.
сценарий содержимого:
chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
console.log(response.farewell);
});
Фоновый сценарий:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
манифест. json
{
"manifest_version": 2,
"name": "name",
"author": "author",
"description": "Pilot towards chrome Extension.",
"version": "1.0.0",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery.js", "content.js"]
}],
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"icons": {
"128": "icon_128.png"
},
"permissions": [
"storage",
"activeTab",
"<all_urls>",
"contextMenus",
"tabs",
"alarms"
]
}
по-прежнему возникает ошибка, указывающая, что принимающая сторона не существует.