| 1 |
const Features = { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
isWebGLAvailable: function (majorVersion = 1) { |
| 10 |
try { |
| 11 |
return !!document.createElement('canvas').getContext(['webgl', 'webgl2'][majorVersion - 1]); |
| 12 |
} catch (e) { } |
| 13 |
return false; |
| 14 |
}, |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
isFetchAvailable: function () { |
| 23 |
return 'fetch' in window && 'Response' in window && 'body' in window.Response.prototype; |
| 24 |
}, |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
isSecureContext: function () { |
| 33 |
return window['isSecureContext'] === true; |
| 34 |
}, |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
isCrossOriginIsolated: function () { |
| 44 |
return window['crossOriginIsolated'] === true; |
| 45 |
}, |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
isSharedArrayBufferAvailable: function () { |
| 57 |
return 'SharedArrayBuffer' in window; |
| 58 |
}, |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
isAudioWorkletAvailable: function () { |
| 67 |
return 'AudioContext' in window && 'audioWorklet' in AudioContext.prototype; |
| 68 |
}, |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
getMissingFeatures: function (supportedFeatures = {}) { |
| 78 |
const { |
| 79 |
|
| 80 |
'threads': supportsThreads = true, |
| 81 |
} = supportedFeatures; |
| 82 |
|
| 83 |
const missing = []; |
| 84 |
if (!Features.isWebGLAvailable(2)) { |
| 85 |
missing.push('WebGL2 - Check web browser configuration and hardware support'); |
| 86 |
} |
| 87 |
if (!Features.isFetchAvailable()) { |
| 88 |
missing.push('Fetch - Check web browser version'); |
| 89 |
} |
| 90 |
if (!Features.isSecureContext()) { |
| 91 |
missing.push('Secure Context - Check web server configuration (use HTTPS)'); |
| 92 |
} |
| 93 |
|
| 94 |
if (supportsThreads) { |
| 95 |
if (!Features.isCrossOriginIsolated()) { |
| 96 |
missing.push('Cross-Origin Isolation - Check that the web server configuration sends the correct headers.'); |
| 97 |
} |
| 98 |
if (!Features.isSharedArrayBufferAvailable()) { |
| 99 |
missing.push('SharedArrayBuffer - Check that the web server configuration sends the correct headers.'); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
return missing; |
| 105 |
}, |
| 106 |
}; |