0

IE has a feature which ignores all output via console.log() until I press F12 or open the Developer Tools in some other way. From that point in time, all output in the console will be kept, even when I close the dev tools for some time.

Is there a way to force IE to keep the console output from the start? Without having to open the developer tools?

I'm using IE 11

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820

1 Answers1

1

Complete Update:

Here is a re-written version of the JsFiddle script I built yesterday:

The version below does not contains debug traces, whereas the JsFiddle version does.

var bufferedConsoleCalls = [];

window.bufferedConsoleLog = function(message) {
  var consoleMethod = window.console.log.toString();
    if (consoleMethod.indexOf('native code') !== -1) {
    bufferedConsoleCalls.push(message);
  }
  else {
    if (bufferedConsoleCalls.length > 0) {
      console.log('previous buffered calls :');
      console.log(bufferedConsoleCalls);
      bufferedConsoleCalls = [];
    }
    console.log(message);
  }
}

// sample code added to generate console entries.
// remove lines below when used for real scenarios.
var count = 1;
setInterval(function() {
  // Simulated call from page, calling bufferedConsoleLog instead of console.log
  bufferedConsoleLog('Log' + count);
  count ++;
}, 1000);

The issues was that IE11 actually has an implementation of console.log method, which does seem not do anything. I put some extra test

window.console.log.toString().indexOf('native code') !== -1

which if what console.log contains when call without opening the F12 Devtools.

Still, console.log ust stops working when you close Devtools after opening it...

Benjamin Soulier
  • 2,223
  • 1
  • 18
  • 30
  • My problem is that IE ignores all calls to console.log until I open dev tools the first time. I'm not interested in logging elsewhere. I'll keep this in mind when it turns out that sending the log messages to a server via AJAX is the only workaround. – Aaron Digulla Aug 15 '16 at 16:04
  • This is a [known error](http://stackoverflow.com/questions/3326650/console-is-undefined-error-for-internet-explorer), The only way I see would be to buffer calls done to console.log before Dev Tools are opened; I made a Fiddler draft [here](https://jsfiddle.net/jaymz666/ahnyfpwj/14/) – Benjamin Soulier Aug 16 '16 at 09:03
  • I'm not getting errors. console.log() just doesn't do anything. I've forked the fiddle: https://jsfiddle.net/9qex9o09/ With IE 11, wait for Toto 4 in the output window and then open the dev tools. You'll see only "Todo 4" in the console, Toto 1..3 will be missing. – Aaron Digulla Aug 16 '16 at 11:38
  • Update: console.log() doesn't do anything as long as the window is closed. So if you close it with the output of "Toto 13", wait several seconds and open it for "Todo 20", you'll just get "Toto 13" and "Toto 20" in the console. – Aaron Digulla Aug 16 '16 at 13:02
  • I completely rewrote my js method to buffer calls for IE11, works like a charm now – Benjamin Soulier Aug 17 '16 at 12:56
  • Hey Aaron, did that helped you out somehow? – Benjamin Soulier Sep 06 '16 at 16:10
  • I got distracted and I'll be away for two weeks. I'll come back to this, promise :-) – Aaron Digulla Sep 09 '16 at 16:12