This is an automated email from the ASF dual-hosted git repository.

poorejc pushed a commit to branch flagon-userale-50
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git


The following commit(s) were added to refs/heads/flagon-userale-50 by this push:
     new 9f1a422  [flagon-userale-50] experimental fix flips out onunload and 
beforeunload event handlers for visibility state change === hidden
9f1a422 is described below

commit 9f1a422a3c58da8b7c9b7e1b9241673b80ae4f9c
Author: poorejc <[email protected]>
AuthorDate: Wed Mar 17 14:03:32 2021 -0400

    [flagon-userale-50] experimental fix flips out onunload and beforeunload 
event handlers for visibility state change === hidden
---
 build/UserALEWebExtension/background.js | 19 ++++++++++++-------
 build/UserALEWebExtension/content.js    | 19 ++++++++++++-------
 build/userale-2.1.1.js                  | 19 ++++++++++++-------
 build/userale-2.1.1.min.js              |  2 +-
 src/sendLogs.js                         | 17 +++++++++++------
 5 files changed, 48 insertions(+), 28 deletions(-)

diff --git a/build/UserALEWebExtension/background.js 
b/build/UserALEWebExtension/background.js
index 24fc4e3..e8952f4 100644
--- a/build/UserALEWebExtension/background.js
+++ b/build/UserALEWebExtension/background.js
@@ -390,21 +390,26 @@ function sendOnInterval(logs, config) {
  * @param  {Object} config Configuration object to be read from.
  */
 function sendOnClose(logs, config) {
-  if (!config.on) {
+/** if (!config.on) {
     return;
-  }
-
-  if (navigator.sendBeacon) {
-    window.addEventListener('unload', function() {
+ } */
+document.addEventListener('visibilitychange', function () {
+    if (document.visibilityState === 'hidden' && logs.length > 0) {
       navigator.sendBeacon(config.url, JSON.stringify(logs));
-    });
+    }
+  });
+/**
+    if (navigator.sendBeacon) {
+    window.addEventListener('unload', function() {
+      ;
   } else {
     window.addEventListener('beforeunload', function() {
       if (logs.length > 0) {
         sendLogs(logs, config, 1);
       }
-    });
+    })
   }
+*/
 }
 
 /**
diff --git a/build/UserALEWebExtension/content.js 
b/build/UserALEWebExtension/content.js
index 0c6e317..cfa781e 100644
--- a/build/UserALEWebExtension/content.js
+++ b/build/UserALEWebExtension/content.js
@@ -816,21 +816,26 @@ function sendOnRefresh(logs, config) {
  * @param  {Object} config Configuration object to be read from.
  */
 function sendOnClose(logs, config) {
-  if (!config.on) {
+/** if (!config.on) {
     return;
-  }
-
-  if (navigator.sendBeacon) {
-    window.addEventListener('unload', function() {
+ } */
+document.addEventListener('visibilitychange', function () {
+    if (document.visibilityState === 'hidden' && logs.length > 0) {
       navigator.sendBeacon(config.url, JSON.stringify(logs));
-    });
+    }
+  });
+/**
+    if (navigator.sendBeacon) {
+    window.addEventListener('unload', function() {
+      ;
   } else {
     window.addEventListener('beforeunload', function() {
       if (logs.length > 0) {
         sendLogs(logs, config, 1);
       }
-    });
+    })
   }
+*/
 }
 
 /**
diff --git a/build/userale-2.1.1.js b/build/userale-2.1.1.js
index ea5de7d..6f04f7d 100644
--- a/build/userale-2.1.1.js
+++ b/build/userale-2.1.1.js
@@ -798,21 +798,26 @@
    * @param  {Object} config Configuration object to be read from.
    */
   function sendOnClose(logs, config) {
-    if (!config.on) {
+  /** if (!config.on) {
       return;
-    }
-
-    if (navigator.sendBeacon) {
-      window.addEventListener('unload', function() {
+   } */
+  document.addEventListener('visibilitychange', function () {
+      if (document.visibilityState === 'hidden' && logs.length > 0) {
         navigator.sendBeacon(config.url, JSON.stringify(logs));
-      });
+      }
+    });
+  /**
+      if (navigator.sendBeacon) {
+      window.addEventListener('unload', function() {
+        ;
     } else {
       window.addEventListener('beforeunload', function() {
         if (logs.length > 0) {
           sendLogs(logs, config, 1);
         }
-      });
+      })
     }
+  */
   }
 
   /**
diff --git a/build/userale-2.1.1.min.js b/build/userale-2.1.1.min.js
index 9b6cd5b..9593f55 100644
--- a/build/userale-2.1.1.min.js
+++ b/build/userale-2.1.1.min.js
@@ -15,4 +15,4 @@
  * limitations under the License.
  * @preserved
  */
-!function(e,n){"object"==typeof exports&&"undefined"!=typeof 
module?n(exports):"function"==typeof 
define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof 
globalThis?globalThis:e||self).userale={})}(this,function(t){"use strict";var 
e="2.1.1",r=null;function n(t,o){Object.keys(o).forEach(function(e){var 
n;"userFromParams"!==e||(n=function(e){e=new 
RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)"),e=window.location.href.match(e);return 
e&&e[2]?decodeURIComponent(e[2].replace(/\+/g," ")):null} [...]
\ No newline at end of file
+!function(e,n){"object"==typeof exports&&"undefined"!=typeof 
module?n(exports):"function"==typeof 
define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof 
globalThis?globalThis:e||self).userale={})}(this,function(t){"use strict";var 
e="2.1.1",i=null;function n(t,o){Object.keys(o).forEach(function(e){var 
n;"userFromParams"!==e||(n=function(e){e=new 
RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)"),e=window.location.href.match(e);return 
e&&e[2]?decodeURIComponent(e[2].replace(/\+/g," ")):null} [...]
\ No newline at end of file
diff --git a/src/sendLogs.js b/src/sendLogs.js
index da43180..20beec7 100644
--- a/src/sendLogs.js
+++ b/src/sendLogs.js
@@ -75,14 +75,18 @@ export function sendOnRefresh(logs, config) {
  * @param  {Object} config Configuration object to be read from.
  */
 export function sendOnClose(logs, config) {
-  if (!config.on) {
+/** if (!config.on) {
     return;
-  }
-
-  if (navigator.sendBeacon) {
-    window.addEventListener('unload', function() {
+ } */
+document.addEventListener('visibilitychange', function () {
+    if (document.visibilityState === 'hidden' && logs.length > 0) {
       navigator.sendBeacon(config.url, JSON.stringify(logs));
-    });
+    }
+  });
+/**
+    if (navigator.sendBeacon) {
+    window.addEventListener('unload', function() {
+      ;
   } else {
     window.addEventListener('beforeunload', function() {
       if (logs.length > 0) {
@@ -90,6 +94,7 @@ export function sendOnClose(logs, config) {
       }
     })
   }
+*/
 }
 
 /**

Reply via email to