【问题标题】:Safari iOS 11.3 not adding to workbox-background-syncSafari iOS 11.3 未添加到 workbox-background-sync
【发布时间】:2018-10-12 11:20:59
【问题描述】:

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

在 Safari iOS 11.3.1 上运行时,Service Worker 已注册,因为它会在日志中报告(Service Worker installed')。但我没有得到耶! Workbox 已加载 ???? 消息。

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

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

【问题讨论】:

标签: mobile-safari service-worker workbox


【解决方案1】:

您的 Service Worker 出现错误,因此 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

【讨论】:

    【解决方案2】:

    iOS 上的 Safari 不支持后台同步

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 2021-08-02
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      相关资源
      最近更新 更多