简体   繁体   English

如何验证浏览器是否支持后台同步?

[英]How to verify if background sync is supported by the browser?

I am developing an application that uses service workers to cache HTTP requests from a specific endpoint.我正在开发一个应用程序,它使用服务工作者来缓存来自特定端点的 HTTP 请求。 These requests should be sent to the server using background sync.这些请求应该使用后台同步发送到服务器。 I know some browsers are not supported , but I would like to warn my users that this feature will not be available.我知道某些浏览器不受支持,但我想警告我的用户此功能将不可用。 To do this, I need some way of identifying whether or not the browser has background sync support.为此,我需要某种方式来确定浏览器是否具有后台同步支持。

if ('serviceWorker' in navigator && 'SyncManager' in window) {
   // service worker stuffs here
} else {
  console.error('Background sync not supported');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM