Angular 6 Failed to execute 'postMessage' on 'Worker'
See original GitHub issueHello, I’ve been trying to use this example to make comlinkjs work in Angular: https://medium.com/lacolaco-blog/enjoyable-webworkers-in-angular-41cfeb0e6519 (example is working when checked out: example
However I can’t seem to replicate the example and I always get this error in my project
ERROR Error: Uncaught (in promise): DataCloneError: Failed to execute 'postMessage' on 'Worker': Symbol(Symbol.toPrimitive) could not be cloned.
Error: Failed to execute 'postMessage' on 'Worker': Symbol(Symbol.toPrimitive) could not be cloned.
Here is my setup
//generate-data-worker.ts
import { expose } from 'comlinkjs';
export class GenerateData {
generateData(source: string) {
return new Promise((resolve, reject) => {
resolve( "TEST" );
});
}
}
expose({GenerateData}, self);
//generate-data.service.ts
import {Injectable} from '@angular/core';
import {proxy} from 'comlinkjs';
const GenerateDataWokrer = proxy<
typeof import('../worker/generate-data').GenerateData
>(
new (Worker as any)('../worker/generate-data', { type: 'module' })
);
@Injectable({
providedIn: 'root'
})
export class GenerateDataService {
async generateData(source: string): Promise<any> {
const worker = await new GenerateDataWokrer();
return await worker.generateData(source);
}
}
calling it as:
this.genDataService.generateData(``).then((value) => {
console.log(value)
});
Can you help me understand from where is the error coming from?
Issue Analytics
- State:
- Created 5 years ago
- Comments:10
Top Results From Across the Web
Failed to execute 'postMessage' on 'Worker': An ...
I'm trying to run multiple instances of my web worker. But I'm getting the following error in browser console : core.js:4081 ERROR DOMException: ......
Read more ><Promise> could not be cloned. | Velo by Wix
Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': #<Promise> could not be cloned. Hello i am trying to generate a csv file ...
Read more >Worker.postMessage() - Web APIs | MDN
The postMessage() method of the Worker interface sends a message to the worker's inner scope. This accepts a single parameter, ...
Read more >failed to execute 'open' on 'xmlhttprequest': invalid url - You.com
I'm working on the frontend of a web application using Angular. When I send a GET request with Postman, it works properly, but...
Read more >Failed to execute 'postMessage' on 'Window': Invalid target ...
jQuery : Uncaught SyntaxError: Failed to execute ' postMessage ' on 'Window': Invalid target origin 'my_page' in a call to 'postMessage' ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for clarifying. I’m unable to reproduce the problem in a standalone project (it works there).
I believe this is some underlying angular configuration on my side. Let’s close the issue and I will respond when I find a solution.
No, it’s a React app, plain javascript through comlink for some share with >1 browser tabs.