logdown.js icon indicating copy to clipboard operation
logdown.js copied to clipboard

Missing methods on IE when "Disable Script Debugging" is enabled

Open OzairP opened this issue 6 years ago • 2 comments

On IE (tested on 11 bug same behavior reported on 8 & 9) if the "Disable Script Debugging" setting is enabled IE only provides console.error unless the console is open. This behavior is explains #29.

Attached is the execution of alert(Object.keys(console).join(', ')). (reactStack and reactStackEnd are side effects of React but is not relevant) IE11

This is the same execution but when the console is open. IE11 with console Tested on IE 11.15.16299.0 via BrowserStack

OzairP avatar Aug 23 '19 17:08 OzairP

You can find an explanation of this behavior in this blog post, https://www.beyondjava.net/console-log-surprises-with-internet-explorer-11-and-edge.

This solution worked for me, https://stackoverflow.com/questions/7742781/why-does-javascript-only-work-after-opening-developer-tools-in-ie-once

I've simplified it to this however,

var console = window.console = window.console || {};
[
    'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
    'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
    'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
    'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
].forEach(function (method) {
    if (!console[method]) {
        console[method] = function () {};
    }
});

I will submit a PR later today fixing this issue.

OzairP avatar Aug 23 '19 17:08 OzairP

I have held back on a PR since I am not sure if @caiogondim wants polyfills essentially bundled in the library.

CoreJS, which are the standard polyfills Babel uses, had console polyfills but they were removed for some reason. So users using this package with CoreJS will encounter this error. I've opened an issue for this https://github.com/zloirock/core-js/issues/633.

Solutions

  1. Bundle console polyfill, it's small but some clients may not want it
  2. Split the console polyfill and warn developers that they need to include it if they are not using CoreJS but want to support IE (only if CoreJS will re-introduce console polyfill)

OzairP avatar Aug 29 '19 20:08 OzairP