6

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...

2
  • Thanks a lot for documenting the details @dogsolitude_uk - we are experiencing the same issue and are happy to find we are not the only ones...I've opened a discussion on developers.facebook.com/community/threads/2324574930953602 to hopefully get some official response on this. We are/were running the most recent version of Workbox (4.3.1) already. Do you know which fixed issue in specific solved your problem (for users without the SW registered already)?
    – leomelzer
    Jun 25, 2019 at 7:28
  • 1
    Thanks @leomelzer ... We've not yet found a fix or a way to force the FB browser to update it's cache. It simply doesn't listen! The issue appears to have got worse after the last update too: in some cases we're not even getting the /offline page and getting net: ERR Failed instead. Jun 25, 2019 at 7:34

2 Answers 2

2
+50

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.

5
  • Looks like it... Wow. The description perfectly describes what we've been seeing. Thanks Jeff! I'll comb through the report tomorrow, and if appropriate will mark this ans the answer and give you the bounty. Jun 26, 2019 at 16:17
  • That sounds like it to me - Facebook's browser is a webview and so would be affected by this. In my testing for this issue all serviceworkers break at the same time. Interesting that unregistering the sw didn't work for you - for us it did, just then never reinstalled a serviceworker thereafter!
    – Rowan
    Jun 26, 2019 at 16:39
  • FYI our tracking is showing the fix (or rather use of policies to revert the experiment?) has rolled out to ~two thirds of users by now, which is pretty quick considering it only started rolling out around a day ago. Based on my testing with switching engines to chrome 76 beta that fixes both service worker updates and fetch() calls within existing installed workers, so nothing more to clean up (phew).
    – Rowan
    Jun 26, 2019 at 16:46
  • @Rowan how did you go about unregistering your SW? We simply couldn't seem to get it to do that! Jun 28, 2019 at 9:48
  • @dogsolitude_uk I think I just did a navigator.serviceWorker.getRegistration().then(sw => sw.unregister()) - could see it unregister, but then wouldn't register again while broken. Newer versions of Chrome 75 and Chrome 76 are working great for me though!
    – Rowan
    Jul 6, 2019 at 12:56
1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.