summaryrefslogtreecommitdiff
path: root/core/util/browser.js
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2022-10-13 09:14:49 +0200
committerPierre Ossman <ossman@cendio.se>2022-12-27 12:50:57 +0100
commitee5e3c5fa3f247d032d48554cb41a63315522870 (patch)
treec3f957ae5ec36631c2334603efe6f3a79b1b0a9a /core/util/browser.js
parent4a34ee4b1e1da67111d50eb2cd059e38aae4349a (diff)
downloadnovnc-ee5e3c5fa3f247d032d48554cb41a63315522870.tar.gz
Refine browser detection
Try to follow the principle outlined by Mozilla when detecting browsers and engines.
Diffstat (limited to 'core/util/browser.js')
-rw-r--r--core/util/browser.js46
1 files changed, 43 insertions, 3 deletions
diff --git a/core/util/browser.js b/core/util/browser.js
index fb0d344..7d2bfd8 100644
--- a/core/util/browser.js
+++ b/core/util/browser.js
@@ -77,6 +77,8 @@ export const hasScrollbarGutter = _hasScrollbarGutter;
* It's better to use feature detection than platform detection.
*/
+/* OS */
+
export function isMac() {
return !!(/mac/i).exec(navigator.platform);
}
@@ -91,12 +93,50 @@ export function isIOS() {
!!(/ipod/i).exec(navigator.platform));
}
+/* Browser */
+
export function isSafari() {
- return (navigator.userAgent.indexOf('Safari') !== -1 &&
- navigator.userAgent.indexOf('Chrome') === -1);
+ return !!navigator.userAgent.match('Safari/...') &&
+ !navigator.userAgent.match('Chrome/...') &&
+ !navigator.userAgent.match('Chromium/...') &&
+ !navigator.userAgent.match('Epiphany/...');
}
export function isFirefox() {
- return !!(/firefox/i).exec(navigator.userAgent);
+ return !!navigator.userAgent.match('Firefox/...') &&
+ !navigator.userAgent.match('Seamonkey/...');
+}
+
+export function isChrome() {
+ return !!navigator.userAgent.match('Chrome/...') &&
+ !navigator.userAgent.match('Chromium/...') &&
+ !navigator.userAgent.match('Edg/...') &&
+ !navigator.userAgent.match('OPR/...');
+}
+
+export function isChromium() {
+ return !!navigator.userAgent.match('Chromium/...');
+}
+
+export function isOpera() {
+ return !!navigator.userAgent.match('OPR/...');
}
+export function isEdge() {
+ return !!navigator.userAgent.match('Edg/...');
+}
+
+/* Engine */
+
+export function isGecko() {
+ return !!navigator.userAgent.match('Gecko/...');
+}
+
+export function isWebKit() {
+ return !!navigator.userAgent.match('AppleWebKit/...') &&
+ !navigator.userAgent.match('Chrome/...');
+}
+
+export function isBlink() {
+ return !!navigator.userAgent.match('Chrome/...');
+}