wrolpi/app/src/components/admin/browserDetect.js
Roland c79127e7da
app: treat pure Chromium UA as supported for extension banner
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.
2026-07-18 13:52:26 -06:00

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';
}