Description:
I am using onSnapshot in my Chrome extension background script to listen for real-time updates to a Firestore database and cache the changes in local storage. I attch the listener after a user successfully logs in. It works well, but after some time of inactivity, the listener stops working. I suspect this is due to the background script going inactive. How can I keep the background script running and ensure that the onSnapshot listener stays active?
Code Example
background.js
onSnapshot(
doc(db, "customers", uid),
(doc) => {
const data = doc.data();
chrome.storage.local.set({'userData': data}, () => {
console.log('User Data Changed', data );
});
},
(error) => {
console.log(error);
}
);
Any help or suggestions would be greatly appreciated. Thank you!