forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #977 from PubMatic-OpenWrap/test_br_b2_20241203141724
Prebid upgarde automate- test pull request created through git api please ignore it
- Loading branch information
Showing
106 changed files
with
12,370 additions
and
2,637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@azhar.mulla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { logError } from '../../src/utils.js'; | ||
|
||
/** | ||
* Detects the browser using either userAgent or userAgentData | ||
* @return {string} The name of the detected browser or 'unknown' if unable to detect | ||
*/ | ||
export function detectBrowser() { | ||
try { | ||
if (navigator.userAgent) { | ||
return detectBrowserFromUserAgent(navigator.userAgent); | ||
} else if (navigator.userAgentData) { | ||
return detectBrowserFromUserAgentData(navigator.userAgentData); | ||
} | ||
} catch (error) { | ||
logError('Error detecting browser:', error); | ||
} | ||
return 'unknown'; | ||
} | ||
|
||
/** | ||
* Detects the browser from the user agent string | ||
* @param {string} userAgent - The user agent string from the browser | ||
* @return {string} The name of the detected browser or 'unknown' if unable to detect | ||
*/ | ||
export function detectBrowserFromUserAgent(userAgent) { | ||
const browserRegexPatterns = { | ||
opera: /Opera|OPR/, | ||
edge: /Edg/, | ||
chrome: /Chrome|CriOS/, | ||
safari: /Safari/, | ||
firefox: /Firefox/, | ||
ie: /MSIE|Trident/, | ||
}; | ||
|
||
// Check for Chrome first to avoid confusion with Safari | ||
if (browserRegexPatterns.chrome.test(userAgent)) { | ||
return 'chrome'; | ||
} | ||
|
||
// Now we can safely check for Safari | ||
if (browserRegexPatterns.safari.test(userAgent) && !browserRegexPatterns.chrome.test(userAgent)) { | ||
return 'safari'; | ||
} | ||
|
||
// Check other browsers | ||
for (const browser in browserRegexPatterns) { | ||
if (browserRegexPatterns[browser].test(userAgent)) { | ||
return browser; | ||
} | ||
} | ||
|
||
return 'unknown'; | ||
} | ||
|
||
/** | ||
* Detects the browser from the NavigatorUAData object | ||
* @param {NavigatorUAData} userAgentData - The user agent data object from the browser | ||
* @return {string} The name of the detected browser or 'unknown' if unable to detect | ||
*/ | ||
export function detectBrowserFromUserAgentData(userAgentData) { | ||
const brandNames = userAgentData.brands.map(brand => brand.brand); | ||
|
||
if (brandNames.includes('Microsoft Edge')) { | ||
return 'edge'; | ||
} else if (brandNames.includes('Opera')) { | ||
return 'opera'; | ||
} else if (brandNames.some(brand => brand === 'Chromium' || brand === 'Google Chrome')) { | ||
return 'chrome'; | ||
} | ||
|
||
return 'unknown'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.