From 52adcc4a763316fb10cb8e7b803bf2f9dee03ffb Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sat, 23 Oct 2021 14:33:43 +0300 Subject: [PATCH] Disable WebGL2 on Safari (#799) --- html/src/components/terminal/index.tsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/html/src/components/terminal/index.tsx b/html/src/components/terminal/index.tsx index 7368915..535d50b 100644 --- a/html/src/components/terminal/index.tsx +++ b/html/src/components/terminal/index.tsx @@ -217,11 +217,31 @@ export class Xterm extends Component { } }; + const isSafari = () => { + // https://stackoverflow.com/questions/9847580 + if (/constructor/i.test(String(window["HTMLElement"]))) { + return true; + } + if (!window.top["safari"]) { + return false; + } + return String(window.top["safari"].pushNotification) === "[object SafariRemoteNotification]"; + }; + + const isIos = () => { + // https://stackoverflow.com/questions/9038625 + // https://github.com/lancedikson/bowser/issues/329 + return !!navigator.platform && ( + /iPad|iPhone|iPod/.test(navigator.platform) + || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1 && !window["MSStream"]) + ); + }; + const { terminal } = this; switch (value) { case 'webgl': if (this.webglAddon) return; - if (isWebGL2Available()) { + if (isWebGL2Available() && !isSafari() && !isIos()) { this.webglAddon = new WebglAddon(); terminal.loadAddon(this.webglAddon); console.log(`[ttyd] WebGL renderer enabled`); -- 2.43.4