Registering a service worker from a view fails

I’m trying to register a service worker from a view in Theia but it is failing with the following error:

DOMException: Failed to register a ServiceWorker: The document is in an invalid state.

The evidence points to the error being related to registering service workers from dynamically created iframes. Looking at the code in Theia, it seems like there is a workaround for this.

I tried creating an iframe in the same way with the same workaround in a sample project and it did allow me to register a service worker.

I can post my code if needed but what I’m trying is a textbook example of registering a service worker.

Theia version: 0.13 (unable to upgrade a the time being because of certain limitations).

What am I doing wrong or what am I missing?

Hi, you will need to share the reproducible repo.

Hi @akosyakov, I couldn’t share the company repo so I set up a sample project that replicates the problem above.

Hope this helps find the issue.

Hi Anton, just wondering if you had the chance to look at the linked repo. Thanks!

Well, it turns out I was testing on the wrong version all this time. It works just fine on version 0.13 and up.So never mind this…