sending message to chrome extension from a web page

前端 未结 5 530
遇见更好的自我
遇见更好的自我 2020-11-27 13:24

I want to send message from the console of the random web page to my chrome extension. chrome.extension.sendMessage doesn\'t seem to work.

5条回答
  •  隐瞒了意图╮
    2020-11-27 13:53

    In addition to @hewigovens , I don't have enough points to comment... I'm explaining @renatoargh and @sbichenko If sending message from a default web page -

    1) the webpage needs to be quoted in the manifest. e.g.:

    "externally_connectable": {
      "matches": ["http://abcde/abcde/main.aspx*"]
    }
    

    2) the background.js (background page) excepts the call with onMessageExternal e.g. (calling an extension):

    var host_name = "com.my_chrome_extension.com";
     chrome.runtime.onMessageExternal.addListener(function(message, sender, sendResponse) {
        chrome.runtime.sendNativeMessage(host_name, {"run":message});
        sendResponse({"success": "success"});
        return true;
    });
    

提交回复
热议问题