| 2847 | |
| 2848 | // eslint-disable-next-line complexity |
| 2849 | function useColors() { |
| 2850 | // NB: In an Electron preload script, document will be defined but not fully |
| 2851 | // initialized. Since we know we're in Chrome, we'll just detect this case |
| 2852 | // explicitly |
| 2853 | if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { |
| 2854 | return true; |
| 2855 | } |
| 2856 | |
| 2857 | // Internet Explorer and Edge do not support colors. |
| 2858 | if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { |
| 2859 | return false; |
| 2860 | } |
| 2861 | var m; |
| 2862 | |
| 2863 | // Is webkit? http://stackoverflow.com/a/16459606/376773 |
| 2864 | // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 |
| 2865 | // eslint-disable-next-line no-return-assign |
| 2866 | return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || |
| 2867 | // Is firebug? http://stackoverflow.com/a/398120/376773 |
| 2868 | typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || |
| 2869 | // Is firefox >= v31? |
| 2870 | // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages |
| 2871 | typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || |
| 2872 | // Double check webkit in userAgent just in case we are in a worker |
| 2873 | typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); |
| 2874 | } |
| 2875 | |
| 2876 | /** |
| 2877 | * Colorize log arguments if enabled. |