Skip to content

Commit 46fc6f5

Browse files
authored
fix: Catch errors when detecting if WebGL is supported (#2426)
- In some headless environments, `document` is `undefined` and this would throw an uncaught exception - Just catch the exception and return `false` - Now this matches the same check that was added to the plotly-express plugin: deephaven/deephaven-plugins#1147
1 parent f006bca commit 46fc6f5

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

packages/chart/src/ChartUtils.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ function isRangedPlotlyAxis(value: unknown): value is { range: Range[] } {
149149
*
150150
* @returns True if Web GL is supported, false otherwise
151151
*/
152-
function isWebGLSupported(): boolean {
153-
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/By_example/Detect_WebGL
154-
const canvas = document.createElement('canvas');
155-
const gl =
156-
canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
157-
return gl != null && gl instanceof WebGLRenderingContext;
152+
export function isWebGLSupported(): boolean {
153+
try {
154+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/By_example/Detect_WebGL
155+
const canvas = document.createElement('canvas');
156+
const gl =
157+
canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
158+
return gl != null && gl instanceof WebGLRenderingContext;
159+
} catch (e) {
160+
return false;
161+
}
158162
}
159163

160164
const IS_WEBGL_SUPPORTED = isWebGLSupported();

0 commit comments

Comments
 (0)