Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.log without reference to the script

Pretty useless question, I guess, but it's really interesting to find out how facebook prints to browser console without reference to the script. Open the console at facebook.com and you will see text, but won't see the reference to th javascript...

enter image description here

like image 918
Prosto Trader Avatar asked Aug 30 '14 22:08

Prosto Trader


1 Answers

Well, friend of my friend found the answer.

To console.log without reference we should use setTimout and bind

setTimeout(console.log.bind(console, 'test'));

And here is the whole facebook snippet:

    var i = "Stop!",
        j = "This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.";

if ((window.chrome || window.safari)) {
var l = 'font-family:helvetica; font-size:20px; ';
[
   [i, l + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'],
   [j, l],
   ['', '']
].map(function(r) {
    setTimeout(console.log.bind(console, '\n%c' + r[0], r[1]));
});
}
like image 141
Prosto Trader Avatar answered Sep 23 '22 13:09

Prosto Trader