mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Match Chromium/ as well as Chrome/ so builds that omit Chrome in the user agent still see the install nudge. Cover with a unit test.
24 lines
1 KiB
JavaScript
24 lines
1 KiB
JavaScript
// Shared UA sniffing for the WROLPi browser extension UI.
|
|
// The extension only ships for Chromium (Chrome/Brave/Edge/Opera) and Firefox;
|
|
// Safari and other browsers should not be nudged to install it.
|
|
|
|
/**
|
|
* @returns {'firefox' | 'chromium' | 'unknown'}
|
|
*/
|
|
export function detectBrowser() {
|
|
if (typeof navigator === 'undefined') return 'unknown';
|
|
const ua = navigator.userAgent || '';
|
|
// Order matters: Edge / Brave / Opera all include 'Chrome' in their UA.
|
|
if (ua.includes('Firefox')) return 'firefox';
|
|
if (ua.includes('Edg/')) return 'chromium';
|
|
if (ua.includes('OPR/') || ua.includes('Opera')) return 'chromium';
|
|
// Pure Chromium builds may advertise Chromium/ without Chrome/.
|
|
if (ua.includes('Chrome') || ua.includes('Chromium')) return 'chromium';
|
|
return 'unknown';
|
|
}
|
|
|
|
/** True when the current browser can run the WROLPi extension. */
|
|
export function isExtensionSupportedBrowser() {
|
|
const browser = detectBrowser();
|
|
return browser === 'firefox' || browser === 'chromium';
|
|
}
|