From 216c290c4b05353f976ce8fc72fe5afcff528671 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Sun, 6 Aug 2017 17:37:34 +0800 Subject: [PATCH] Check availability of console before using it (Fix IE9) --- src/Logger.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Logger.js b/src/Logger.js index e912883..bbdf241 100644 --- a/src/Logger.js +++ b/src/Logger.js @@ -10,21 +10,25 @@ export default class Logger { // eslint-disable-next-line flowtype/no-weak-types log(...args: any) { - Function.prototype.bind - .call(window.console.log, window.console) - .apply( - window.console, - [Date.now() - this.start + 'ms', 'html2canvas:'].concat([].slice.call(args, 0)) - ); + if (window.console && window.console.log) { + Function.prototype.bind + .call(window.console.log, window.console) + .apply( + window.console, + [Date.now() - this.start + 'ms', 'html2canvas:'].concat([].slice.call(args, 0)) + ); + } } // eslint-disable-next-line flowtype/no-weak-types error(...args: any) { - Function.prototype.bind - .call(window.console.error, window.console) - .apply( - window.console, - [Date.now() - this.start + 'ms', 'html2canvas:'].concat([].slice.call(args, 0)) - ); + if (window.console && window.console.error) { + Function.prototype.bind + .call(window.console.error, window.console) + .apply( + window.console, + [Date.now() - this.start + 'ms', 'html2canvas:'].concat([].slice.call(args, 0)) + ); + } } }