0

I used the steps described here to convert my Angular4 app to a web worker. When I run the app, I see the following error:

enter image description here

The change I have from my existing Angular4 app and the new one is the support of the web worker.

The error does not give any clue of what component or code is causing this. Is there a tracing that I can add to somewhere to find what is causing this error?

---- UPDATE 6/28 -----

The error is generated from the following code

WorkerDomAdapter.prototype.getCookie = function (name) { throw 'not implemented'; }; in platform-webworker.umd.js

The getCookie call is made by http.umd.js.

enter image description here

wonderful world
  • 10,969
  • 20
  • 97
  • 194

2 Answers2

1

You can't access cookies with a web-worker, as well as localStorage or sessionStorage aren't accessible.

A similar topic with some more information can be found here: Accessing localStorage from a webWorker

malifa
  • 8,025
  • 2
  • 42
  • 57
1

The solution to this problem is to create a custom XSRFStrategy so the Angular http module uses the custom rather than the default one.

import { HttpModule, XSRFStrategy, Request } from '@angular/http';

...

class CustomXSRFStrategy extends XSRFStrategy
{
    public configureRequest(req: Request) { /* */ }
}

...

 providers: [{ provide: XSRFStrategy, useValue: new CustomXSRFStrategy() }]
wonderful world
  • 10,969
  • 20
  • 97
  • 194