browser.js 3.1 KB

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