Closed JanMisker closed 12 months ago
I did some digging, perhaps it is enough to just catch the TypeError
and then assume it is because the worker is a module worker?
https://github.com/whatwg/html/pull/608#issuecomment-183039469
Here another solution: https://stackoverflow.com/a/75802510/403991
function isModule() {
try{
importScripts("data:,");
return false;
} catch(e) {}
return true;
}
Thanks for the suggestions, fixed in 0.12.2
Describe the bug The worker script that loads the
ffmpeg-core.js
and.wasm
only works correctly on Chrome. The reason is the hardcoded check on the error message thrown whenimportScripts
is called inside a module worker. So this section: https://github.com/ffmpegwasm/ffmpeg.wasm/blob/c1b07068b79d19d5d3cc18011aad2e7bcba633e9/packages/ffmpeg/src/worker.ts#L51-L61On Chrome and Edge the TypeError message is:
Failed to execute 'importScripts' on 'WorkerGlobalScope': Module scripts don't support importScripts().
so it works with the check one.toString().includes("Module scripts")
.However on Safari and Firefox the error messages are different:
importScripts cannot be used if worker type is "module"
WorkerGlobalScope.importScripts: Using 'ImportScripts' inside a Module Worker is disallowed.
So the check fails and the script
I tested on macOS only, but I suppose it fails similarly on other systems. I guess the hardcoded string check could be extended, but I think a better way should be devised to figure whether the worker is a module?