Get access to the console once the console object reference was changed

后端 未结 1 1312
情深已故
情深已故 2021-01-21 15:48

I like making userscripts. It\'s real fun to get some more control of your favorite page or just speed up it\'s loading.

Curently, I came across a problem that a page ei

相关标签:
1条回答
  • 2021-01-21 16:30

    Well, I've got one nasty solution here. Create an iframe (which creates new window) and get the console object of that iframe:

    function healConsole() {
      //<iframe> element
      var iframe = document.createElement("iframe");
      //Hide it somewhere
      iframe.style.position="fixed";
      iframe.style.height = iframe.style.width = "1px";
      iframe.style.top = iframe.style.left = "-5px";
      //No src to prevent loading some data
      iframe.src = "about: blank";
      //Needs append to work
      document.body.appendChild(iframe);
      //Get the inner console
      window.console = iframe.contentWindow.console;
    }
    

    Not sure how cross browser is this though. I'm looking for something better...

    0 讨论(0)
提交回复
热议问题