Safari iOS 11.3未添加到workbox-background-sync

时间:2018-05-02 11:04:02

标签: mobile-safari service-worker workbox

我遵循了有关服务工作者和后台同步的教程: https://codelabs.developers.google.com/codelabs/workbox-indexeddb/index.html?index=..%2F..%2Findex#0

在Safari iOS 11.3.1上运行时,服务工作者已注册,因为它已在日志中报告(已安装的服务工作者' )。但我没有得到 Yay!工作箱已加载消息。

IndexedDB工作正常,对象从服务器的每个fetch更新。

但是,当我故意离线并执行POST时,没有任何内容写入IndexedDB队列。我的问题是: 1.我在哪里可以检查Web Inspector中的服务人员? 2. workbox-background-sync是否支持Safari iOS 11.3.1?如果是的话,我的设置有什么问题?

1 个答案:

答案 0 :(得分:0)

服务工作者出现错误,因此Workbox无法加载。在示例中,您必须添加一个正则表达式表达式:

将以下内容替换为服务人员:

workbox.routing.registerRoute(
  \/api\/add,
  networkWithBackgroundSync,
  'POST'
);

使用此:

const bgSyncPlugin = new workbox.backgroundSync.Plugin('offlineQueue', {
  maxRetentionTime: 48 * 60 // 48 hours retention on Indexed DB (up to your needs)
});

workbox.routing.registerRoute(
      new RegExp('./api\/add'),
      workbox.strategies.networkOnly({
        plugins: [bgSyncPlugin]
      }),
      'POST'
    );

在Safari 11.3.1上,您只能使请求入队,但尚不支持完整的后台支持。检查:https://github.com/GoogleChrome/workbox/issues/1466