Android+Chrome not registering service workers


(Jeff Wong) #1

Noticed today that new service worker registration isn’t firing on Android Chrome, tested on a Pixel XL - Chrome 65.0.3325.109

It appears like the event listener isn’t firing here:

@tgxworld It seemed pretty deliberate to have that event listener, but can we do without it?


(Alan Tan) #2

So from what I tested on Android Chrome, the load event seems to only fire when the page is first loaded into a new tab. Once the tab has been loaded, the load event doesn’t fire until I close the tab and create a new one. Not sure if that is the intended behavior that the Chrome team wanted, perhaps we should check with them on this.

It was what the ServiceWorker guide from Google recommended when I was reading through the guide a few months back.

A simple rule of thumb would be to delay registration until after the load event fires on window , like so

We can definitely do without it but that does mean we have to be sure that whatever is happening in the initializer does not affect the page load time significantly.


(Jeff Wong) #3

It’s strange because it’s not consistent. Sometimes I’m able to get the service worker in a new tab and refresh both (more consistently on meta), but on other sites I cannot seem to get the service worker to re-install even when opening a new tab.

My best guess is that ember’s initialization method may fire after the window’s load event, so it never gets called in some cases.

Other oddities, the service worker registrations only work in production environments with compiled assets - I’ve added a registration case for development as well.

I’ve prepared a PR with the suggested fixes, let me know if it looks OK:


(Kane York) #4

Another candidate for “delay until there’s not too much work” is requestIdleCallback.


(Jeff Wong) #5

A nice suggestion - just wish there was more browser support for it. :frowning:


(Sam Saffron) #6

Simplest is just to measure, if real short skip delay, if longer than 3ms sleep 3 seconds and register


(Jeff Wong) #7

I haven’t seen that function take longer than 0.2ms. I’ve measured it around 0.17ms on average, so it seems OK without the delay.


(Jeff Wong) #8