openfree commited on
Commit
c9d6ddb
·
verified ·
1 Parent(s): cd05f5e

fix(sw): v4 - .catch() 체인 제거, actions 없이 안정화

Browse files
Files changed (1) hide show
  1. sw.js +10 -20
sw.js CHANGED
@@ -1,9 +1,10 @@
1
  /* ======================================================
2
- VIDRAFT Service Worker — Web Push Notifications v3
3
- 변경: Windows Chrome 호환성 강화 (actions 제거, image fallback, URL 갱신)
 
4
  ====================================================== */
5
 
6
- const CACHE_VERSION = 'vidraft-sw-v3'; // 버전 변경 → 브라우저 자동 업데이트
7
 
8
  self.addEventListener('install', () => self.skipWaiting());
9
  self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
@@ -24,36 +25,25 @@ self.addEventListener('push', (e) => {
24
  catch { d.body = e.data.text(); }
25
  }
26
 
27
- console.log('[SW v3] push received, title:', d.title, '/ image:', d.image);
28
 
29
- // Windows Chrome / Edge 호환 옵션
30
- // actions 제거: Windows에서 silent fail 유발 사례 있음
31
- // requireInteraction false: Windows 알림센터에 쌓이지 않게
32
  const options = {
33
  body: d.body,
34
  icon: d.icon,
35
  badge: d.badge,
36
- tag: 'vidraft-push', // 동일 tag → 이전 알림 교체
37
- renotify: true, // tag 같아도 다시 울림
38
  requireInteraction: false,
39
- silent: false,
40
  data: { url: d.url },
 
41
  };
42
 
43
- // Hero 이미지 — 비어 있지 않을 때만 포함
44
  if (d.image && d.image.trim()) {
45
  options.image = d.image.trim();
46
  }
47
 
48
- e.waitUntil(
49
- self.registration.showNotification(d.title, options)
50
- .catch(err => {
51
- // image 포함 시 실패 → image 없이 재시도 (Windows 일부 버전 fallback)
52
- console.warn('[SW v3] showNotification failed, retrying without image:', err);
53
- delete options.image;
54
- return self.registration.showNotification(d.title, options);
55
- })
56
- );
57
  });
58
 
59
  // ── 알림 클릭 → 탭 열기 ─────────────────────────────
 
1
  /* ======================================================
2
+ VIDRAFT Service Worker — Web Push Notifications v4
3
+ v3에서 .catch() 체인 제거 (모바일 silent-fail 원인)
4
+ Windows 호환: actions 제거 유지
5
  ====================================================== */
6
 
7
+ const CACHE_VERSION = 'vidraft-sw-v4';
8
 
9
  self.addEventListener('install', () => self.skipWaiting());
10
  self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
 
25
  catch { d.body = e.data.text(); }
26
  }
27
 
28
+ console.log('[SW v4] push received, title:', d.title);
29
 
 
 
 
30
  const options = {
31
  body: d.body,
32
  icon: d.icon,
33
  badge: d.badge,
34
+ tag: 'vidraft-push',
35
+ renotify: true,
36
  requireInteraction: false,
 
37
  data: { url: d.url },
38
+ // actions 제거 — Windows Chrome silent-fail 유발
39
  };
40
 
 
41
  if (d.image && d.image.trim()) {
42
  options.image = d.image.trim();
43
  }
44
 
45
+ // .catch() 체인 없이 직접 waitUntil — 가장 안정적
46
+ e.waitUntil(self.registration.showNotification(d.title, options));
 
 
 
 
 
 
 
47
  });
48
 
49
  // ── 알림 클릭 → 탭 열기 ─────────────────────────────