Stub console.* calls for IE compatibility #344

plievone opened this Issue Jan 24, 2013 · 7 comments


None yet
3 participants

I pulled the current master and packed the demo app assets, then grepped for some usual suspects in IE compatibility. There are (perhaps from browserify, so in all socketstream builds) some calls to console.error, console.trace and console.log. Perhaps one should make them empty functions if they are not defined (and with a typeof check as IE can break when coercing native functions to booleans)

if (typeof console == 'undefined') console = {};
if (typeof console.log == 'undefined') console.log = function() {};
if (typeof console.error == 'undefined') console.error = function() {};
if (typeof console.trace == 'undefined') console.trace = function() {};

paulbjensen commented May 18, 2013

Hi, there's a bit of Javascript you can use to stub out console for IE here:

Is this still an issue with SocketStream 0.3.4? I'm wondering if browserify didn't clean up the calls to console by now.


paulbjensen commented May 18, 2013

Oh wait, it is. Nevermind. I will make a PR with this patch for IE.


thepian commented Oct 20, 2014

I've done various implementations of this for EssentialJS

It turns out that 'console' is a magic keyword on IE8, so you can't even make a variable called console and have it work properly.

Given the line

 var console = {};

When running without the debugger console will evaluate to undefined!

You have to convert console calls to something else on the serverside, or provide a console API.


paulbjensen commented Oct 20, 2014

Thanks for the info. A StackOverflow thread suggests some other possible options:


thepian commented Oct 23, 2014

I would recommend using an upgraded approach where you can ask for a console API for instance

ss.logger(logic_name) or ss.logger(module)

That way you get more benefit and you only have to minimally adjust your habit of writing console....

I think it deserves a standalone module, and I'd be happy to contribute. Once I have refactored EssentialJS to have a minimal core, I can contribute such a module based on just the core if that sounds like a good idea. Currently Essential is about the size of jQuery which is a bit bulky.

The current implementation can be found in

Look for proxyConsole


thepian commented Nov 28, 2014

TBH I suggest closing this issue as a wont fix. IE8 is rapidly dying even in Enterprise.

In a real setup you should have a build step to ensure that there are no console log statements in your production code, and other libraries take care of this sort of issue.

The golden fix would be a plugin that adds init code for legacy browser hacks


thepian commented Feb 1, 2015

I don't think this is a Socketstream concern. There are libraries to take care of these, and many approaches. Stubbing, is unfortunately not an option.

thepian closed this Feb 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment