Ben
Ben

Reputation: 9001

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:

Console screenshot on 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.

Upvotes: 33

Views: 9127

Answers (2)

Ameen Rashad
Ameen Rashad

Reputation: 514

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

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

consoleWithNoSource("Helloo....!")

Upvotes: 4

Oliver Salzburg
Oliver Salzburg

Reputation: 22099

They are using setTimeout to detach from the source:

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

Upvotes: 38

Related Questions