Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

asynchronous - Firestore update document on beforeunload

How can I update a document in Firestore on beforeunload?

    function sleep() {
      var start = new Date().getTime();
      while (new Date().getTime() < start + 3000);
    }

    window.addEventListener("beforeunload", function(event) {
      const ref = db.collection('users').doc(currentUser.uid);
      ref.update({
        profiles: true
      }).then(function() {
        console.log("Added!");
      });
      console.log("Blocking for 3 seconds...");
      sleep();
      console.log("Done!!");
    });

Seems like ref.update() is never called? Any idea why that's the case?

question from:https://stackoverflow.com/questions/65895509/firestore-update-document-on-beforeunload

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.5k users

...