feat: Service Worker 注册失败修复方案

1. 使用了 window.location.origin,但 Service Worker 环境中没有 window 对象
2. 注册逻辑缺少详细的错误处理和状态检查
This commit is contained in:
zdl
2025-11-11 10:57:12 +08:00
parent 643c3db03e
commit a15585c464
2 changed files with 46 additions and 6 deletions

View File

@@ -35,7 +35,7 @@ self.addEventListener('notificationclick', (event) => {
.then((windowClients) => {
// 查找是否已有打开的窗口
for (let client of windowClients) {
if (client.url.includes(window.location.origin) && 'focus' in client) {
if (client.url.includes(self.location.origin) && 'focus' in client) {
// 聚焦现有窗口并导航到目标页面
return client.focus().then(client => {
return client.navigate(urlToOpen);