We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I am consuming a remote application inside a host application using Module Federation. The remote application includes a worker implementation.
Error: SecurityError: Failed to construct 'Worker': Script at 'http://localhost:3000/static/js/src_worker_js.chunk.js' cannot be accessed from origin 'http://localhost:3001/'.
http://localhost:3001
http://localhost:3000
src_worker_js.chunk.js
The worker with Comlink should function seamlessly without cross-origin access issues.
The browser throws a SecurityError, preventing the worker from being constructed.
SecurityError
The issue seems related to cross-origin restrictions when loading the worker script.
The text was updated successfully, but these errors were encountered:
Found the solution while using blob for worker need to explicitly mention the cdn package link
// worker code const workerCode = ` import * as Comlink from 'https://unpkg.com/comlink/dist/esm/comlink.mjs'; class FaceDetectionWorker { name; constructor() { this.name = "Face Detection Worker"; console.log(this.name) } consoleData(){ console.log(this.name) } } Comlink.expose(FaceDetectionWorker) `;
// worker initialization import * as Comlink from "comlink" const blob = new Blob([workerCode], { type: "application/javascript", }); const blobURL = URL.createObjectURL(blob); const worker = new Worker(blobURL, { type: "module", }); const worker = new Worker(); const FaceDetectionWorkerClass = Comlink.wrap(worker); this.faceDetectionWorker = await new FaceDetectionWorkerClass(); console.log("NAME", await this.faceDetectionWorker.name);
Sorry, something went wrong.
Hey, re-opening the issue for a better solution instead of above hack.
No branches or pull requests
I am consuming a remote application inside a host application using Module Federation. The remote application includes a worker implementation.
Error: SecurityError: Failed to construct 'Worker': Script at 'http://localhost:3000/static/js/src_worker_js.chunk.js' cannot be accessed from origin 'http://localhost:3001/'.
Context
http://localhost:3001
.http://localhost:3000
.src_worker_js.chunk.js
) is being accessed cross-origin.Steps to Reproduce
Expected Behavior
The worker with Comlink should function seamlessly without cross-origin access issues.
Actual Behavior
The browser throws a
SecurityError
, preventing the worker from being constructed.Potential Cause
The issue seems related to cross-origin restrictions when loading the worker script.
Environment
http://localhost:3001
http://localhost:3000
Additional Notes
Repo: https://github.com/KVPasupuleti/cra-module-federation
Branch : comlink-worker-issue-mfe
The text was updated successfully, but these errors were encountered: