]> git.proxmox.com Git - mirror_novnc.git/blob - core/util/browser.js
4b371e307d871ad42aabe5623e97211fd401355f
[mirror_novnc.git] / core / util / browser.js
1 /*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2019 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
5 *
6 * See README.md for usage and integration instructions.
7 */
8
9 import * as Log from './logging.js';
10
11 // Touch detection
12 export let isTouchDevice = ('ontouchstart' in document.documentElement) ||
13 // requried for Chrome debugger
14 (document.ontouchstart !== undefined) ||
15 // required for MS Surface
16 (navigator.maxTouchPoints > 0) ||
17 (navigator.msMaxTouchPoints > 0);
18 window.addEventListener('touchstart', function onFirstTouch() {
19 isTouchDevice = true;
20 window.removeEventListener('touchstart', onFirstTouch, false);
21 }, false);
22
23
24 // The goal is to find a certain physical width, the devicePixelRatio
25 // brings us a bit closer but is not optimal.
26 export let dragThreshold = 10 * (window.devicePixelRatio || 1);
27
28 let _supportsCursorURIs = false;
29
30 try {
31 const target = document.createElement('canvas');
32 target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
33
34 if (target.style.cursor.indexOf("url") === 0) {
35 Log.Info("Data URI scheme cursor supported");
36 _supportsCursorURIs = true;
37 } else {
38 Log.Warn("Data URI scheme cursor not supported");
39 }
40 } catch (exc) {
41 Log.Error("Data URI scheme cursor test exception: " + exc);
42 }
43
44 export const supportsCursorURIs = _supportsCursorURIs;
45
46 let _supportsImageMetadata = false;
47 try {
48 new ImageData(new Uint8ClampedArray(4), 1, 1);
49 _supportsImageMetadata = true;
50 } catch (ex) {
51 // ignore failure
52 }
53 export const supportsImageMetadata = _supportsImageMetadata;
54
55 export function isMac() {
56 return navigator && !!(/mac/i).exec(navigator.platform);
57 }
58
59 export function isWindows() {
60 return navigator && !!(/win/i).exec(navigator.platform);
61 }
62
63 export function isIOS() {
64 return navigator &&
65 (!!(/ipad/i).exec(navigator.platform) ||
66 !!(/iphone/i).exec(navigator.platform) ||
67 !!(/ipod/i).exec(navigator.platform));
68 }
69
70 export function isAndroid() {
71 return navigator && !!(/android/i).exec(navigator.userAgent);
72 }
73
74 export function isSafari() {
75 return navigator && (navigator.userAgent.indexOf('Safari') !== -1 &&
76 navigator.userAgent.indexOf('Chrome') === -1);
77 }
78
79 export function isIE() {
80 return navigator && !!(/trident/i).exec(navigator.userAgent);
81 }
82
83 export function isEdge() {
84 return navigator && !!(/edge/i).exec(navigator.userAgent);
85 }
86
87 export function isFirefox() {
88 return navigator && !!(/firefox/i).exec(navigator.userAgent);
89 }
90