Why is console.log an empty function on some sites in Chrome?

前端 未结 5 2379
有刺的猬
有刺的猬 2021-01-01 22:33

Go to Twitter\'s login page and type the following in the console:

window.addEventListener(\'keypress\', function(e){console.log(\'hello\')}, true)

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 23:16

    This problem doesn't occur on Firefox.

    I've checked on Chrome and apparently for some reason the Gmail and Twitter pages end up reassigning console.log to an empty function function () {}, so your handler gets called but it does nothing. If you try alert() instead of console.log, you'll see it working.

    Interesting.

提交回复
热议问题