Add tabId to log entries
diff --git a/src/UserALEWebExtension/background.js b/src/UserALEWebExtension/background.js
index d8aed77..20cb4f8 100644
--- a/src/UserALEWebExtension/background.js
+++ b/src/UserALEWebExtension/background.js
@@ -75,6 +75,9 @@
// Attach Handlers for tab events
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs
browser.tabs.onActivated.addListener((activeInfo) => {
+ browser.storage.local.set({ "tabId": e.tabId }, function() {
+ console.log("The tabID has been set in storage.local");
+ });
packageTabLog(activeInfo.tabId, activeInfo, "tabs.onActivated");
});
diff --git a/src/packageLogs.js b/src/packageLogs.js
index db287d1..d8807bf 100644
--- a/src/packageLogs.js
+++ b/src/packageLogs.js
@@ -33,6 +33,7 @@
export let mapHandler = null;
export let cbHandlers = {};
+
/**
* Assigns a handler to filter logs out of the queue.
* @deprecated Use addCallbacks and removeCallbacks instead
@@ -105,12 +106,27 @@
}
/**
+ * Get the tabID from local storage
+ */
+function getTabId() {
+ return new Promise((resolve, reject) => {
+ chrome.storage.local.get("tabId", function(result) {
+ if (result.tabId !== undefined) {
+ resolve(result.tabId);
+ } else {
+ reject('tabId not found');
+ }
+ });
+ });
+}
+
+/**
* Transforms the provided HTML event into a log and appends it to the log queue.
* @param {Object} e The event to be logged.
* @param {Function} detailFcn The function to extract additional log parameters from the event.
* @return {boolean} Whether the event was logged.
*/
-export function packageLog(e, detailFcn) {
+export async function packageLog(e, detailFcn) {
if (!config.on) {
return false;
}
@@ -124,6 +140,8 @@
(e.timeStamp && e.timeStamp > 0) ? config.time(e.timeStamp) : Date.now()
);
+ const tabId = await getTabId();
+
let log = {
'target' : getSelector(e.target),
'path' : buildPath(e),
@@ -143,6 +161,7 @@
'toolVersion' : config.version,
'toolName' : config.toolName,
'useraleVersion': config.useraleVersion,
+ 'tabId': tabId,
'sessionID': config.sessionID,
};
@@ -174,7 +193,7 @@
* @param {boolean} userAction Indicates user behavior (true) or system behavior (false)
* @return {boolean} Whether the event was logged.
*/
-export function packageCustomLog(customLog, detailFcn, userAction) {
+export async function packageCustomLog(customLog, detailFcn, userAction) {
if (!config.on) {
return false;
}
@@ -184,6 +203,8 @@
details = detailFcn();
}
+ const tabId = await getTabId();
+
const metaData = {
'pageUrl': window.location.href,
'pageTitle': document.title,
@@ -198,6 +219,7 @@
'toolVersion' : config.version,
'toolName' : config.toolName,
'useraleVersion': config.useraleVersion,
+ 'tabId': tabId,
'sessionID': config.sessionID
};
@@ -243,7 +265,7 @@
* @param {Object} e
* @return boolean
*/
-export function packageIntervalLog(e) {
+export async function packageIntervalLog(e) {
const target = getSelector(e.target);
const path = buildPath(e);
const type = e.type;
@@ -258,6 +280,8 @@
intervalCounter = 0;
}
+ const tabId = await getTabId();
+
if (intervalID !== target || intervalType !== type) {
// When to create log? On transition end
// @todo Possible for intervalLog to not be pushed in the event the interval never ends...
@@ -282,6 +306,7 @@
'toolVersion': config.version,
'toolName': config.toolName,
'useraleVersion': config.useraleVersion,
+ 'tabId': tabId,
'sessionID': config.sessionID
};