features.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. export const PluginFeatureDetection = {
  7. get preferWebGl1() {
  8. if (typeof navigator === 'undefined' || typeof window === 'undefined') return false;
  9. // WebGL2 isn't working in MacOS 12.0.1 Safari 15.1, 15.2. It is working in Safari 15.4 tech preview, so disabling all versions before that.
  10. // prefer webgl 1 based on the userAgent substring
  11. const unpportedSafariVersions = [
  12. 'Version/15.1 Safari',
  13. 'Version/15.2 Safari',
  14. 'Version/15.3 Safari'
  15. ];
  16. if (unpportedSafariVersions.some(v => navigator.userAgent.indexOf(v) > 0)) {
  17. return true;
  18. }
  19. // Check for iOS device which enabled WebGL2 recently but it doesn't seem
  20. // to be full up to speed yet.
  21. // adapted from https://stackoverflow.com/questions/9038625/detect-if-device-is-ios
  22. const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
  23. const isAppleDevice = navigator.userAgent.includes('Macintosh');
  24. const isTouchScreen = navigator.maxTouchPoints >= 4; // true for iOS 13 (and hopefully beyond)
  25. return !(window as any).MSStream && (isIOS || (isAppleDevice && isTouchScreen));
  26. },
  27. get wboit() {
  28. if (typeof navigator === 'undefined' || typeof window === 'undefined') return true;
  29. // disable Wboit in Safari 15
  30. return !/Version\/15.\d Safari/.test(navigator.userAgent);
  31. }
  32. };