From 194b810ad518150198a3915563e8821a3264fd07 Mon Sep 17 00:00:00 2001 From: Taige Wang Date: Sun, 8 Oct 2023 13:03:28 +0300 Subject: [PATCH] Fix Webgl2 compatability on legacy Safari with webgl2 enabled --- addons/xterm-addon-webgl/src/WebglAddon.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index 3e091f0b87..61a8e2efb3 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -10,6 +10,7 @@ import { Disposable, toDisposable } from 'common/Lifecycle'; import { getSafariVersion, isSafari } from 'common/Platform'; import { ICoreService, IDecorationService, ILogService, IOptionsService } from 'common/services/Services'; import { ITerminalAddon, Terminal } from 'xterm'; +import { IWebGL2RenderingContext } from './Types'; import { WebglRenderer } from './WebglRenderer'; import { setTraceLogger } from 'common/services/LogService'; @@ -30,7 +31,16 @@ export class WebglAddon extends Disposable implements ITerminalAddon { private _preserveDrawingBuffer?: boolean ) { if (isSafari && getSafariVersion() < 16) { - throw new Error('Webgl2 is only supported on Safari 16 and above'); + // Perform an extra check to determine if Webgl2 is manually enabled in developer settings + const contextAttributes = { + antialias: false, + depth: false, + preserveDrawingBuffer: true + }; + const gl = document.createElement('canvas').getContext('webgl2', contextAttributes) as IWebGL2RenderingContext; + if (!gl) { + throw new Error('Webgl2 is only supported on Safari 16 and above'); + } } super(); }