Skip to content

chore: safari support #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lib/client/adapters/webcontainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const converter = new AnsiToHtml({
/** @type {import('@webcontainer/api').WebContainer} Web container singleton */
let vm;

function webcontainer_is_supported() {
// @ts-ignore
return 'function' === typeof Atomics.waitAsync;
}

/**
* @param {import('svelte/store').Writable<string | null>} base
* @param {import('svelte/store').Writable<Error | null>} error
Expand All @@ -25,8 +30,8 @@ let vm;
* @returns {Promise<import('$lib/types').Adapter>}
*/
export async function create(base, error, progress, logs, warnings) {
if (/safari/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent)) {
throw new Error('WebContainers are not supported by Safari');
if (/safari/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent) && !webcontainer_is_supported()) {
throw new Error('WebContainers are not supported by Safari 16.3 or earlier');
}

progress.set({ value: 0, text: 'loading files' });
Expand Down
7 changes: 6 additions & 1 deletion src/routes/tutorial/[slug]/Loading.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@

/** @type {string} */
export let status;

function webcontainer_is_supported() {
// @ts-ignore
return 'function' === typeof Atomics.waitAsync;
}
</script>

<div class="loading" class:error>
{#if error}
{#if /safari/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent)}
{#if /safari/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent) && !webcontainer_is_supported()}
<p>This app requires modern web platform features. Please use a browser other than Safari.</p>
{:else}
<small>{error.message}</small>
Expand Down