【问题标题】:How to restore console.log on a web page that overwrites it?如何在覆盖它的网页上恢复 console.log?
【发布时间】:2015-12-24 10:27:13
【问题描述】:

Twitter 的网站做了类似的事情

console.log = function () {};

将浏览器的内置 console.log 方法变成无操作。有没有办法恢复原来的功能?

【问题讨论】:

  • 使用delete console.log
  • console.dir() 或console.warn() 有用吗?
  • @michael Only console.error...
  • 如果网站用console = { log: function () { } };覆盖整个控制台怎么办?

标签: javascript browser console.log


【解决方案1】:

除非他们也在原型中删除它,否则使用getPrototypeOf() 获取log 方法应该可以工作:

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

由于使用console.log = function() {}会覆盖,但不会删除原型中定义的那个,你可以删除覆盖方法:

delete console.log

【讨论】:

  • 或者只是console.log = Console.prototype.log?
  • @ŠimeVidas - 请在 chrome 中试试这个:)
  • 请从您的回答中删除其他人的姓名。这不是评论
  • 这不是评论,而是功劳。我想只是删除覆盖方法,然后注意到您的评论。我可以删除它,如果它打扰你。
  • @OriDrori 我很好奇为什么 Chrome 决定不将 Console 暴露在全局范围内。
猜你喜欢
  • 1970-01-01
  • 2014-04-07
  • 2016-06-03
  • 2011-10-28
  • 2013-04-27
  • 2013-12-25
  • 1970-01-01
  • 1970-01-01
  • 2011-10-25
相关资源
最近更新 更多