FiRestore for the Web能否与服务工作人员集成以实现后台同步? [英] Can Firestore for the web integrate with service worker for background synchronization?
本文介绍了FiRestore for the Web能否与服务工作人员集成以实现后台同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
推荐答案
在提出问题时,这可能是不可能的,但同时使用Chrome扩展是可能的。
从版本9开始,Firebase Web SDK使用fetch
而不是XMLHttpRequest
。因此,它在服务人员内部工作。
以下是我在后台监控FiRestore数据库和更新Chrome扩展的徽章的工作示例:
background.js
:
var unsubscribe;
auth.onAuthStateChanged(function(user) {
if (user) {
const db = getFirestore(app);
let colReference = collection(db, "User", user.uid, "Reference");
unsubscribe = onSnapshot(colReference, function(querySnapshot) {
chrome.action.setBadgeText({text: querySnapshot.size.toString()});
});
} else {
unsubscribe();
}
});
有关如何为Chrome(清单v3)扩展设置Firebase的答案:https://stackoverflow.com/a/70815962/3243751
此答案是如何使用Firebase身份验证通过FiRestore数据库进行身份验证:https://stackoverflow.com/a/70987391/3243751
这篇关于FiRestore for the Web能否与服务工作人员集成以实现后台同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文