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

前端 未结 5 2406
有刺的猬
有刺的猬 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 22:57

    Get it from an iframe:

    function setConsole() {
      var iframe = document.createElement('iframe');
      iframe.style.display = 'none';
      document.body.appendChild(iframe);
      console = iframe.contentWindow.console;
      window.console = console;
    }
    

    (and then call it)

    setConsole()
    

    source: https://gist.github.com/cowlicks/a3bc662b38c36483b35f74b2b54e37c0

提交回复
热议问题