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 0ec3645 [flagon-userale-50] fixes issue of duplicate logs due to
sendOnRefresh in refresh events, and fixes issue with duplicate events with
browser tab switching--sendOnClose now flushes the 'logs' queue after sending
0ec3645 is described below
commit 0ec3645b828ff1429ec70beba8165102180d443b
Author: poorejc <[email protected]>
AuthorDate: Thu Mar 18 22:37:28 2021 -0400
[flagon-userale-50] fixes issue of duplicate logs due to sendOnRefresh in
refresh events, and fixes issue with duplicate events with browser tab
switching--sendOnClose now flushes the 'logs' queue after sending
---
build/UserALEWebExtension/background.js | 1 +
build/UserALEWebExtension/content.js | 248 +++++++++++++++-----------------
build/userale-2.1.1.js | 248 +++++++++++++++-----------------
build/userale-2.1.1.min.js | 2 +-
src/attachHandlers.js | 3 -
src/sendLogs.js | 19 +--
6 files changed, 233 insertions(+), 288 deletions(-)
diff --git a/build/UserALEWebExtension/background.js
b/build/UserALEWebExtension/background.js
index e8952f4..6350eaa 100644
--- a/build/UserALEWebExtension/background.js
+++ b/build/UserALEWebExtension/background.js
@@ -396,6 +396,7 @@ function sendOnClose(logs, config) {
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'hidden' && logs.length > 0) {
navigator.sendBeacon(config.url, JSON.stringify(logs));
+ logs.splice(0); // Clear array reference (no reassignment)
}
});
/**
diff --git a/build/UserALEWebExtension/content.js
b/build/UserALEWebExtension/content.js
index cfa781e..704252b 100644
--- a/build/UserALEWebExtension/content.js
+++ b/build/UserALEWebExtension/content.js
@@ -756,138 +756,6 @@ function detectBrowser() {
* limitations under the License.
*/
-var sendIntervalId = null;
-
-/**
- * Initializes the log queue processors.
- * @param {Array} logs Array of logs to append to.
- * @param {Object} config Configuration object to use when logging.
- */
-function initSender(logs, config) {
- if (sendIntervalId !== null) {
- clearInterval(sendIntervalId);
- }
-
- sendIntervalId = sendOnInterval(logs, config);
- sendOnClose(logs, config);
-}
-
-/**
- * Checks the provided log array on an interval, flushing the logs
- * if the queue has reached the threshold specified by the provided config.
- * @param {Array} logs Array of logs to read from.
- * @param {Object} config Configuration object to be read from.
- * @return {Number} The newly created interval id.
- */
-function sendOnInterval(logs, config) {
- return setInterval(function() {
- if (!config.on) {
- return;
- }
-
- if (logs.length >= config.logCountThreshold) {
- sendLogs(logs.slice(0), config, 0); // Send a copy
- logs.splice(0); // Clear array reference (no reassignment)
- }
- }, config.transmitInterval);
-}
-
-/**
- * Provides a simplified send function that can be called before events that
would
- * refresh page can resolve so that log queue ('logs) can be shipped
immediately. This
- * is different than sendOnClose because browser security practices prevent
you from
- * listening the process responsible for window navigation actions, in action
(e.g., refresh;
- * you can only detect, after the fact, the process responsible for the
current window state.
- * @param {Array} logs Array of logs to read from.
- * @param {Object} config Configuration object to be read from.
- */
-function sendOnRefresh(logs, config) {
- if (!config.on) {
- return;
- }
- if (logs.length > 0) {
- sendLogs(logs, config, 1);
- }
-}
-
-/**
- * Attempts to flush the remaining logs when the window is closed.
- * @param {Array} logs Array of logs to be flushed.
- * @param {Object} config Configuration object to be read from.
- */
-function sendOnClose(logs, config) {
-/** if (!config.on) {
- return;
- } */
-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);
- }
- })
- }
-*/
-}
-
-/**
- * Sends the provided array of logs to the specified url,
- * retrying the request up to the specified number of retries.
- * @param {Array} logs Array of logs to send.
- * @param {string} config configuration parameters (e.g., to extract URL
from & send the POST request to).
- * @param {Number} retries Maximum number of attempts to send the logs.
- */
-
-// @todo expose config object to sendLogs replate url with config.url
-function sendLogs(logs, config, retries) {
- var req = new XMLHttpRequest();
-
- // @todo setRequestHeader for Auth
- var data = JSON.stringify(logs);
-
- req.open('POST', config.url);
- if (config.authHeader) {
- req.setRequestHeader('Authorization', config.authHeader);
- }
-
- req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
-
- req.onreadystatechange = function() {
- if (req.readyState === 4 && req.status !== 200) {
- if (retries > 0) {
- sendLogs(logs, config, retries--);
- }
- }
- };
-
- req.send(data);
-}
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
// @todo var>let
var events;
var bufferBools;
@@ -985,7 +853,6 @@ function attachHandlers(config) {
Object.keys(refreshEvents).forEach(function(ev) {
document.addEventListener(ev, function(e) {
packageLog(e, events[ev]);
- sendOnRefresh(logs$1,config);
}, true);
});
@@ -1015,6 +882,121 @@ function attachHandlers(config) {
* limitations under the License.
*/
+var sendIntervalId = null;
+
+/**
+ * Initializes the log queue processors.
+ * @param {Array} logs Array of logs to append to.
+ * @param {Object} config Configuration object to use when logging.
+ */
+function initSender(logs, config) {
+ if (sendIntervalId !== null) {
+ clearInterval(sendIntervalId);
+ }
+
+ sendIntervalId = sendOnInterval(logs, config);
+ sendOnClose(logs, config);
+}
+
+/**
+ * Checks the provided log array on an interval, flushing the logs
+ * if the queue has reached the threshold specified by the provided config.
+ * @param {Array} logs Array of logs to read from.
+ * @param {Object} config Configuration object to be read from.
+ * @return {Number} The newly created interval id.
+ */
+function sendOnInterval(logs, config) {
+ return setInterval(function() {
+ if (!config.on) {
+ return;
+ }
+
+ if (logs.length >= config.logCountThreshold) {
+ sendLogs(logs.slice(0), config, 0); // Send a copy
+ logs.splice(0); // Clear array reference (no reassignment)
+ }
+ }, config.transmitInterval);
+}
+
+/**
+ * Attempts to flush the remaining logs when the window is closed.
+ * @param {Array} logs Array of logs to be flushed.
+ * @param {Object} config Configuration object to be read from.
+ */
+function sendOnClose(logs, config) {
+/** if (!config.on) {
+ return;
+ } */
+document.addEventListener('visibilitychange', function () {
+ if (document.visibilityState === 'hidden' && logs.length > 0) {
+ navigator.sendBeacon(config.url, JSON.stringify(logs));
+ logs.splice(0); // Clear array reference (no reassignment)
+ }
+ });
+/**
+ if (navigator.sendBeacon) {
+ window.addEventListener('unload', function() {
+ ;
+ } else {
+ window.addEventListener('beforeunload', function() {
+ if (logs.length > 0) {
+ sendLogs(logs, config, 1);
+ }
+ })
+ }
+*/
+}
+
+/**
+ * Sends the provided array of logs to the specified url,
+ * retrying the request up to the specified number of retries.
+ * @param {Array} logs Array of logs to send.
+ * @param {string} config configuration parameters (e.g., to extract URL
from & send the POST request to).
+ * @param {Number} retries Maximum number of attempts to send the logs.
+ */
+
+// @todo expose config object to sendLogs replate url with config.url
+function sendLogs(logs, config, retries) {
+ var req = new XMLHttpRequest();
+
+ // @todo setRequestHeader for Auth
+ var data = JSON.stringify(logs);
+
+ req.open('POST', config.url);
+ if (config.authHeader) {
+ req.setRequestHeader('Authorization', config.authHeader);
+ }
+
+ req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
+
+ req.onreadystatechange = function() {
+ if (req.readyState === 4 && req.status !== 200) {
+ if (retries > 0) {
+ sendLogs(logs, config, retries--);
+ }
+ }
+ };
+
+ req.send(data);
+}
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
var config = {};
var logs = [];
var startLoadTimestamp = Date.now();
diff --git a/build/userale-2.1.1.js b/build/userale-2.1.1.js
index 6f04f7d..4f4f158 100644
--- a/build/userale-2.1.1.js
+++ b/build/userale-2.1.1.js
@@ -738,138 +738,6 @@
* limitations under the License.
*/
- var sendIntervalId = null;
-
- /**
- * Initializes the log queue processors.
- * @param {Array} logs Array of logs to append to.
- * @param {Object} config Configuration object to use when logging.
- */
- function initSender(logs, config) {
- if (sendIntervalId !== null) {
- clearInterval(sendIntervalId);
- }
-
- sendIntervalId = sendOnInterval(logs, config);
- sendOnClose(logs, config);
- }
-
- /**
- * Checks the provided log array on an interval, flushing the logs
- * if the queue has reached the threshold specified by the provided config.
- * @param {Array} logs Array of logs to read from.
- * @param {Object} config Configuration object to be read from.
- * @return {Number} The newly created interval id.
- */
- function sendOnInterval(logs, config) {
- return setInterval(function() {
- if (!config.on) {
- return;
- }
-
- if (logs.length >= config.logCountThreshold) {
- sendLogs(logs.slice(0), config, 0); // Send a copy
- logs.splice(0); // Clear array reference (no reassignment)
- }
- }, config.transmitInterval);
- }
-
- /**
- * Provides a simplified send function that can be called before events that
would
- * refresh page can resolve so that log queue ('logs) can be shipped
immediately. This
- * is different than sendOnClose because browser security practices prevent
you from
- * listening the process responsible for window navigation actions, in
action (e.g., refresh;
- * you can only detect, after the fact, the process responsible for the
current window state.
- * @param {Array} logs Array of logs to read from.
- * @param {Object} config Configuration object to be read from.
- */
- function sendOnRefresh(logs, config) {
- if (!config.on) {
- return;
- }
- if (logs.length > 0) {
- sendLogs(logs, config, 1);
- }
- }
-
- /**
- * Attempts to flush the remaining logs when the window is closed.
- * @param {Array} logs Array of logs to be flushed.
- * @param {Object} config Configuration object to be read from.
- */
- function sendOnClose(logs, config) {
- /** if (!config.on) {
- return;
- } */
- 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);
- }
- })
- }
- */
- }
-
- /**
- * Sends the provided array of logs to the specified url,
- * retrying the request up to the specified number of retries.
- * @param {Array} logs Array of logs to send.
- * @param {string} config configuration parameters (e.g., to extract
URL from & send the POST request to).
- * @param {Number} retries Maximum number of attempts to send the logs.
- */
-
- // @todo expose config object to sendLogs replate url with config.url
- function sendLogs(logs, config, retries) {
- var req = new XMLHttpRequest();
-
- // @todo setRequestHeader for Auth
- var data = JSON.stringify(logs);
-
- req.open('POST', config.url);
- if (config.authHeader) {
- req.setRequestHeader('Authorization', config.authHeader);
- }
-
- req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
-
- req.onreadystatechange = function() {
- if (req.readyState === 4 && req.status !== 200) {
- if (retries > 0) {
- sendLogs(logs, config, retries--);
- }
- }
- };
-
- req.send(data);
- }
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
// @todo var>let
var events;
var bufferBools;
@@ -1000,7 +868,6 @@
Object.keys(refreshEvents).forEach(function(ev) {
document.addEventListener(ev, function(e) {
packageLog(e, events[ev]);
- sendOnRefresh(logs$1,config);
}, true);
});
@@ -1030,6 +897,121 @@
* limitations under the License.
*/
+ var sendIntervalId = null;
+
+ /**
+ * Initializes the log queue processors.
+ * @param {Array} logs Array of logs to append to.
+ * @param {Object} config Configuration object to use when logging.
+ */
+ function initSender(logs, config) {
+ if (sendIntervalId !== null) {
+ clearInterval(sendIntervalId);
+ }
+
+ sendIntervalId = sendOnInterval(logs, config);
+ sendOnClose(logs, config);
+ }
+
+ /**
+ * Checks the provided log array on an interval, flushing the logs
+ * if the queue has reached the threshold specified by the provided config.
+ * @param {Array} logs Array of logs to read from.
+ * @param {Object} config Configuration object to be read from.
+ * @return {Number} The newly created interval id.
+ */
+ function sendOnInterval(logs, config) {
+ return setInterval(function() {
+ if (!config.on) {
+ return;
+ }
+
+ if (logs.length >= config.logCountThreshold) {
+ sendLogs(logs.slice(0), config, 0); // Send a copy
+ logs.splice(0); // Clear array reference (no reassignment)
+ }
+ }, config.transmitInterval);
+ }
+
+ /**
+ * Attempts to flush the remaining logs when the window is closed.
+ * @param {Array} logs Array of logs to be flushed.
+ * @param {Object} config Configuration object to be read from.
+ */
+ function sendOnClose(logs, config) {
+ /** if (!config.on) {
+ return;
+ } */
+ document.addEventListener('visibilitychange', function () {
+ if (document.visibilityState === 'hidden' && logs.length > 0) {
+ navigator.sendBeacon(config.url, JSON.stringify(logs));
+ logs.splice(0); // Clear array reference (no reassignment)
+ }
+ });
+ /**
+ if (navigator.sendBeacon) {
+ window.addEventListener('unload', function() {
+ ;
+ } else {
+ window.addEventListener('beforeunload', function() {
+ if (logs.length > 0) {
+ sendLogs(logs, config, 1);
+ }
+ })
+ }
+ */
+ }
+
+ /**
+ * Sends the provided array of logs to the specified url,
+ * retrying the request up to the specified number of retries.
+ * @param {Array} logs Array of logs to send.
+ * @param {string} config configuration parameters (e.g., to extract
URL from & send the POST request to).
+ * @param {Number} retries Maximum number of attempts to send the logs.
+ */
+
+ // @todo expose config object to sendLogs replate url with config.url
+ function sendLogs(logs, config, retries) {
+ var req = new XMLHttpRequest();
+
+ // @todo setRequestHeader for Auth
+ var data = JSON.stringify(logs);
+
+ req.open('POST', config.url);
+ if (config.authHeader) {
+ req.setRequestHeader('Authorization', config.authHeader);
+ }
+
+ req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
+
+ req.onreadystatechange = function() {
+ if (req.readyState === 4 && req.status !== 200) {
+ if (retries > 0) {
+ sendLogs(logs, config, retries--);
+ }
+ }
+ };
+
+ req.send(data);
+ }
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
var config = {};
var logs = [];
var startLoadTimestamp = Date.now();
diff --git a/build/userale-2.1.1.min.js b/build/userale-2.1.1.min.js
index 9593f55..50736ea 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",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
+!function(e,t){"object"==typeof exports&&"undefined"!=typeof
module?t(exports):"function"==typeof
define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof
globalThis?globalThis:e||self).userale={})}(this,function(n){"use strict";var
e="2.1.1",i=null;function t(n,o){Object.keys(o).forEach(function(e){var
t;"userFromParams"!==e||(t=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/attachHandlers.js b/src/attachHandlers.js
index 0d6967a..dbe0277 100644
--- a/src/attachHandlers.js
+++ b/src/attachHandlers.js
@@ -15,10 +15,8 @@
* limitations under the License.
*/
-import { logs } from './packageLogs';
import { packageLog } from './packageLogs.js';
import { packageIntervalLog} from './packageLogs';
-import { sendOnRefresh } from "./sendLogs";
// @todo var>let
var events;
@@ -150,7 +148,6 @@ export function attachHandlers(config) {
Object.keys(refreshEvents).forEach(function(ev) {
document.addEventListener(ev, function(e) {
packageLog(e, events[ev]);
- sendOnRefresh(logs,config);
}, true);
});
diff --git a/src/sendLogs.js b/src/sendLogs.js
index 20beec7..29167ae 100644
--- a/src/sendLogs.js
+++ b/src/sendLogs.js
@@ -52,24 +52,6 @@ export function sendOnInterval(logs, config) {
}
/**
- * Provides a simplified send function that can be called before events that
would
- * refresh page can resolve so that log queue ('logs) can be shipped
immediately. This
- * is different than sendOnClose because browser security practices prevent
you from
- * listening the process responsible for window navigation actions, in action
(e.g., refresh;
- * you can only detect, after the fact, the process responsible for the
current window state.
- * @param {Array} logs Array of logs to read from.
- * @param {Object} config Configuration object to be read from.
- */
-export function sendOnRefresh(logs, config) {
- if (!config.on) {
- return;
- }
- if (logs.length > 0) {
- sendLogs(logs, config, 1);
- }
-}
-
-/**
* Attempts to flush the remaining logs when the window is closed.
* @param {Array} logs Array of logs to be flushed.
* @param {Object} config Configuration object to be read from.
@@ -81,6 +63,7 @@ export function sendOnClose(logs, config) {
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'hidden' && logs.length > 0) {
navigator.sendBeacon(config.url, JSON.stringify(logs));
+ logs.splice(0); // Clear array reference (no reassignment)
}
});
/**