# 'console' is undefined - javascript error in logs

**URL:** <https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056>\
**Category:** Bug\
**Created:** [January 15, 2015, 8:56pm UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056 "2015-01-15T20:56:49Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [January 15, 2015, 8:56pm UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/1 "2015-01-15T20:56:49Z")

</div>

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

##Info

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

```

##Env

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

params:

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

```

---

<div class="post-metadata">

**Author:** ![chapel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapel/32/122414_2.png) [@chapel](https://meta.discourse.org/u/chapel)\
**Post date:** [January 16, 2015, 12:52am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/3 "2015-01-16T00:52:41Z")

</div>

> [@DeanMarkTaylor](#):
>
> Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)

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.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [January 16, 2015, 1:36am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/4 "2015-01-16T01:36:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [January 19, 2015, 2:16am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/5 "2015-01-19T02:16:34Z")

</div>

On reviewing your suppression for logster…  
[https://github.com/discourse/discourse/commit/a2e77d8bf49c41c3a56515afe7dc118d8f88725f](https://github.com/discourse/discourse/commit/a2e77d8bf49c41c3a56515afe7dc118d8f88725f)

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 () {};

```

> <https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function/9593812#9593812>

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [January 19, 2015, 2:18am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/6 "2015-01-19T02:18:28Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [January 19, 2015, 3:12am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/7 "2015-01-19T03:12:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [January 19, 2015, 3:17am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/8 "2015-01-19T03:17:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [January 19, 2015, 3:19am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/9 "2015-01-19T03:19:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [January 19, 2015, 3:19am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/10 "2015-01-19T03:19:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [January 19, 2015, 8:35am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/11 "2015-01-19T08:35:56Z")

</div>

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

[https://github.com/discourse/discourse/commit/3d0e59942cfc786e362924d2e0d3d617cc18599a](https://github.com/discourse/discourse/commit/3d0e59942cfc786e362924d2e0d3d617cc18599a)

Hopefully that’s it.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [January 19, 2015, 9:36am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/12 "2015-01-19T09:36:10Z")

</div>

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

It’s in vendor.js just grep the unminified

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [January 19, 2015, 9:53am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/13 "2015-01-19T09:53:12Z")

</div>

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(){};

```

and

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

```

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [January 19, 2015, 9:54am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/14 "2015-01-19T09:54:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![geeksareforlife](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geeksareforlife/32/114335_2.png) [@geeksareforlife](https://meta.discourse.org/u/geeksareforlife)\
**Post date:** [January 19, 2015, 11:12am UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/15 "2015-01-19T11:12:02Z")

</div>

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.

J

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [January 19, 2015, 9:38pm UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/16 "2015-01-19T21:38:28Z")

</div>

> [@codinghorror](#):
>
> 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 ?

Created a new topic to cover IE9 test results:

> [@IE9 vs Chrome comparison review](https://meta.discourse.org/t/ie9-vs-chrome-comparison-review/24194):
>
> Continuing the discussion from [‘console’ is undefined - javascript error in logs](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/14): So I did a quick run-though of experience of IE9 (9.0.8112.16421) vs Chrome 39. I did test far more than what’s listed here, these are the problem areas. ##composer ###Newly opened ####Chrome ####IE9 missing placeholder text in input fields. initial category not selected ###Post filled in ####Chrome ####IE9 Your topic is similar to... displayed empty So I tired it…

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [January 20, 2015, 8:30pm UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/17 "2015-01-20T20:30:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [February 17, 2015, 2:45pm UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/18 "2015-02-17T14:45:39Z")

</div>

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

[https://github.com/discourse/discourse/commit/df8880a71a20e2d845934b2ab6e8515b3808eeb2](https://github.com/discourse/discourse/commit/df8880a71a20e2d845934b2ab6e8515b3808eeb2)

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

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [February 17, 2015, 3:20pm UTC](https://meta.discourse.org/t/console-is-undefined-javascript-error-in-logs/24056/19 "2015-02-17T15:20:09Z")

</div>


