]>
git.proxmox.com Git - mirror_novnc.git/blob - core/util/browser.js
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2019 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
6 * See README.md for usage and integration instructions.
8 * Browser feature support detection
11 import * as Log
from './logging.js';
14 export let isTouchDevice
= ('ontouchstart' in document
.documentElement
) ||
15 // requried for Chrome debugger
16 (document
.ontouchstart
!== undefined) ||
17 // required for MS Surface
18 (navigator
.maxTouchPoints
> 0) ||
19 (navigator
.msMaxTouchPoints
> 0);
20 window
.addEventListener('touchstart', function onFirstTouch() {
22 window
.removeEventListener('touchstart', onFirstTouch
, false);
26 // The goal is to find a certain physical width, the devicePixelRatio
27 // brings us a bit closer but is not optimal.
28 export let dragThreshold
= 10 * (window
.devicePixelRatio
|| 1);
30 let _supportsCursorURIs
= false;
33 const target
= document
.createElement('canvas');
34 target
.style
.cursor
= 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
36 if (target
.style
.cursor
.indexOf("url") === 0) {
37 Log
.Info("Data URI scheme cursor supported");
38 _supportsCursorURIs
= true;
40 Log
.Warn("Data URI scheme cursor not supported");
43 Log
.Error("Data URI scheme cursor test exception: " + exc
);
46 export const supportsCursorURIs
= _supportsCursorURIs
;
48 let _supportsImageMetadata
= false;
50 new ImageData(new Uint8ClampedArray(4), 1, 1);
51 _supportsImageMetadata
= true;
55 export const supportsImageMetadata
= _supportsImageMetadata
;
57 let _hasScrollbarGutter
= true;
59 // Create invisible container
60 const container
= document
.createElement('div');
61 container
.style
.visibility
= 'hidden';
62 container
.style
.overflow
= 'scroll'; // forcing scrollbars
63 document
.body
.appendChild(container
);
65 // Create a div and place it in the container
66 const child
= document
.createElement('div');
67 container
.appendChild(child
);
69 // Calculate the difference between the container's full width
70 // and the child's width - the difference is the scrollbars
71 const scrollbarWidth
= (container
.offsetWidth
- child
.offsetWidth
);
74 container
.parentNode
.removeChild(container
);
76 _hasScrollbarGutter
= scrollbarWidth
!= 0;
78 Log
.Error("Scrollbar test exception: " + exc
);
80 export const hasScrollbarGutter
= _hasScrollbarGutter
;
83 * The functions for detection of platforms and browsers below are exported
84 * but the use of these should be minimized as much as possible.
86 * It's better to use feature detection than platform detection.
89 export function isMac() {
90 return navigator
&& !!(/mac/i).exec(navigator
.platform
);
93 export function isWindows() {
94 return navigator
&& !!(/win/i).exec(navigator
.platform
);
97 export function isIOS() {
99 (!!(/ipad/i).exec(navigator
.platform
) ||
100 !!(/iphone/i).exec(navigator
.platform
) ||
101 !!(/ipod/i).exec(navigator
.platform
));
104 export function isSafari() {
105 return navigator
&& (navigator
.userAgent
.indexOf('Safari') !== -1 &&
106 navigator
.userAgent
.indexOf('Chrome') === -1);
109 export function isIE() {
110 return navigator
&& !!(/trident/i).exec(navigator
.userAgent
);
113 export function isEdge() {
114 return navigator
&& !!(/edge/i).exec(navigator
.userAgent
);
117 export function isFirefox() {
118 return navigator
&& !!(/firefox/i).exec(navigator
.userAgent
);