josdejong / jsoneditor

A web-based tool to view, edit, format, and validate JSON
http://jsoneditoronline.org
Apache License 2.0
11.59k stars 2.04k forks source link

Avoid "console" errors in browsers that lack a console #319

Open aeberhardo opened 8 years ago

aeberhardo commented 8 years ago

In version 5.5.6 there are many instances of console.warn(..) and console.error(..). This can be problematic in browsers that don't support the console object like IE11: an "undefined object" error will be thrown potentially breaking the jsoneditor integration.

Before trying to log to the console I suggest checking for the existence of the console object.

Another option would be something like the following script by HTML5Boilderplate.com: https://github.com/h5bp/html5-boilerplate/blob/master/dist/js/plugins.js (it might be a bit too intrusive in the context of an JSON editor though).

josdejong commented 8 years ago

Thanks for bringing this up, we should add some polyfills there I suppose.

josdejong commented 8 years ago

I was looking into this issue, but it seems that both console.warn and console.error are supported in all browsers staring from IE8 and newer. So I think this is is no issue anymore (jsoneditor supports IE9 and newer).

https://developer.mozilla.org/en-US/docs/Web/API/Console/error#Browser_compatibility https://developer.mozilla.org/en-US/docs/Web/API/Console/warn#Browser_compatibility

If jsoneditor is used in some application that requires compatibility with really old browsers, you can always load polyfills yourself.