开发者

Returning a value from a content script

开发者 https://www.devze.com 2023-04-10 17:30 出处:网络
When executing a content script from a popup is there a way for that content script to return a value to the popup where the s开发者_运维百科cript was executed.Referring to Google\'s Docs, use the fol

When executing a content script from a popup is there a way for that content script to return a value to the popup where the s开发者_运维百科cript was executed.


Referring to Google's Docs, use the following code:

contentscript.js

chrome.runtime.sendMessage({value: "hello"}, null);

popup.html

chrome.runtime.onMessage.addListener(
    function myFunc(request, sender, sendResponse) {
        doStuffWithValue(request.value);
        chrome.runtime.onMessage.removeListener(myFunc); //if you want to stop listening after receiving the message
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消