Repository navigation
fix(web): 웹 푸시가 백그라운드에서 표시되지 않던 것 + 알림 탭을 열린 탭에서 따라가기 - #327
Merged
Merged
Conversation
1) 서비스워커가 firebase.messaging() 을 부르지 않았다.
compat SDK 는 이 인스턴스를 만들 때 push·notificationclick 처리기를 등록한다
(지연 생성). 부르지 않으니 탭이 백그라운드일 때 온 웹 푸시를 SDK 가 표시하지
못했다 — 07-28 도입 때부터. 이제 처리기 등록 뒤에 부른다.
2) 알림 탭이 갈 곳을 몰랐다.
서버가 링크를 싣지 않았고(짝 PR pmdb), SW 의 navigate() 는 이 SW 가 앱 페이지를
제어하지 않아(FCM 전용 범위 등록) 거절된다. 이제
- 링크(webpush.fcm_options.link → FCM_MSG.fcmOptions.link)를 읽고,
- 열린 탭이 있으면 그 탭에 postMessage 로 넘기고 포커스한다. 페이지의
web/notification_link.js 가 같은 탭에서 그 주소로 옮긴다 — 웹 세션은 탭별
sessionStorage 라 새 창을 열면 로그아웃 상태로 열리기 때문이다.
- 열린 탭이 없으면 링크(없으면 '/')를 새 창으로 연다.
- 링크가 없는 알림(채팅·공지 등)은 열린 탭을 앞으로 가져오기만 한다.
우리 처리기를 SDK 보다 먼저 등록하고 stopImmediatePropagation 으로 SDK 의
클릭 처리(링크 탭이 없을 때마다 새 창)를 막는다.
탭이 보이는 동안 온 푸시는 SDK 가 시스템 알림 대신 페이지로 넘기는데 앱은 쓰지
않는다 — 그 동안의 표시는 지금처럼 실시간 구독의 인앱 배너다.
CSP 가 인라인 스크립트를 막아(script-src 'self') 페이지 쪽은 별도 파일이다.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
전체 라인 커버리지: 25.0% (5286/21105) 이 PR 의 변경 파일:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
무엇이 문제였나
web/firebase-messaging-sw.js가firebase.messaging()을 부르지 않았다. compat SDK(11.9.1)는 이 인스턴스를 만들 때push·pushsubscriptionchange·notificationclick처리기를 등록한다(지연 생성 — SDK 원본에서 확인). 부르지 않으니 탭이 백그라운드일 때 온 푸시를 SDK 가 표시하지 못했다. 07-28 웹 푸시 도입 때부터다.navigate()는 이 SW 가 앱 페이지를 제어하지 않아(FCM 전용 범위/firebase-cloud-messaging-push-scope등록) 거절된다.바꾼 것
web/firebase-messaging-sw.jsFCM_MSG.fcmOptions.link(= 서버의webpush.fcm_options.link) →click_action→data.linkpostMessage({pawmateOpenLink})로 넘기고 포커스한다. 같은 탭에서 옮겨야 로그인이 유지된다(웹 세션은 탭별sessionStorage)/)를 새 창으로 연다stopImmediatePropagation으로 SDK 의 클릭 처리(링크 주소의 탭이 없을 때마다 새 창)를 막은 뒤firebase.messaging()을 부른다web/notification_link.js(새 파일) +web/index.html— SW 가 보낸 링크를 받아 같은 오리진일 때만 그 탭에서location.assign. 지금 주소와 같으면 무시. CSP 가 인라인 스크립트를 막아(script-src 'self') 별도 파일이다lib/services/push_service.dart— 웹 경로 주석을 실제 동작에 맞춤(코드 변경 없음)탭이 보이는 동안 온 푸시는 SDK 가 시스템 알림 대신 페이지로 넘기는데 앱은 그 메시지를 쓰지 않는다. 그 동안의 표시는 지금처럼 실시간 구독의 인앱 배너다(이중 표시 없음).
시험
node --check두 파일 통과messaging()), 링크+열린 탭 → 같은 탭 이동 요청, 링크+탭 없음 → 새 창, 링크 없음+탭 → 포커스만, 링크 없음+탭 없음 →/, 다른 오리진 탭 무시·포커스 탭 우선, 옛 형식(data.link·click_action) 호환, 페이지는 같은 오리진·다른 주소일 때만 이동, serviceWorker 미지원 브라우저에서 조용히 빠짐배포 뒤 확인(웹, 데스크톱 크롬)
🤖 Generated with Claude Code