3

I need to be able to run my angularjs app in IE9 but this currently only works with devtools open(F12). From what I am aware is that console.log can cause this but this is stripped out in the app , I am using gulp.stripDebug. What can be another cause or is this a IE9 bug? Is there a way of debugging/tracking js code without having to open the devtools at the same time?

Pindakaas
  • 4,389
  • 16
  • 48
  • 83
  • `try-catch-alert(e.message)`? – dfsq Feb 03 '15 at 12:20
  • 1
    You probably should be using [$log](https://docs.angularjs.org/api/ng/service/$log) instead. Are you sure everything is stripped out? Run the app with the dev tools open and check that nothing is logged to the console. – Wayne Ellery Feb 03 '15 at 12:31
  • Faced similar issue, don't remember how it was fixed. Meanwhile check this out http://stackoverflow.com/questions/7742781/why-javascript-only-works-after-opening-developer-tools-in-ie-once?rq=1 – salahuddin Feb 03 '15 at 12:34
  • first in your html, add a script tag with: window.console= window.console || {log:function(){},error:function(){},warning:function(){}}; It will prevent ie from dying if there are leftover console.log() or similar functions. – jornare Feb 09 '15 at 19:31

1 Answers1

0

If console is not defined, calling .log() will break javascript execution. An easy way to overcome this is to check if it exists and create a dummy object if it does not. If you load the page without developer console and open the console afterwards, logging won't work though.

if (!window.console) {
  window.console = { log : function () {} };
}

You could make the function alert the debug message, but that would probably annoy more than it would benefit you ;)

Per Hornshøj-Schierbeck
  • 15,097
  • 21
  • 80
  • 101