@@ -942,6 +942,14 @@ export class IndexedDbPersistence implements Persistence {
942
942
}
943
943
}
944
944
945
+ /**
946
+ * Returns the page termination event to listen to. 'pagehide' is recommended
947
+ * if available, it falls back to the less reliable 'unload'.
948
+ */
949
+ private terminationEvent ( ) : string {
950
+ return 'onpagehide' in this . window ! ? 'pagehide' : 'unload' ;
951
+ }
952
+
945
953
/**
946
954
* Attaches a window.unload handler that will synchronously write our
947
955
* clientId to a "zombie client id" location in LocalStorage. This can be used
@@ -966,7 +974,10 @@ export class IndexedDbPersistence implements Persistence {
966
974
return this . shutdown ( ) ;
967
975
} ) ;
968
976
} ;
969
- this . window . addEventListener ( 'unload' , this . windowUnloadHandler ) ;
977
+ this . window . addEventListener (
978
+ this . terminationEvent ( ) ,
979
+ this . windowUnloadHandler
980
+ ) ;
970
981
}
971
982
}
972
983
@@ -976,7 +987,10 @@ export class IndexedDbPersistence implements Persistence {
976
987
typeof this . window ?. removeEventListener === 'function' ,
977
988
"Expected 'window.removeEventListener' to be a function"
978
989
) ;
979
- this . window ! . removeEventListener ( 'unload' , this . windowUnloadHandler ) ;
990
+ this . window ! . removeEventListener (
991
+ this . terminationEvent ( ) ,
992
+ this . windowUnloadHandler
993
+ ) ;
980
994
this . windowUnloadHandler = null ;
981
995
}
982
996
}
0 commit comments