Chrome拡張機能は初めてです。コンテンツ スクリプトとbackground.htmlページの間で通信しようとしています。background.htmlはリクエスト「hello」をコンテンツ スクリプトに送信し、コンテンツ スクリプトは「hello background」アラートで応答する必要があります。しかし、それは起こっていません。私のbackground.htmlコードは次のとおりです。
function testRequest() {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"});
});
}
content.jsコード:
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello")
alert("hello background");
}
);
popup.htmlコード:
<!doctype html>
<html>
<head></head>
<body>
<form>
<input type="button" value="sendMessage" onclick="testRequest()" />
</form>
</body>
</html>
manifest.json :
{
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"background": {
"page": "background.html"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*",
"notifications",
"contextMenus"
],
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["content.js"]
}
],
"name": "FirstExtension",
"version": "1.0"
}
助けてください!