Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore console.log on a web page that overwrites it?

Twitter’s website does something like

console.log = function () {};

to turn the browsers’ built-in console.log method into a no-op. Is there I way to restore the original function?

like image 587
Šime Vidas Avatar asked Nov 10 '22 04:11

Šime Vidas


1 Answers

Unless they also removed it in the prototype, getting the log method using getPrototypeOf() should work:

console.log = Object.getPrototypeOf(console).log;

Since using console.log = function() {} overrides, but doesn't remove the one defined in the prototype, you can delete the overriding method:

delete console.log
like image 75
Ori Drori Avatar answered Nov 14 '22 21:11

Ori Drori