Passing message from background.js to popup.js

后端 未结 4 1472
无人共我
无人共我 2020-12-05 10:12

I\'m trying to implement my own chrome extension on which, on a certain event, create a browser notification and fills the popup with data calculated in background.js

<
4条回答
  •  死守一世寂寞
    2020-12-05 10:53

    Use runtime.sendMessage to send messages to background script, and tabs.sendMessage from background to content script.

    Please note that you need to specify tab id:

    chrome.tabs.query({ active: true }, (tabs) => {
        chrome.tabs.sendMessage(tabs[0].id, { greeting: 'hello' }, (response) => {
            console.log(response);
        });
    });
    

    You can find full example and documentation here: https://developer.chrome.com/extensions/messaging#simple

提交回复
热议问题