/* ====================================================== VIDRAFT Service Worker — Web Push Notifications v4 v3에서 .catch() 체인 제거 (모바일 silent-fail 원인) Windows 호환: actions 제거 유지 ====================================================== */ const CACHE_VERSION = 'vidraft-sw-v4'; self.addEventListener('install', () => self.skipWaiting()); self.addEventListener('activate', e => e.waitUntil(self.clients.claim())); // ── Push 수신 → 알림 표시 ──────────────────────────── self.addEventListener('push', (e) => { let d = { title: 'VIDRAFT', body: '새 소식이 있습니다.', icon: 'https://vidraft-ai.static.hf.space/favicon.png', badge: 'https://vidraft-ai.static.hf.space/favicon.png', image: '', url: 'https://vidraft.net' }; if (e.data) { try { d = { ...d, ...e.data.json() }; } catch { d.body = e.data.text(); } } console.log('[SW v4] push received, title:', d.title); const options = { body: d.body, icon: d.icon, badge: d.badge, tag: 'vidraft-push', renotify: true, requireInteraction: false, data: { url: d.url }, // actions 제거 — Windows Chrome silent-fail 유발 }; if (d.image && d.image.trim()) { options.image = d.image.trim(); } // .catch() 체인 없이 직접 waitUntil — 가장 안정적 e.waitUntil(self.registration.showNotification(d.title, options)); }); // ── 알림 클릭 → 탭 열기 ───────────────────────────── self.addEventListener('notificationclick', (e) => { e.notification.close(); const target = (e.notification.data && e.notification.data.url) ? e.notification.data.url : 'https://vidraft.net'; e.waitUntil( self.clients.matchAll({ type: 'window', includeUncontrolled: true }) .then(clients => { for (const c of clients) { if (c.url === target && 'focus' in c) return c.focus(); } if (self.clients.openWindow) return self.clients.openWindow(target); }) ); });