]> prime8.dev >> repos - ttyd.git/commitdiff
Disable WebGL2 on Safari (#799)
authorMaxim Devaev <mdevaev@gmail.com>
Sat, 23 Oct 2021 11:33:43 +0000 (14:33 +0300)
committerGitHub <noreply@github.com>
Sat, 23 Oct 2021 11:33:43 +0000 (19:33 +0800)
html/src/components/terminal/index.tsx

index 73689154aff043c0eca5269b3723ab30a78474eb..535d50b9dd0ef50f18acc71db8e6f7f019f8b048 100644 (file)
@@ -217,11 +217,31 @@ export class Xterm extends Component<Props> {
             }
         };
 
+        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`);