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 and you will see text, but won't see the reference to th javascript...
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. and you will see text, but won't see the reference to th javascript...
Share Improve this question edited Aug 30, 2014 at 22:22 Prosto Trader asked Aug 30, 2014 at 22:14 Prosto TraderProsto Trader 3,5273 gold badges33 silver badges53 bronze badges 17-
2
You can override JS functions simply be redefining them.
console.log = function(){ /* whatever magic you want */ }
– Lix Commented Aug 30, 2014 at 22:18 - 1 @ProstoTrader It's not a useless question. Actually I am interested in the answer too..It's quite interesting how they did it. – Ani Commented Aug 30, 2014 at 22:30
- 1 @ProstoTrader - All you have to do is make sure that the dev tools are in a detached window and you can inspect the inspector :) Check out this post for more info: stackoverflow./questions/12291138/… – Lix Commented Aug 30, 2014 at 22:34
- 1 wow! didn't know we can inspect the inspector ))) simply changing css we can hide reference ))) #console-messages .link, #console-messages a { color: transparent; cursor: pointer; } – Prosto Trader Commented Aug 30, 2014 at 22:41
- 1 @ProllyGeek You don't have to log in. Just go the fb url and inspect – Ani Commented Aug 30, 2014 at 22:45
2 Answers
Reset to default 8Well, 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]));
});
}
More generic function.
If run with () instead of ("Your title here","Your text here")
it will display the default message.
((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's 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's 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!")