Chrome Extension - Message Passing from Popup to Content Script

后端 未结 1 923
难免孤独
难免孤独 2020-12-05 11:16

I\'m trying to pass data from a popup to a content script, but I\'m not having any luck. I got it to work the other way around (content -> popup) though. All I want to do is

相关标签:
1条回答
  • 2020-12-05 12:10

    You need to specify to which tab to send to. Like this:

    chrome.tabs.sendMessage(tab.id, {action:'start'}, function(response) {
        console.log('Start action sent');
    });
    

    If you don't know which is the tab, you can either send to all (probably a bad idea) or make the tab send info first.

    For more information check this page: Message Passing.

    0 讨论(0)
提交回复
热议问题