'console' is undefined - javascript error in logs

(Dean Taylor) #1

Error from log
Discourse 1.2.0.beta4 - https://github.com/discourse/discourse version 3cea85e09a5a86d7a965fb2ffd8b132659b79db0


'console' is undefined
Url: http://example.com/assets/vendor-0dbc6e71b0ee5428574e3562afe91ef1.js
Line: 16
Window Location: http://example.com/


HTTP_HOST: example.com
REQUEST_URI: /logs/report_js_error
HTTP_USER_AGENT: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)
HTTP_REFERER: http://example.com/


      message: 'console' is undefined
    Url: http://example.com/assets/vendor-0dbc6e71b0ee5428574e3562afe91ef1.js
      url: http://example.com/assets/vendor-0dbc6e71b0ee5428574e3562afe91ef1.js
      line: 16
      window_location: http://example.com/

(Jacob Chapel) #3

IE 9 on Windows Vista

Older IE’s don’t have console and you will see this error.

Best way to handle this is to not use console and use another lib to manage writing, or use a shim.

(Jeff Atwood) #4

We only have to support IE9 and barely. So we need to figure out where that’s being called from @eviltrout.

(Dean Taylor) #5

On reviewing your suppression for logster…

I think the best thing to do would be add the following simple code, the reason for this is that the code after the failed console.log will not be executed causing unexpected user experience that might just work fine otherwise.

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

(Jeff Atwood) #6

In a year or so we will probably drop IE9 support altogether so I am not sure it is worth it.

IE 9 has been our minimum browser since launch in Feb 2013 and it has been almost two years now…

(Jeff Atwood) #7

Also checking browser stats today, IE9 is quite rare. IE8 is much more globally common mainly because Windows XP users cannot upgrade to any higher version of IE. And we do not even pretend to work on IE8 of course, we sort of work on IE9 in an “absolute bare bones minimum” kind of way.

I will try to track down where that console.log is coming from though.

(Dean Taylor) #8

Sadly 12.75% of traffic for one of the communities I am involved with came from IE8 & 9 in the past 30 days - 11.6% IE9.

(Jeff Atwood) #9

Well at least the IE8 number is low! I agree the basics should continue to work on ie9 for at least the next year.

(Dean Taylor) #10

Actually IE8 doesn’t have the console.log issue - it’s only IE9 - IE9 requires the debug console open for console to exist.

(Jeff Atwood) #11

The only console.log I could find that wasn’t buried in external dependencies or in testing was here in I8n.


Hopefully that’s it.

(Sam Saffron) #12

That’s there on purpose for verbose localization which is default off…

It’s in vendor.js just grep the unminified

(Jeff Atwood) #13

Problem is there are ~150 instances of console.log, probably ~100 of those are in external dependencies and I can’t tell which ones matter… looks like some of the dependencies set up custom handling for the console, e.g.

// Console
var console = window.console = {};
console.log = console.info = console.warn = console.error = function(){};


if ( typeof console !== "undefined" && typeof console.log !== "undefined" )
  console.log.apply( null, args );

(Jeff Atwood) #14

Maybe it’s better to look at it this way: is anything unusual (other than pushstate, which doesn’t exist) broken in IE9?

Can you answer that question @DeanMarkTaylor ? That might be more useful to us than regurgitating a bunch of javascript error logs submitted by the client… I did download the IE9 vm which is 3.5 gb, but it’s hard to make time on MLK day with 3 kids at home, etc.

IE9 vs Chrome comparison review
(James Hayward) #15

I can’t talk for Discourse specifically, but this will affect IE8 and 9 - basically, console gets created the first time a user opens the developer console (ever, in the whole life of that browser) and exists for ever more.

Speaking from experience it is an extremely annoying problem to track down, and you will more than likely miss some other features that aren’t working.

I have found that building a fake console (as in @codinghorror post) is the easiest way to deal with this.


(Dean Taylor) #16

Created a new topic to cover IE9 test results:

(Robin Ward) #17

Right now our Javascript linting is designed to raise errors on console.log and not push to tests-passed. however they can still sneak in sometimes in files that are not linted properly.

Also we still sneak in logs using the {{log}} helper in Ember, but I checked their implementation and it seems like it should work in IE9.

Filling it with an empty function like @DeanMarkTaylor suggested is a pretty good solution. I could make an initializer to do that and call it “ie9-hax” or something to make it easy to find later on.

(Dean Taylor) #18

I believe this topic can be closed thanks to your commit @eviltrout


Unless you think there is something else to do with linting?

(Robin Ward) closed #19