This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use pagehide instead of visibilitychange
- Loading branch information
Showing
2 changed files
with
16 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,13 +208,23 @@ export async function getSessionLock(onNewInstance: () => Promise<void>): Promis | |
// Now add a listener for other claimants to the lock. | ||
window.addEventListener("storage", onStorageEvent); | ||
|
||
// also add a listener to clear our claims when our tab closes (provided we haven't released it already) | ||
window.document.addEventListener("visibilitychange", (event) => { | ||
if (window.document.visibilityState === "hidden" && lockServicer !== null) { | ||
prefixedLogger.info("Unloading: clearing our claims"); | ||
// also add a listener to clear our claims when our tab closes or navigates away | ||
window.addEventListener("pagehide", (event) => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
richvdh
Author
Member
|
||
// only remove the ping if we still think we're the owner. Otherwise we could be removing someone else's claim! | ||
if (lockServicer !== null) { | ||
prefixedLogger.info("page hide: clearing our claim"); | ||
window.localStorage.removeItem(STORAGE_ITEM_PING); | ||
window.localStorage.removeItem(STORAGE_ITEM_OWNER); | ||
} | ||
|
||
// It's worth noting that, according to the spec, the page might come back to life again after a pagehide. | ||
// | ||
// In practice that's unlikely because Element is unlikely to qualify for the bfcache, but if it does, | ||
// this is probably the best we can do: we certainly don't want to stop the user loading any new tabs because | ||
// Element happens to be in a bfcache somewhere. | ||
// | ||
// So, we just hope that we aren't in the middle of any crypto operations, and rely on `onStorageEvent` kicking | ||
// in soon enough after we resume to tell us if another tab woke up while we were asleep. | ||
}); | ||
|
||
return true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
That doesn't sound right