title: Fetch data from firebase/firestore with service worker
body: <p>I built a PWA that fetches data from firestore. I want to run some checks on that data every couple of hours which is why I want to use a service worker for that.</p>
  <p>This is a snippet from my working code:</p>
  <pre><code>billsCollection.orderBy('dayOfMonth', 'asc').onSnapshot(querySnapshot =&gt; {
    let billsArray = [];
    querySnapshot.forEach(doc =&gt; {
      let bill = doc.data();
      bill.id = doc.id;
      billsArray.push(bill);
    });
    store.commit('setBills', billsArray);
  });
  </code></pre>
  <p>If I try to run .onSnapshot in my service worker I get the message that xmlhttprequest is not known or similar.</p>
  <p>It seems like 'firebase/app' and 'firebase/firestore' use the old xmlhttprequest to communicate with firebase/firestore. Service Workers only support the newer fetch api. Has anybody successfully fetched data  from firebase/firestore before using the new fetch api?</p>
  <p>I would like to periodically fetch data from firebase using a service worker.</p>
  <p>If that does not work, is it possible to check your data with a Cloud Firestore function? I am not sure since it would need a time event trigger or similar.</p>
  <p>Thanks everybody for your ideas,
  Johannes</p>
  <p>Edit:</p>
  <p>As Scarygami pointed out I can solve that problem by using a cron service that triggers a firestore function. This works. Nevertheless, I am still looking for a way to fetch data from firestore with a service worker directly. Then I would not need a 3rd party cron service or cloud functions and the specific token of the device I want to send a message to. It would simply fetch data, check data, show notification if needed.</p>