简体   繁体   English

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

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

I'm new to javascript so I apologies if this is obvious and everyone knows.我是 javascript 的新手,所以如果这很明显并且每个人都知道,我很抱歉。

I'm using Message Passing to intruct the background.js of my Chrome Extension to perform an action when you press a button in the extensions popup.js当您按下扩展程序 popup.js 中的按钮时,我正在使用消息传递来指导我的 Chrome 扩展程序的 background.js 执行操作

popup.js: popup.js:

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

Background.js:背景.js:

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

I've already learned that i need to "Inspect" my popup window for it's console (where I can see the response being printed).我已经了解到我需要“检查”我的弹出窗口 window 的控制台(我可以看到正在打印的响应)。

I can see the page is alerting, and I can see the response in my popups console.我可以看到页面正在发出警报,并且我可以在弹出窗口控制台中看到响应。 But the main pages console isn't being filled (with message starting "Received message").但是主页控制台没有被填充(消息以“收到的消息”开头)。

Can someone help a poor js beginner out?有人可以帮助一个可怜的 js 初学者吗?

@Amedina has rightly suggested my answer is here: @Amedina 正确地建议我的答案在这里:

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

I should be using the extension page to access my background.js console我应该使用扩展页面来访问我的 background.js 控制台

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

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