Ensure browser supports workers-in-workers (#1325)

Fixes #1324
This commit is contained in:
Jake Archibald
2023-01-09 10:42:14 +00:00
committed by GitHub
parent 13a185def2
commit 583117697e
12 changed files with 39 additions and 16 deletions

View File

@@ -0,0 +1,17 @@
import { threads } from 'wasm-feature-detect';
export default async function checkThreadsSupport() {
const supportsWasmThreads = await threads();
if (!supportsWasmThreads) return false;
// Safari 16 shipped with WASM threads support, but it didn't ship with nested workers support.
// This meant Squoosh failed in Safari 16, since we call our wasm from inside a worker to begin with.
// Right now, this check is only run from a worker.
// More implementation is needed to run it from a page.
if (!('importScripts' in self)) {
throw Error('Not implemented');
}
return 'Worker' in self;
}