Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/web/js/engine/features.js
10279 views
1
const Features = {
2
/**
3
* Check whether WebGL is available. Optionally, specify a particular version of WebGL to check for.
4
*
5
* @param {number=} [majorVersion=1] The major WebGL version to check for.
6
* @returns {boolean} If the given major version of WebGL is available.
7
* @function Engine.isWebGLAvailable
8
*/
9
isWebGLAvailable: function (majorVersion = 1) {
10
try {
11
return !!document.createElement('canvas').getContext(['webgl', 'webgl2'][majorVersion - 1]);
12
} catch (e) { /* Not available */ }
13
return false;
14
},
15
16
/**
17
* Check whether the Fetch API available and supports streaming responses.
18
*
19
* @returns {boolean} If the Fetch API is available and supports streaming responses.
20
* @function Engine.isFetchAvailable
21
*/
22
isFetchAvailable: function () {
23
return 'fetch' in window && 'Response' in window && 'body' in window.Response.prototype;
24
},
25
26
/**
27
* Check whether the engine is running in a Secure Context.
28
*
29
* @returns {boolean} If the engine is running in a Secure Context.
30
* @function Engine.isSecureContext
31
*/
32
isSecureContext: function () {
33
return window['isSecureContext'] === true;
34
},
35
36
/**
37
* Check whether the engine is cross origin isolated.
38
* This value is dependent on Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers sent by the server.
39
*
40
* @returns {boolean} If the engine is running in a Secure Context.
41
* @function Engine.isSecureContext
42
*/
43
isCrossOriginIsolated: function () {
44
return window['crossOriginIsolated'] === true;
45
},
46
47
/**
48
* Check whether SharedBufferArray is available.
49
*
50
* Most browsers require the page to be running in a secure context, and the
51
* the server to provide specific CORS headers for SharedArrayBuffer to be available.
52
*
53
* @returns {boolean} If SharedArrayBuffer is available.
54
* @function Engine.isSharedArrayBufferAvailable
55
*/
56
isSharedArrayBufferAvailable: function () {
57
return 'SharedArrayBuffer' in window;
58
},
59
60
/**
61
* Check whether the AudioContext supports AudioWorkletNodes.
62
*
63
* @returns {boolean} If AudioWorkletNode is available.
64
* @function Engine.isAudioWorkletAvailable
65
*/
66
isAudioWorkletAvailable: function () {
67
return 'AudioContext' in window && 'audioWorklet' in AudioContext.prototype;
68
},
69
70
/**
71
* Return an array of missing required features (as string).
72
*
73
* @returns {Array<string>} A list of human-readable missing features.
74
* @function Engine.getMissingFeatures
75
* @param {{threads: (boolean|undefined)}} supportedFeatures
76
*/
77
getMissingFeatures: function (supportedFeatures = {}) {
78
const {
79
// Quotes are needed for the Closure compiler.
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
// Audio is normally optional since we have a dummy fallback.
104
return missing;
105
},
106
};
107
108