さまざまな方法で繰り返し質問されていることは知っていますが、すべての回答を調べようとしましたが(誰かを見逃さなかったといいのですが)、どれもうまくいきませんでした。
これが私の拡張機能のコードです:
マニフェスト:
{
"name": "test",
"version": "1.1",
"background": 
{ 
    "scripts": ["contextMenus.js"]
},
"permissions": ["tabs", "<all_urls>", "contextMenus"],
"content_scripts" : [
    {
        "matches" : [ "http://*/*" ],
        "js": ["jquery-1.8.3.js", "jquery-ui.js"],
        "css": [ "jquery-ui.css" ],
        "js": ["openDialog.js"]
    }
],
"manifest_version": 2
}
contextMenus.js
function onClickHandler(info, tab) {
    if (info.menuItemId == "line1"){
      alert("You have selected: " + info.selectionText);
      chrome.extension.sendMessage({action:'open_dialog_box'}, function(){});
      alert("Req sent?");
    }
}
chrome.contextMenus.onClicked.addListener(onClickHandler);
chrome.runtime.onInstalled.addListener(function() {
  chrome.contextMenus.create({"id": "line1", "type": "normal", "title": "I'm line 1",     "contexts":["selection"]});
});
openDialog.js
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
  if (msg.action == 'open_dialog_box') {
    alert("Message recieved!");
  }
});
バックグラウンドページの2つのアラートは機能しますが、content_scriptの1つは機能しません。
コンソールログのメッセージ:ポートエラー:接続を確立できませんでした。受信側は存在しません。
私のせいはどこですか?
chrome.tabs.sendMessage()ではなく、コンテンツスクリプトにメッセージを送信するために使用する必要がありますchrome.extension.sendMessage()。