Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Facebook log to console like this?

I was inspecting stuff, as you do, and came across this interesting thing on facebook.

fbView Full Image

I understand that is completely do-able with something similar to this:

var cssRule =     "color: rgb(249, 162, 34);" +     "font-size: 60px;" +     "font-weight: bold;" +     "text-shadow: 1px 1px 5px rgb(249, 162, 34);" +     "filter: dropshadow(color=rgb(249, 162, 34), offx=1, offy=1);"; console.log("%cHello World", cssRule); 

Source

My main question is, How do they stop the showing of the file.js:line_numer that you always get on the right hand side in console?

With the above code, you would see this: normView Full Image

Do you notice the red circle? But in facebooks example, they don't display that information. I've looked through the Web.Console API on Mozilla (Link), so does anybody possibly know how to exclude that specific peice of information?

like image 745
Darren Avatar asked Dec 11 '14 04:12

Darren


People also ask

How do I disable the console on my website?

To disable Javascript console, we need to throw an exception in the get accessor by checking if the property attached by chrome developer tool exists. With this script above, user won't be allowed to enter Javascript in the console. It also blocks auto-complete in console too. Thank you friends!

How does Facebook disable integrated developer tools?

Just go to Facebook and open up the developer tools, type one character into the console, and this warning pops up. No matter what you put in, it will not get executed.

How do you show warnings in console?

The console. warn() method is used to write a warning message in the console. So open the console to display the output (warning message).


2 Answers

You just have to async/defer the console.log call, e.g.

setTimeout(console.log.bind(console, '%cFoo', 'color: #FF00FF;'), 0); 
like image 171
Paul S. Avatar answered Sep 24 '22 15:09

Paul S.


Even though I joined the party late but I think this will do!

    var cssRule =     "color: rgb(249, 162, 34);" +     "font-size: 30px;" +     "font-weight: bold;" +     "text-shadow: 1px 1px 5px rgb(249, 162, 34);" +     "filter: dropshadow(color=rgb(249, 162, 34), offx=1, offy=1);" setTimeout(console.log.bind(console, "%cHello World", cssRule), 0); 
like image 25
Powerstone Avatar answered Sep 21 '22 15:09

Powerstone