1
0
mirror of https://github.com/videojs/video.js.git synced 2025-03-17 21:18:27 +02:00

fix: logging failing on browsers that don't always have console (#3686)

In browsers like IE9, `console` isn't always available. This, we need to apply `console` to our console functions but bail out early if `window.console` isn't defined.
This commit is contained in:
Pat O'Neill 2016-10-18 12:02:28 -04:00 committed by Gary Katsevman
parent 44ec0e4e75
commit e932061024

View File

@ -19,14 +19,6 @@ let log;
*/
export const logByType = (type, args, stringify = !!IE_VERSION && IE_VERSION < 11) => {
// If there's no console then don't try to output messages, but they will
// still be stored in `log.history`.
//
// Was setting these once outside of this function, but containing them
// in the function makes it easier to test cases where console doesn't exist
// when the module is executed.
const fn = window.console && window.console[type] || function() {};
if (type !== 'log') {
// add the type to the front of the message when it's not "log"
@ -39,6 +31,19 @@ export const logByType = (type, args, stringify = !!IE_VERSION && IE_VERSION < 1
// add console prefix after adding to history
args.unshift('VIDEOJS:');
// If there's no console then don't try to output messages, but they will
// still be stored in `log.history`.
//
// Was setting these once outside of this function, but containing them
// in the function makes it easier to test cases where console doesn't exist
// when the module is executed.
const fn = window.console && window.console[type];
// Bail out if there's no console.
if (!fn) {
return;
}
// IEs previous to 11 log objects uselessly as "[object Object]"; so, JSONify
// objects and arrays for those less-capable browsers.
if (stringify) {
@ -62,7 +67,7 @@ export const logByType = (type, args, stringify = !!IE_VERSION && IE_VERSION < 1
if (!fn.apply) {
fn(args);
} else {
fn[Array.isArray(args) ? 'apply' : 'call'](console, args);
fn[Array.isArray(args) ? 'apply' : 'call'](window.console, args);
}
};