yyx990803 / register-service-worker

A script to simplify service worker registration with hooks for common events.
MIT License
639 stars 58 forks source link

Error: Undefined is not a function when registering the service worker #19

Open kawazoe opened 5 years ago

kawazoe commented 5 years ago

I am getting a weird error on a production application when the service worker is registered. I cannot reproduce it on my own devices and it appear to only happen less than one percent of the time.

Our analytics tells us that some devices gets an "undefined is not a function" at https://github.com/yyx990803/register-service-worker/blob/master/src/index.js#L44 on the then call. This seems to indicate that the register() call returned undefined which is not valid according to the spec.

The devices that trigger those errors are running Android 7, 8 or 8.1 and using Chrome 70, 71 or Samsung Internet 7.4 or 8 or 8.1 so they should have support for service workers. We are also getting calls from those browsers/os that do work fine.

I don't think there is much that can be done on your side beside checking the result of the register call and emiting an error if it's not a promise. Have you even seen this problem before? I can't seem to find anyone complaining about this.

clifford-lc commented 5 years ago

We are getting the same errors reported through bugsnag: undefined is not a function

node_modules/register-service-worker/index.js:47 - registerValidSW

If any information or a fix is possible, would be great.

franciscolourenco commented 5 years ago

Same here, also w/ bugsnag

SylverFox commented 5 years ago

Same here, caught by Sentry/Raven Additional info:

Browser: Chrome version: 74.0.3729 OS: Windows 10 User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36

AntonioAngelino commented 4 years ago

Same here, caught by Rollbar

UA: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

File webpack:///./node_modules/register-service-worker/index.js line 52 col 6 in o .then(function (registration) { File webpack:///./node_modules/register-service-worker/index.js line 43 col 9 in [anonymous] registerValidSW(swUrl, emit, registrationOptions)

SylverFox commented 4 years ago

Update since July, the exception is caught every now and then and happens across all combinations of users/devices/OS's/browsers. (currently 184 events over 41 users) It's strange that the 'ready' function is defined but 'register' is not, possibly a race condition during the serviceWorker init?

haoqunjiang commented 4 years ago

Do you have any real-world web pages to reproduce the error? I can't debug it by just looking at the error messages.

kawazoe commented 4 years ago

@sodatea I do but since it an app that is meant to be private, I would feel better sharing the link privately. Do you have any other channel we could use for this?

Also, keep in mind that this is happening less that 1% of the time and I have never seen it happening on our machines. It only happened in the wild, and very rarely.

haoqunjiang commented 4 years ago

@kawazoe You can find me on discord as sodatea#9125. My email's haoqunjiang@gmail.com.

kawazoe commented 4 years ago

I've sent you an email with some extra details.

haoqunjiang commented 4 years ago

@kawazoe Thanks! I'll have a look.

agarwalvinit commented 4 years ago

Any update on this ?

haoqunjiang commented 4 years ago

I still can't locate the bug

kawazoe commented 4 years ago

@sodatea I think that at this point, maybe we should open an issue in webkit? I feel like this is more on their side if the call to register() returns undefined.

haoqunjiang commented 4 years ago

Yeah, but maybe in Blink instead? As the above-mentioned user-agent strings are all from Chrome.

kawazoe commented 4 years ago

Chromium bug link: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616