Console errors in Application Insights RRS feed

  • Question

  • I've been running the azure version of application insights in production for about a week now with great success. The *cough* insights into my application have been very useful. I've been able to address several issues into which I previously had no visibility. However I have an issue and that is related to the number of JavaScript errors that application insights itself is responsible for. 

    The error here is related to console being undefined. The error seems to be related to older versions of internet explorer. I believe some of these older browsers didn't define console unless the console was actually open. Looking at the script I don't see anything wrong. The only pace where there is use of console is in the _warn function:

    n._warn = function (n) { if (console && typeof console.warn == "function") console.warn(n); else try { console.log(n) } catch (t) { } }

    and here it appears to be properly guarded. It is, of course, almost impossible to test as you can't have the developer tools open or they will define console and that's assuming you can even find an IE9 browser (thanks, browserstack!).

    Would it be possible to rewrite this function as 

    n._warn = function (n) { if (console && typeof console.warn == "function") console.warn(n); else if (console && typeof console.log == "function") { console.log(n) } }

    Although it seems like this should make no difference it is following a better practice. I wonder if perhaps the onerror catch of older browsers might also catch caught exceptions.

    I'm happy to dig into this more if it would be helpful. For now I'll try prefacing the appInsights script block with

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

    Wednesday, November 19, 2014 2:41 PM