From 11a2c987e27b1b5671a1a0b5c67d99a2c75ff662 Mon Sep 17 00:00:00 2001 From: SamVerschueren Date: Thu, 27 Apr 2023 09:28:02 +0200 Subject: [PATCH] chore(safari): enable terminal on Safari 16.4 --- .../theme/components/Examples/WCEmbed/utils.ts | 12 +++++++++++- .../components/Examples/WCEmbed/webcontainer.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/.vitepress/theme/components/Examples/WCEmbed/utils.ts b/docs/.vitepress/theme/components/Examples/WCEmbed/utils.ts index a517776..dfdef55 100644 --- a/docs/.vitepress/theme/components/Examples/WCEmbed/utils.ts +++ b/docs/.vitepress/theme/components/Examples/WCEmbed/utils.ts @@ -1,15 +1,25 @@ /** * Checks if WebContainer is supported on the current browser. */ -export function isWebContainerSupported() { +export function isWebContainerSupported() { const hasSharedArrayBuffer = 'SharedArrayBuffer' in window; const looksLikeChrome = navigator.userAgent.toLowerCase().includes('chrome'); const looksLikeFirefox = navigator.userAgent.includes('Firefox'); + const looksLikeSafari = navigator.userAgent.includes('Safari'); if (hasSharedArrayBuffer && (looksLikeChrome || looksLikeFirefox)) { return true; } + if (hasSharedArrayBuffer && looksLikeSafari) { + // we only support Safari 16.4 and up so we check for the version here + const match = navigator.userAgent.match(/Version\/(\d+)\.(\d+) (?:Mobile\/.*?)?Safari/); + const majorVersion = match ? Number(match?.[1]) : 0; + const minorVersion = match ? Number(match?.[2]) : 0; + + return majorVersion > 16 || (majorVersion === 16 && minorVersion >= 4); + } + // Allow overriding the support check with localStorage.webcontainer_any_ua = 1 try { return Boolean(localStorage.getItem('webcontainer_any_ua')); diff --git a/docs/.vitepress/theme/components/Examples/WCEmbed/webcontainer.ts b/docs/.vitepress/theme/components/Examples/WCEmbed/webcontainer.ts index 90b0145..ff13fc0 100644 --- a/docs/.vitepress/theme/components/Examples/WCEmbed/webcontainer.ts +++ b/docs/.vitepress/theme/components/Examples/WCEmbed/webcontainer.ts @@ -112,7 +112,7 @@ async function bootWebContainer(terminal: import('xterm').Terminal) { [ red('Incompatible Web Browser'), '', - `WebContainers currently work in Chromium-based browsers and Firefox. We're hoping to add support for more browsers as they implement the necessary Web Platform features.`, + `WebContainers currently work in Chromium-based browsers, Firefox, and Safari 16.4. We're hoping to add support for more browsers as they implement the necessary Web Platform features.`, '', 'Read more about browser support:', 'https://webcontainers.io/guides/browser-support',