diff --git a/client/index.js b/client/index.js index 6b71693..2155db2 100644 --- a/client/index.js +++ b/client/index.js @@ -291,7 +291,7 @@ export class Client { this.onUnload = this.onUnload.bind(this) if (typeof window !== 'undefined' && window.addEventListener) { - window.addEventListener('unload', this.onUnload) + window.addEventListener('pagehide', this.onUnload) } this.processing = {} @@ -347,7 +347,7 @@ export class Client { this.node.destroy() clearInterval(this.pinging) if (typeof window !== 'undefined' && window.removeEventListener) { - window.removeEventListener('unload', this.onUnload) + window.removeEventListener('pagehide', this.onUnload) } } diff --git a/client/index.test.ts b/client/index.test.ts index c6f2f66..70d946b 100644 --- a/client/index.test.ts +++ b/client/index.test.ts @@ -383,7 +383,7 @@ it('cleans own actions on unload', async () => { { type: 'A' }, { reasons: ['tab' + client.tabId], tab: client.tabId } ) - window.dispatchEvent(new Event('unload')) + window.dispatchEvent(new Event('pagehide')) await delay(10) expect(client.log.actions()).toHaveLength(0) expect(localStorage.getItem('test:tab:' + client.tabId)).toBeNull() diff --git a/cross-tab-client/index.js b/cross-tab-client/index.js index b6b97bd..c596911 100644 --- a/cross-tab-client/index.js +++ b/cross-tab-client/index.js @@ -70,7 +70,7 @@ export class CrossTabClient extends Client { if (typeof window !== 'undefined' && window.addEventListener) { window.addEventListener('storage', e => this.onStorage(e)) - window.addEventListener('unload', e => this.onUnload(e)) + window.addEventListener('pagehide', e => this.onUnload(e)) } if (this.isLocalStorage) {