Console.log without script reference

A pretty useless question, I think, but it’s really interesting to know how facebook prints in the browser console without a script link. Open the console on facebook.com and you will see the text, but will not see the link to javascript ...

enter image description here

+6
source share
2 answers

Well, my friend’s friend found the answer.

In console.log without a link, we should use setTimout and bind

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

And here is the whole snippet on facebook:

  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 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])); }); } 
+5
source

More general function.
If you use instead of () instead of ("Your title is here", "Your text is here")
a default message will be displayed.

 ((title,message)=>{ var i = title || "Stop!" , j = message || "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 account, it is a scam and will give them access to your Facebook account."; 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])); }); })("Your title here","Your text here") 

or directly:

 console.alert = function(title, message) { var i = title || "Stop!", j = message || "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 account, it is a scam and will give them access to your Facebook account."; 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])); }); } 

and

 console.alert("Hello", "You can write what you like here!") 
0
source

Source: https://habr.com/ru/post/1201485/


All Articles