sendMessage from popup to content.js not working in chrome extension

前端 未结 2 1872
鱼传尺愫
鱼传尺愫 2021-02-08 01:18

I\'m trying to make a popup interface for a chrome extension. I can\'t seem to send a message from the popup.html/popup.js to the content.js script. Here\'s what I have so far.

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 01:39

    The answer from 2105 still works on chrome version 88.0.4324.104. I just tested this. One thing I would update is instead of

    alert("started"); in the content.js use console.log("started");

    You have your proof (Hit F12, console tab) that it worked which persists for you and you can verify the x number of clicks produces x number of "started" log entries.

    Make sure you reload the target page when you "Load Unpacked" each time, that had me stuck for a moment.

    my manifest.json looks like this:

    {
    "name":"Chr Ext",
    "description":"blah blah",
    "version":"2",
    "minimum_chrome_version": "46",
    "manifest_version":2,
      "content_scripts": [
      {
        "matches": [
          ""
        ],
        "js": ["content.js"]
      }],
        "permissions": [
            "tabs"
        ],
        "browser_action": {
            "default_popup": "popup.html"
        }
    }
    

提交回复
热议问题