在侦听器中时,Console.log未显示在控制台中

问题描述

我是javascript的新手,如果这很明显并且大家都知道,我深表歉意。

当您在扩展程序popup.js中按一个按钮时,我正在使用消息传递来插入我的Chrome扩展程序的background.js来执行操作

popup.js:

getCurrentTab(function(tab) {
    chrome.runtime.sendMessage(
        {type: 'status',tabId: tab.id },function(response) {
            console.log(response.message)
        }
    )
})

Background.js:

chrome.runtime.onMessage.addListener(
  function(message,sender,callback) {
    console.log("Received message" + message + "," + sender + "," + callback)
    alert('received')
    callback({message: message.type});
})

我已经了解到需要对控制台的弹出窗口进行“检查”(可以在其中看到正在打印的响应)。

我可以看到页面正在发出警报,并且可以在弹出式控制台中看到响应。但是没有填充主控制台(消息以“收到的消息”开头)。

有人可以帮助一个糟糕的js初学者吗?

解决方法

@Amedina正确建议我的答案在这里:

https://stackoverflow.com/a/17293612/726954

我应该使用扩展页面访问我的background.js控制台