如何在控制台中隐藏日志消息的来源? [英] How to hide source of Log messages in Console?
问题描述
将消息输出到控制台时,还会显示源(在Chrome开发者工具中位于右侧):
When outputting messages into the console, the source is also displayed (in Chrome Developer Tools it's on the right):
console.log("Foo"); //Source
Foo test.js:1 //Output
但是,在某些站点上,消息显示为,而却没有显示源,例如在 Facebook上:
However, on some sites, messages are displayed without the source being displayed, such as on Facebook:
看看 Chrome控制台API参考,其中有一些示例大量不同的输出,但所有输出都有显示.
Having a look on the Chrome Console API Reference there are examples across a ton of different outputs but all of them have the source displayed.
如何隐藏控制台输出的来源(.js
页和行号)?
How can I hide the source (.js
page and line number) of console outputs?
为澄清起见,这不是 Facebook如何禁用浏览器的集成开发人员工具?,因为该问题回答了控制台如何禁用标准用户输入(其答案说明了其工作原理).我特别在问不显示源文件和行的美感.
Just for clarification, this is not a duplicate of How does Facebook disable the browser's integrated Developer Tools? as that question answers how the console disables standard user input (and its answers explain how it works). I am specifically asking about the aesthetic of not displaying the source file and line.
推荐答案
他们正在使用setTimeout
与源分离:
They are using setTimeout
to detach from the source:
setTimeout(console.log.bind(console, '\n%c' + s[0], s[1]));
这篇关于如何在控制台中隐藏日志消息的来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!