-
Notifications
You must be signed in to change notification settings - Fork 12
[CI 3890] switch beforeunload with visibilitychange #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2cdf553
fc0c47d
14bed18
cc40ecf
80d2b3e
f93ed85
ed78445
1db67e3
98973ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,18 @@ class RequestQueue { | |
| ? true | ||
| : false; // Defaults to 'false' | ||
|
|
||
| // Mark if page environment is unloading | ||
| helpers.addEventListener('beforeunload', () => { | ||
| this.pageUnloading = true; | ||
| helpers.addEventListener('visibilitychange', () => { | ||
| // Mark if page environment is unloading | ||
| if (document.visibilityState === 'hidden') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add in some additional logic here to call
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I somehow completely missed the notification for this one. I don't see any reason not to. Good call |
||
| this.pageUnloading = true; | ||
| } else if (document.visibilityState === 'visible' && this.pageUnloading === true) { | ||
| // Send events once page is visible again | ||
| this.pageUnloading = false; | ||
|
|
||
| if (this.sendTrackingEvents) { | ||
| this.send(); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| if (this.sendTrackingEvents) { | ||
|
|
@@ -182,7 +191,7 @@ class RequestQueue { | |
| if (this.options && this.options.trackingSendDelay === 0) { | ||
| this.sendEvents(); | ||
| } else { | ||
| // Defer sending of events to give beforeunload time to register (avoids race condition) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened/happens when beforeunload/visibilitychange registers?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. beforeunload/visibilitychange changes the |
||
| // Defer sending of events to give visibilitychange time to register (avoids race condition) | ||
| setTimeout(this.sendEvents.bind(this), (this.options && this.options.trackingSendDelay) || 250); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.