title: Update Service Worker in Facebook Browser
body: <p>Got a problem where some of our users have a buggy Service Worker sitting in their Facebook Browsers from our sites.</p>
  
  <p><strong>The problem: Facebook App users are getting our 'you are offline page' on the FB browser when they access our pages shared on FB.</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>To wipe the old Service Worker out from the FB browser, we tried the following:</p>
  
  <pre><code>&lt;script&gt;
  "use strict";
  console.log("Service Worker Registration");
  
    function isFacebookApp() {
      var ua = navigator.userAgent || navigator.vendor || window.opera;
      return (ua.indexOf("FBAN") &gt; -1) || (ua.indexOf("FBAV") &gt; -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", () =&gt; {
            navigator.serviceWorker.register("/sw.js");
        });
      }
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p><strong>Update</strong></p>
  
  <p>So far we have tried:</p>
  
  <ul>
  <li>Fooling the browser to update the Service worker by using a query string in the SW registration URL</li>
  <li>Iterating through the registrations and unregister()ing (see above)</li>
  <li>Using <code>skipWaiting()</code> in the Service Worker code</li>
  <li>Adding 'no-cache' to our headers on sw.js</li>
  <li>Ensuring that sw.js isn't being cached by the server</li>
  <li>Removing or changing the <code>/offline</code> page resulted in <code>net::ERR_FAILED</code> error</li>
  <li>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</li>
  </ul>
  
  <p>Our analytics indicate the following:</p>
  
  <ul>
  <li>Chrome Mobile 75 may be an issue</li>
  <li>problems seem to have occurred since 6/7 June.</li>
  </ul>
  
  <p>Nothing's worked: our Service Worker, or <em>something</em>, is still returning the Offline page...</p>