简体   繁体   English

如何在覆盖它的网页上恢复console.log?

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

Twitter's website does something like Twitter的网站有类似的东西

console.log = function () {};

to turn the browsers' built-in console.log method into a no-op. 将浏览器的内置console.log方法转换为无操作。 Is there I way to restore the original function? 我有办法恢复原来的功能吗?

Unless they also removed it in the prototype, getting the log method using getPrototypeOf() should work: 除非他们也在原型中删除它,否则使用getPrototypeOf()获取log方法应该有效:

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: 由于使用console.log = function() {}覆盖但不删除原型中定义的那个,您可以删除覆盖方法:

delete console.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM