1 import { load, save } from '../helpers/secureSessionStorage';
2 import createStore from '../helpers/store';
4 const createSecureSessionStorage = () => {
5 const store = createStore(load());
7 if ('onpagehide' in window) {
8 const handlePageShow = () => {
9 // This does not need to do anything. The main purpose is just to reset window.name and sessionStorage to fix the Safari 13.1 described below
13 const handlePageHide = () => {
14 // Cannot use !event.persisted because Safari 13.1 does not send that when you are navigating on the same domain
15 save(store.getState());
18 window.addEventListener('pageshow', handlePageShow, true);
19 window.addEventListener('pagehide', handlePageHide, true);
21 const handleUnload = () => {
22 save(store.getState());
24 // This gets narrowed to never because of the onpagehide
26 window.addEventListener('unload', handleUnload, true);
32 export type SecureSessionStorage = ReturnType<typeof createSecureSessionStorage>;
34 export default createSecureSessionStorage;