question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular 6 Failed to execute 'postMessage' on 'Worker'

See original GitHub issue

Hello, 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:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
kzmvcommented, Mar 20, 2019

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.

0reactions
sansatocommented, May 8, 2019

No, it’s a React app, plain javascript through comlink for some share with >1 browser tabs.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found