0
votes

Im facing an issue when registering my service worker, got a rejected promise and the error description says "TypeError: Invalid argument")

any thoughts ?

Thanks! German.

Note 1: This happens only when https is on, using localhost works like a charm).

Note 2: This happens only on Microsoft Edge (ver 17), Chrome and Firefoxs works as expected.

Note 3: Im working in an non authenticated scenario, just pointing this out because of this thread: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/17360912/

Note 4: example working site using service worker on Edge: https://serviceworke.rs/strategy-cache-only_demo.html (proves that indeed there's a solution!)

This is my code:

navigator.serviceWorker.register("sw.js")
.then(function() {
alert("never goes here..");
})
.catch(function(e) { 
alert("always enter here!!"); 
});
1

1 Answers

2
votes

I ran into the same error on Edge 16 and in my case the solution was to remove object spread operators ({ someAttr, ...spread }) from the service worker.

It appears that Type Error: Invalid Argument can be thrown if Edge is not able to parse the script correctly, so I suggest you check your code to see if you're using any unsupported features.

This may not be relevant to your case since you said it worked fine on localhost, but I hope this helps somebody anyway.