Files
SmyWorkCollect/SproutWorkCollect-Frontend/src/serviceWorkerRegistration.js

17 lines
525 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 在浏览器加载完成后注册自定义 Service Worker使应用成为 PWA。
// 生产环境和开发环境都可以注册,方便本地调试。
export function registerServiceWorker() {
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/service-worker.js')
.catch((error) => {
// eslint-disable-next-line no-console
console.error('[PWA] Service Worker 注册失败:', error);
});
});
}
}