コンテンツスクリプトがバックグラウンドページにメッセージを送信し、ブラウザのアクションで拡張機能アイコンをクリックするとそのバックグラウンドページにアクセスしてデータを取得する拡張機能を作成したいと思います。Windows8でChromeバージョン23.0.1271.64mを使用しています。
次のエラーが発生します。ポートエラー:接続を確立できませんでした。受信側は存在しません。
私は同じことを解決しようとしました。しかし、人々はchrome20+でサポートされていないsendRequestを使用しています。私はまた、クロム20+について言及された解決策を見つけました。しかし、機能していません。助けてください。
以下はファイルの内容です。
マニフェスト.json
{
  "name": "Test Extension",
  "version": "1.0",
  "manifest_version": 2,
  "description": "A test extension.",
  "background": "background.html",
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["jquery.js","content.js"]
    }
  ],
 "permissions": ["tabs", "http://*/", "https://*/"],
   "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}
background.html
<html>
<head>
    <script src="background.js"></script>
</head>
<body>
    <h1>Wy</h1>
</body>
</html>
background.js
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
    // Chrome 20+
    alert(request);
    console.log('received in listener');
  sendResponse({farewell: "goodbye"});
});
content.js
$(function(){
console.log('start-sending message');
chrome.extension.sendMessage({greeting: "hello"},function(response){alert(response);});
console.log('end-sending message');
});
popup.html
<!doctype html>
<html>
  <head>
    <title>Getting Started Extension's Popup</title>
    </style>
    <!-- JavaScript and HTML must be in separate files for security. -->
    <script src="jquery.js"></script>
    <script src="popup.js"></script>
  </head>
  <body>
  </body>
</html>
popup.js
$(function(){
  var str_html = "<tr><td width='60%'>S</td><td width='40%'>15</td></tr><tr><td width='60%'>M</td><td width='40%'>25</td></tr>";
  $('#sizes_container').html(str_html);
  var bkg = chrome.extension.getBackgroundPage();
    console.log(bkg);
});