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

前端 未结 5 2255
有刺的猬
有刺的猬 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:11

    Because those sites have specifically set (for webkit apparently):

    console.log = function(){};
    

    However, in Chrome you can restore the original log() functionality by issuing this command in console:

    console.log = console.__proto__.log
    

    Then you can do this:

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

    And it should work as expected.

提交回复
热议问题