【发布时间】:2018-06-18 16:28:49
【问题描述】:
我正在尝试使用以下代码从background.js 向content.js 发送消息:
背景
chrome.runtime.sendMessage({'method': 'test'});
内容
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
if(message.method == 'test')
console.log('Got message');
});
当background.js 收到来自popup.js 的特定消息时发送后台消息,该消息发生在点击事件上。所以用户点击弹出窗口中的一个按钮,一条消息被发送到后台,然后发送到内容。
我感觉我的问题与以下事实有关:当在弹出窗口(这是一个单独的选项卡)中单击按钮时,内容脚本没有收到它,因为它不是当前的活动选项卡。
请帮帮我。
【问题讨论】: