sendMessage from extension background or popup to content script doesn't work

后端 未结 4 950
孤街浪徒
孤街浪徒 2020-12-02 05:38

I know that question has been repeatedly asked in different ways, but I tried to go through all the answers (hopefully I didn\'t miss anyone) and none of them worked for me.

4条回答
  •  借酒劲吻你
    2020-12-02 06:26

    Here's an example of a background script that sends a message to the content-script file.

    background.js

    chrome.tabs.sendMessage(tabs[0].id,"your message"); 
    

    content-script/content.js

    chrome.runtime.onMessage.addListener(function (response, sendResponse) {
              console.log(response);
    });
    

提交回复
热议问题