简体   繁体   中英

How to hide source of Log messages in Console?

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

However, on some sites, messages are displayed without the source being displayed, such as on Facebook :

Facebook.com 上的控制台屏幕截图

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.

How can I hide the source ( .js page and line number) of console outputs?


Edit: 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.

They are using setTimeout to detach from the source:

setTimeout(console.log.bind(console, '\n%c' + s[0], s[1]));

for those who are still looking for this, you can use something like

 function consoleWithNoSource(...params) { setTimeout(console.log.bind(console, ...params)); } consoleWithNoSource("Helloo....!")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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