Javascript console.log 未在 Chrome 浏览器中显示输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38895724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
console.log not showing output in Chrome browser
提问by zeeshan
I am using Chrome browser Version 52.0.2743.116 (64-bit) on Mac OSX 10.11.6.
我在 Mac OSX 10.11.6 上使用 Chrome 浏览器版本 52.0.2743.116(64 位)。
I have a chrome extension with a background.js where I have a console.log statement for debugging purposes. However, I am unable to see the output in the Chrome browser console. Alert works fine but console.log outputs nothing.
我有一个带有 background.js 的 chrome 扩展,其中有一个用于调试目的的 console.log 语句。但是,我无法在 Chrome 浏览器控制台中看到输出。警报工作正常,但 console.log 不输出任何内容。
alert("CSS code: "+css);
console.log("CSS code:"+css);
I have checked to make sure "All" messages are selected, the context is set to "top", etc. When the page loads, I see other console.log messages (not from my extension), the alert window pop up but nothing printed to the console.
我已经检查以确保选择了“所有”消息,上下文设置为“顶部”等。当页面加载时,我看到其他 console.log 消息(不是来自我的扩展),警报窗口弹出但什么也没有打印到控制台。
How do I see console.log output?
如何查看 console.log 输出?
EDIT:Adding the function code where the alert
and console.log
statements appear.
编辑:添加alert
和console.log
语句出现的功能代码。
function doSomething(tab) {
var tabUrl = tab.url;
if (tabUrl && tabUrl.indexOf("my-site.com") != -1) {
var css = "";
if (hideAds == true) {
css += ".adsBanner {display: none !important;} .promo {display: none !important;} ";
}
alert("CSS code: "+css);
console.log("CSS code:"+css);
chrome.tabs.insertCSS(tab.id, {
code: css
});
}
}
EDIT 2:In response to the comment that this is a duplicate of thisquestion, I want to print console.log
statements from the background file, I don't have a popup.html file. The other question has solutions to execute console.log
on the background page called from the popup page.
编辑 2:为了回应关于这是这个问题的重复的评论,我想console.log
从后台文件打印语句,我没有 popup.html 文件。另一个问题有console.log
在从弹出页面调用的后台页面上执行的解决方案。
回答by zeeshan
回答by Adedolapo Dolexy Sokoya
The answer to your problem is to use document.write();
您的问题的答案是使用 document.write();