1

私はchrome exstion APIでいくつかのことを試しています.background.jsからcontentscrip.jsにデータを送信したいと思います. 私がしたことはすべて失敗し、グーグルの例をコピーして貼り付けようとしても、まだうまくいきません。(2日間やってます笑)

ここに私のjsonファイルがあります:

    {
  "name": "BlaExtension",
  "version": "0.1",
  "description": "bla the the exstion",
  "permissions": [
    "tabs","http://*/*","https://*/*"
  ],
  "background": {
    "scripts": ["background.js"]
  },
  "content_scripts": [
    {
       "matches": ["http://*/*","https://*/*"],
      "js": ["content_script.js"]
    }
  ],

     "permissions": [
    "tabs", "http://www.google.com/*"
  ],
  "manifest_version": 2
}

background.js

chrome.tabs.getSelected(null, function (tab) {
    chrome.tabs.sendMessage(tab.id, { greeting: "hello" }, function (response) {
        alert(foo);
    });
});

content_script.js

chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
  alert(request.greeting);


});

ここでスタックオーバーフローのメッセージングに関する古い投稿でヘルプを探してみましたが、何も役に立たないようです。何をしているの?(私の英語でごめんなさい)

4

0 に答える 0