diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js
index badc551048420..765c052a2f575 100644
--- a/src/lib/libpthread.js
+++ b/src/lib/libpthread.js
@@ -423,6 +423,15 @@ var LibraryPThread = {
var p = trustedTypes.createPolicy('emscripten#workerPolicy1', { createScriptURL: (ignored) => import.meta.url });
worker = new Worker(p.createScriptURL('ignored'), {{{ pthreadWorkerOptions }}});
} else
+#endif
+#if expectToReceiveOnModule('mainScriptUrlOrBlob')
+ if (Module['mainScriptUrlOrBlob']) {
+ var pthreadMainJs = Module['mainScriptUrlOrBlob'];
+ if (typeof pthreadMainJs != 'string') {
+ pthreadMainJs = URL.createObjectURL(pthreadMainJs);
+ }
+ worker = new Worker(pthreadMainJs, {{{ pthreadWorkerOptions }}});
+ } else
#endif
// We need to generate the URL with import.meta.url as the base URL of the JS file
// instead of just using new URL(import.meta.url) because bundler's only recognize
diff --git a/test/pthread/main_js_as_blob_loader.html b/test/pthread/main_js_with_loader.html
similarity index 91%
rename from test/pthread/main_js_as_blob_loader.html
rename to test/pthread/main_js_with_loader.html
index 2ec93f75ec0ff..0112c5e356902 100644
--- a/test/pthread/main_js_as_blob_loader.html
+++ b/test/pthread/main_js_with_loader.html
@@ -147,28 +147,6 @@
};
-
+