Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Service Worker in Facebook Browser

Got a problem where some of our users have a buggy Service Worker sitting in their Facebook Browsers from our sites.

The problem: Facebook App users are getting our 'you are offline page' on the FB browser when they access our pages shared on FB.

The bug appeared to be that an old version of Google's Workbox (3.6.1) was automatically returning the 'You Are Offline' page in the FB app using Chrome 75. Updating Workbox fixed it.

The reference to Workbox was in the service worker, so when we updated our Workbox version (which fixed the issue) some users still had the old one cached.

If users clear their FB App caches or reinstall FB, then all's well and they can see our content. But we'd like to try to force the SW to update without asking them to do that.

To wipe the old Service Worker out from the FB browser, we tried the following:

<script>
"use strict";
console.log("Service Worker Registration");

  function isFacebookApp() {
    var ua = navigator.userAgent || navigator.vendor || window.opera;
    return (ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1);
  }

  if ("serviceWorker" in navigator) {
    if(isFacebookApp() == true) {
      console.log("Service Worker Registration: using v2, via Facebook App");
      navigator.serviceWorker.getRegistrations().then(function(registrations) {
        for(let registration of registrations) {
          console.log("Service Worker Registration: "+registration);
          registration.unregister();
        }
      });
    } else {
      console.log("Service Worker Registration: using v2, not via Facebook App");
      window.addEventListener("load", () => {
          navigator.serviceWorker.register("/sw.js");
      });
    }
  }
</script>

However our analytics show that we're still getting hits on the You Are Offline page, and we're still getting reports from users that they can's follow links to our articles.

Can anyone help? Is there a way of forcing FB's in-app browser to update the cache, and get our users using a working Service Worker?

Update

So far we have tried:

  • Fooling the browser to update the Service worker by using a query string in the SW registration URL
  • Iterating through the registrations and unregister()ing (see above)
  • Using skipWaiting() in the Service Worker code
  • Adding 'no-cache' to our headers on sw.js
  • Ensuring that sw.js isn't being cached by the server
  • Removing or changing the /offline page resulted in net::ERR_FAILED error
  • We suspected that all our service worker revisions may have some unseen fault in them, so we tried an 'empty' service worker to see if that would work and flush out the others

Our analytics indicate the following:

  • Chrome Mobile 75 may be an issue
  • problems seem to have occurred since 6/7 June.

Nothing's worked: our Service Worker, or something, is still returning the Offline page...

like image 521
dogsolitude_uk Avatar asked Jun 20 '19 08:06

dogsolitude_uk


2 Answers

This is a bug in Chrome/the Chromium WebView, tracked in https://bugs.chromium.org/p/chromium/issues/detail?id=977784

The fix should be broadly rolled out at this point.

like image 198
Jeff Posnick Avatar answered Oct 19 '22 13:10

Jeff Posnick


we experienced the same problem but presenting slightly differently - our users began receiving an error message "net:: ERR FAILED" though it sounds like the same cause. The problem began around 10 days ago, and the only way I've managed to get around the cache is to send the users to a new version of the site - by removing the www. from the URL that I'm sending to, and stopping this from 301'ing to with the www.

I also tried a bunch of solutions like you have, but it doesn't seem to be possible to get the service worker to contact the website - if you put Charles between your phone and the internet you'll see no traffic reaches your site. I'm hoping that after a period of disuse the service worker will be cleaned up by the app cache and we can switch back. Sorry I can't be more help, but rest assured you're not alone!

like image 20
Paul Sharratt Avatar answered Oct 19 '22 11:10

Paul Sharratt