Explore Related Tools
Hand-picked utilities and calculators related to this tool.
Firebase apps naturally handle network interruptions, but you can explicitly enable disk persistence to allow data to survive app restarts and reboots, even without a connection.
On web, persistence is not enabled by default. You must call enableIndexedDbPersistence.
import { getFirestore, enableIndexedDbPersistence } from "firebase/firestore";
const db = getFirestore();
enableIndexedDbPersistence(db).catch((err) => {
if (err.code == 'failed-precondition') {
// Multiple tabs open, persistence can only be enabled in one tab at a time.
console.log("Persistence failed (multiple tabs)");
} else if (err.code == 'unimplemented') {
// The current browser does not support persistence.
console.log("Persistence is not supported");
}
});doc.metadata.fromCache to see if the data is live or local.For the Realtime Database, simple persistence is enabled like this:
firebase.database().goOffline(); // Manually manage stateHand-picked utilities and calculators related to this tool.
