在Facebook浏览器中更新Service Worker [英] Update Service Worker in Facebook Browser

查看:109
本文介绍了在Facebook浏览器中更新Service Worker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到了一个问题,我们的某些用户从我们的网站的Facebook浏览器中坐着一辆有问题的服务人员.

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

问题:当Facebook App用户访问我们在FB上共享的页面时,他们在FB浏览器上获得了您离线页面".

该错误似乎是由于Google Workbox(3.6.1)的旧版本正在使用Chrome 75自动返回FB应用程序中的您处于离线状态"页面.更新Workbox对其进行了修复.

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.

对Workbox的引用是在服务工作者中进行的,因此,当我们更新Workbox版本(解决了该问题)时,某些用户仍然可以缓存旧版本.

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.

如果用户清除其FB应用程序缓存或重新安装FB,则一切正常,他们可以看到我们的内容.但是我们想尝试强迫软件更新而不要求他们这样做.

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.

要从FB浏览器中清除旧的Service Worker,我们尝试了以下操作:

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.

任何人都可以帮忙吗?有没有一种方法可以强制FB的应用程序内浏览器更新缓存,并让我们的用户使用正常的Service Worker?

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?

更新

到目前为止,我们已经尝试过:

So far we have tried:

  • 使用SW注册URL中的查询字符串欺骗浏览器以更新Service Worker
  • 遍历注册并进行unregister()处理(请参见上文)
  • 在Service Worker代码中使用skipWaiting()
  • 在sw.js的标头中添加"no-cache"
  • 确保服务器未缓存sw.js
  • 删除或更改/offline页面导致net::ERR_FAILED错误
  • 我们怀疑所有服务人员的修订版本可能都存在一些看不见的错误,因此我们尝试了一个空"服务人员以查看是否可行,并清除了其他版本
  • 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

我们的分析表明:

  • Chrome Mobile 75可能是个问题
  • 自6月6日至7日以来似乎已经出现问题.

什么都没做:我们的服务人员,或者说某事,仍在返回离线页面...

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

推荐答案

这是Chrome/Chromium WebView中的错误,可在

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.

这篇关于在Facebook浏览器中更新Service Worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆