繁体   English   中英

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

[英]Console.log not showing in console when in listener

我是 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)
        }
    )
})

背景.js:

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

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

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

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM