Make code robust against missing `navigator`

This commit is contained in:
jos 2018-06-24 14:37:56 +02:00
parent 463276a3d9
commit cab3211e05
2 changed files with 5 additions and 4 deletions

View File

@ -144,7 +144,9 @@ var _defs = {
var _defaultLang = 'en';
var _lang;
var userLang = navigator.language || navigator.userLanguage;
var userLang = typeof navigator !== 'undefined'
? navigator.language || navigator.userLanguage
: undefined;
_lang = _locales.find(function (l) {
return l === userLang;
});

View File

@ -588,8 +588,7 @@ exports.getInnerText = function getInnerText(element, buffer) {
exports.getInternetExplorerVersion = function getInternetExplorerVersion() {
if (_ieVersion == -1) {
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
if (typeof navigator !== 'undefined' && navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null) {
@ -608,7 +607,7 @@ exports.getInternetExplorerVersion = function getInternetExplorerVersion() {
* @returns {boolean} isFirefox
*/
exports.isFirefox = function isFirefox () {
return (navigator.userAgent.indexOf("Firefox") != -1);
return (typeof navigator !== 'undefined' && navigator.userAgent.indexOf("Firefox") !== -1);
};
/**