diff options
author | Peter Zhang <peter@innocraft.com> | 2022-05-03 02:07:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 02:07:42 +0300 |
commit | b9043debf14b422f4b2045a55f2f37b65fa9bb31 (patch) | |
tree | ca2c5c76f1ffc60a3de6b733f93902c4bc827de3 /js/piwik.js | |
parent | a0a47dc27b0b67e8f69498fb1bb5592da5d52bf9 (diff) |
[JS]update beforeunload to visibilitychange (#19041)
* Update piwik.js
update beforeunload to visibilitychange
* Update piwik.js
update condition
* rebuilt piwik.js
* Update piwik.js
take timer outside of check
* rebuilt piwik.js
* Update piwik.js
update functions
* rebuilt piwik.js
* update visibility State
update visibility State
* rebuilt piwik.js
* add extra event
add extra event
* rebuilt piwik.js
* update tests, reset timer
update tests, reset timer
* Update js/piwik.js
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
* update tests
update tests
* add visibilitychange to test
update tests
* update test to 530
update test to 530
* Update tests/javascript/index.php
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
* disable unload if tab is switched
disable unload if tab is switched
* update events
update events
* update jsLint error
update jsLint error
Co-authored-by: peterhashair <peterhashair@users.noreply.github.com>
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
Diffstat (limited to 'js/piwik.js')
-rw-r--r-- | js/piwik.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/js/piwik.js b/js/piwik.js index 7b1ba0e56b..b10f2862ad 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -497,13 +497,12 @@ if (typeof window.Matomo !== 'object') { * Chrome V8 extension that terminates JS that exhibits * "slow unload", i.e., calling getTime() > 1000 times */ - function beforeUnloadHandler() { + function beforeUnloadHandler(event) { var now; isPageUnloading = true; executePluginMethod('unload'); - - now = new Date(); + now = new Date(); var aliasTime = now.getTimeAlias(); if ((expireDateTime - aliasTime) > 3000) { expireDateTime = aliasTime + 3000; @@ -7167,6 +7166,16 @@ if (typeof window.Matomo !== 'object') { // initialize the Matomo singleton addEventListener(windowAlias, 'beforeunload', beforeUnloadHandler, false); + addEventListener(windowAlias, 'visibilitychange', function () { + // if unloaded, return + if (isPageUnloading) { + return; + } + // if not visible + if (documentAlias.visibilityState === 'hidden') { + executePluginMethod('unload'); + } + }, false); addEventListener(windowAlias, 'online', function () { if (isDefined(navigatorAlias.serviceWorker)) { navigatorAlias.serviceWorker.ready.then(function(swRegistration) { |