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
[JS]update beforeunload to visibilitychange #19041
Conversation
update beforeunload to visibilitychange
update condition
take timer outside of check
build js |
update functions
update visibility State
add extra event
update tests, reset timer
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
build js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the right approach to me @peterhashair, but there is one failing test because the unload handler takes longer now:
Test failed in module request: 'Internal timers and setLinkTrackingTimer()'
Error: beforeUnloadHandler(): 522 was greater than 520
Also can any test be added eg beforeUnloadHandler({ type: 'visibilitychange' })
?
@justinvelluppillai will fix that one, you are 100% correct, test changed to |
I don't see the changes yet so will remove the |
update tests
update tests
update test to 530
# Conflicts: # tests/javascript/index.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the most recent merge of 4.x into this branch has overwritten the commit that updated the test time from 520 to 530.
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
@peterhashair I'm seeing My test was to add a |
@bx80 yes, I found the same problem, mention on the issue itself as well, |
@peterhashair I suppose existing plugin code would need to be aware that For example, it looks like HSR will stop sending data the first time that the plugin unload event is called, so in a scenario where the user loaded the page, quickly switched to another tab to check mail and then switched back, then I suspect none of the subsequent user interactions would be recorded. |
@bx80 makes sense, let me see if I can filter out the tab switch event. |
disable unload if tab is switched
@bx80 I am trying to do some research seems like that even can't escape tab change. Maybe that event shouldn't be added, any thought? |
@peterhashair I took a look too and it doesn't look like the visibility API offers any way to differentiate between a tab switch and leaving the page, so we probably don't want to have this event trigger the plugin unload event and potentially break existing plugins. |
@bx80 agree, but I notice, the visibiltyChange actually useful when is mobile.
|
update events
update jsLint error
@bx80 just revert some changes, am I on the right track? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, both events are being handled and the plugin load
event is only being called once on leaving the page. The first tab switch is still triggering the unload event, but as discussed this should be ok 👍
Description:
Fixes: #18810
update
beforeunload
tovisibilitychange
Please include a description of this change and which issue it fixes. If no issue exists yet please include context and what problem it solves.
Review