We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 99a4ca7 commit 0577cbaCopy full SHA for 0577cba
lib/index.browser.ts
@@ -33,13 +33,18 @@ export const createInstance = function(config: Config): Client {
33
});
34
35
if (client) {
36
- const unloadEvent = 'onpagehide' in window ? 'pagehide' : 'unload';
37
- window.addEventListener(
38
- unloadEvent,
39
- () => {
+ if ('onvisibilitychange' in document) {
+ document.addEventListener('visibilitychange', () => {
+ if (document.hidden) {
+ client.flushImmediately();
40
+ }
41
+ });
42
+ } else {
43
+ const unloadEvent = 'onpagehide' in window ? 'pagehide' : 'unload';
44
+ window.addEventListener(unloadEvent, () => {
45
client.flushImmediately();
- },
- );
46
47
48
}
49
50
return client;
0 commit comments