onMessage() not fired when app is in background (Web javascript).
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- firebase, javascript
调研方向
首先,将 Firebase Web Messaging 关于 onMessage()、onBackgroundMessage() 和通知点击的文档与提供的 index 代码和 sw.js 片段进行比较。使用 Firebase SDK 8.9.1 重现后台窗口流程,然后验证文档所述的 callback 行为是否符合报告中的预期,并确定支持哪种澄清或 repository 更改。
由索引模型根据 Issue 内容生成。
描述
I building a simple demo chat app with fcm integrated for new message notification. As far as I know, in fcm doc regarding onMessage(), it said this method get called when:
(1) a message is received while the app has focus
(2) - the user clicks on an app notification created by a service worker messaging.onBackgroundMessage handler.
But I'm not sure why onMessage() callback is not fired when my app is in background.
Step 1: Describe your environment
- Operating system: OSX Big Sur
- Browser: All
- Firebase SDK version: 8.9.1
Step 2: Describe the problem:
onMessage() callback is not fired when my app is in background.
Steps to reproduce:
- hide current browser window to make it in background state.
- send test message.
Observed Results:
onBackgroundMessage() from sw.js get called fine, but when I clicked on the notification to land on my app window, onMessage() did not get triggered (it's only triggered when the current browser window is in foreground state). It did not show any error or warning.
Expected Results:
onMessage() should be fired after I clicked the notification to have my app focused.
Relevant Code:
this is my index file
const messaging = firebase.messaging();
function sendTokenToServer(fcm_token) {
let player_sn = '{{Auth::id()}}';
axios.post('api/save-token', {
fcm_token,
player_sn
})
.then(function(response) {
// console.log(response);
})
.catch(function(error) {
console.log(error);
});
}
messaging.getToken({
vapidKey: '{{config("fcm.VAPID")}}'
}).then((currentToken) => {
// console.log(currentToken)
if (currentToken) {
sendTokenToServer(currentToken)
} else {
// Show permission request UI
console.log('No registration token available. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
// ...
});
messaging.onMessage((payload) => {
console.log('onMessage');
console.log(payload)
});
this is my sw.js
importScripts('https://cdnjs.cloudflare.com/ajax/libs/firebase/8.10.1/firebase.js');
importScripts('https://cdnjs.cloudflare.com/ajax/libs/firebase/8.10.1/firebase-messaging.min.js');
const firebaseConfig = {
apiKey: "AIzaSyBE90OnfKk6MELQ2-Z_DVLYp4maXVzvQO8",
authDomain: "ninja-firestore-tut-nov11.firebaseapp.com",
databaseURL: "https://ninja-firestore-tut-nov11-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "ninja-firestore-tut-nov11",
storageBucket: "ninja-firestore-tut-nov11.appspot.com",
messagingSenderId: "28680409583",
appId: "1:28680409583:web:66bef6c94232b88816e61a"
};
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
console.log('onBackgroundMessage ', payload);
// Customize notification here
const {title, body} = payload.notification;
const notificationTitle = title;
const notificationOptions = {
body: body,
icon: '/firebase-logo.png'
};
// self.registration.showNotification(notificationTitle,
// notificationOptions);
});
Note: I need to comment self.registration.showNotification(notificationTitle, notificationOptions); to avoid the notification got duplicate.
Any help on this would be much appreciated...
Thank you.
- 主要语言
- TypeScript
- 星标
- 5.4k
- 派生
- 3.7k
- 平均合并
- 4 天 23 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/quickstart-js 的其他 Issue
-
Payment未关闭
难度 5/5 一周以上 新手友好度 10/100
firebase/quickstart-js#945 ·
-
难度 4/5 3-5 天 新手友好度 35/100
firebase/quickstart-js#937 · 1 条评论 ·
-
Get the region of my firebase function from frontend file可能重新可做 @anjalisharma0909 于 238 天前认领,目前没有进行中的 PR。 未关闭
难度 5/5 一周以上 新手友好度 25/100
firebase/quickstart-js#907 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 32/100
firebase/quickstart-js#837 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
firebase/quickstart-js#825 ·
查看 firebase/quickstart-js 的全部 Issue
相似的 Issue
-
bug require-triage
难度 2/5 1-3 小时 新手友好度 72/100
expressjs/expressjs.com#2549 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
umami-software/umami#4686 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug]: Device screenshot fails with 500 on iPhone Duo (Xcode 27.2): serve-sim calls simctl without --display可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 66/100
pingdotgg/t3code#24900 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
inu-appcenter/UNIDorm-web#411 ·
维护者通常 1 天内回复
-
🐛 bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复