Skip to content

Commit

Permalink
Fix missing userAgent error on nodejs (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
echatzief authored Jan 3, 2022
1 parent 5b689e5 commit 49d1a3a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@
* https://github.com/videojs/video.js/blob/4238f5c1d88890547153e7e1de7bd0d1d8e0b236/src/js/utils/browser.js
*/

// User agent example taken from Safari desktop:
const useAgent = navigator && navigator.userAgent || '';
/**
* Retrieve from the navigator the user agent property.
* @returns user agent property.
*/
function getUserAgent(){
return navigator && navigator.userAgent || '';
}

/**
* Detect if current browser is any Android
* @returns true if current browser is Android, false otherwise.
*/
export function isAndroid(){
return (/Android/i).test(useAgent);
const userAgent = getUserAgent();
return (/Android/i).test(userAgent);
}

/**
* Detect if current browser is any Edge
* @returns true if current browser is Edge, false otherwise.
*/
export function isEdge(){
return (/Edg/i).test(useAgent);
const userAgent = getUserAgent();
return (/Edg/i).test(userAgent);
}

/**
* Detect if current browser is chrome.
* @returns true if current browser is Chrome, false otherwise.
*/
export function isChrome(){
return !isEdge() && ((/Chrome/i).test(useAgent) || (/CriOS/i).test(useAgent));
const userAgent = getUserAgent();
return !isEdge() && ((/Chrome/i).test(userAgent) || (/CriOS/i).test(userAgent));
}

/**
Expand All @@ -38,5 +46,6 @@ export function isSafari(){
// User agents for other browsers might include "Safari" so we must exclude them.
// For example - this is the chrome user agent on windows 10:
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
return (/Safari/i).test(useAgent) && !isChrome() && !isAndroid() && !isEdge();
const userAgent = getUserAgent();
return (/Safari/i).test(userAgent) && !isChrome() && !isAndroid() && !isEdge();
}

0 comments on commit 49d1a3a

Please sign in to comment.