问题描述
几个月前,随着Apple宣布Service Worker支持iOS 11.3,我最近开始尝试让Service Worker在iOS上工作.在Safari上,它可以按预期工作,在访问网站后,它可以脱机工作.但是,当尝试在Chrome中使用相同功能时,出现了间歇性的结果.具体来说,服务工作者只能每隔刷新一次页面,而离线后的原始刷新是不起作用的一种.
As Apple announced Service Worker support for iOS 11.3 a few months ago, I recently started trying to get a service worker to work on iOS. On Safari it works as expected, after vising the website, it works offline. However, when trying to use the same feature in Chrome, I had intermittent results. Specifically, the service worker would only work every other page refresh, with the original refresh after going offline being one of the ones not working.
我知道iOS上的Chrome基于Safari版本构建,因此我对此行为感到困惑.
I know that Chrome on iOS is built on a version of Safari, therefore I am confused about this behavior.
这是由于Chrome iOS对Service Workers的不完全支持吗?由于它是iOS上的Chrome,因此我也不确定是否有任何简便的方法可以对其进行调试,因此,希望能找到其他有助于解决该问题的技巧.谢谢!
Is this due to incomplete support from Chrome iOS for Service Workers? Because it is Chrome on iOS, I'm not sure of any easy way to debug it either, so any other tips to help track down the problem would be appreciated. Thank you!
推荐答案
Chrome(iOS版)目前不支持服务人员(截至2020年4月),如果您对此感兴趣,则添加到主屏幕"选项也不可用.您遇到的任何脱机页面加载都应来自常规浏览器缓存.
Chrome for iOS do not support service workers currently(as of Apr-2020) and also the "Add to home screen" option is not available, if you are interested in that. Any offline page loading that you are experiencing should be from regular browser cache.
值得注意的是,Chrome使用WKWebView作为iOS中的浏览器引擎,根据上述声明(您可以在上面提供的链接中找到),该引擎尚不支持Service Worker.因此,在iOS中使用Service worker的唯一方法是使用Safari浏览器或在本机应用程序中使用以上支持的网络视图之一.
Notably, Chrome uses WKWebView as its browser engine in iOS, which don't have service worker support yet as per the above statement(which you can find in the link provided above). So the only way you can use Service worker in iOS is to use Safari browser or use one of the above supported web-views inside a native app.
此处是有关iOS的所有PWA功能仍然存在的文章丢失的.请记住,这是一个快速增长的领域.始终检查现在是否适用,尤其是在文档/文章越来越老的情况下.
Here is an article on what all PWA features iOS is still missing. Remember, this is a fast growing area. Always check if what is applicable now, especially if the documentation/article is getting older.
这是一个适配器,可帮助在Chrome开发工具中调试已加载页面iOS-Webkit/Safari.希望有一天它能像Android Chrome调试一样容易!
Here is an adapter to help debug in Chrome dev tools for pages loaded iOS - webkit/safari. Hope it becomes as easy as Android Chrome debugging one day!
这篇关于Chrome Service Worker iOS支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!