Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit e8a9b66

Browse files
authored
Merge branch 'test' into dependabot/npm_and_yarn/test/jsdom-and-global-jsdom-23.0.1
2 parents d4cb2fb + aac2dce commit e8a9b66

28 files changed

+3114
-605
lines changed

build/UserALEWebExtension/background.js

Lines changed: 813 additions & 160 deletions
Large diffs are not rendered by default.

build/UserALEWebExtension/content.js

Lines changed: 111 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one or more
3-
* contributor license agreements. See the NOTICE file distributed with
4-
* this work for additional information regarding copyright ownership.
5-
* The ASF licenses this file to You under the Apache License, Version 2.0
6-
* (the "License"); you may not use this file except in compliance with
7-
* the License. You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
17-
18-
/* eslint-disable */
19-
20-
// these are default values, which can be overridden by the user on the options page
21-
var userAleHost = 'http://localhost:8000';
22-
var userAleScript = 'userale-2.4.0.min.js';
23-
var toolUser = 'nobody';
24-
var toolName = 'test_app';
25-
var toolVersion = '2.4.0';
26-
27-
/* eslint-enable */
28-
291
/*
302
* Licensed to the Apache Software Foundation (ASF) under one or more
313
* contributor license agreements. See the NOTICE file distributed with
@@ -99,6 +71,7 @@ function getInitialSettings() {
9971
settings.sessionID = get('data-session') || sessionId;
10072
settings.authHeader = get('data-auth') || null;
10173
settings.custIndex = get('data-index') || null;
74+
settings.headers = get('data-headers') || null;
10275
return settings;
10376
}
10477

@@ -432,7 +405,7 @@ function createVersionParts(count) {
432405
* limitations under the License.
433406
*/
434407

435-
var browser$1 = detect();
408+
var browserInfo = detect();
436409
var logs$1;
437410
var config$1;
438411

@@ -747,8 +720,8 @@ function selectorizePath(path) {
747720
}
748721
function detectBrowser() {
749722
return {
750-
'browser': browser$1 ? browser$1.name : '',
751-
'version': browser$1 ? browser$1.version : ''
723+
'browser': browserInfo ? browserInfo.name : '',
724+
'version': browserInfo ? browserInfo.version : ''
752725
};
753726
}
754727

@@ -906,22 +879,60 @@ function attachHandlers(config) {
906879
return true;
907880
}
908881

909-
/*
910-
* Licensed to the Apache Software Foundation (ASF) under one or more
911-
* contributor license agreements. See the NOTICE file distributed with
912-
* this work for additional information regarding copyright ownership.
913-
* The ASF licenses this file to You under the Apache License, Version 2.0
914-
* (the "License"); you may not use this file except in compliance with
915-
* the License. You may obtain a copy of the License at
916-
*
917-
* http://www.apache.org/licenses/LICENSE-2.0
918-
*
919-
* Unless required by applicable law or agreed to in writing, software
920-
* distributed under the License is distributed on an "AS IS" BASIS,
921-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
922-
* See the License for the specific language governing permissions and
923-
* limitations under the License.
924-
*/
882+
function _arrayWithHoles(arr) {
883+
if (Array.isArray(arr)) return arr;
884+
}
885+
886+
function _iterableToArrayLimit(r, l) {
887+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
888+
if (null != t) {
889+
var e,
890+
n,
891+
i,
892+
u,
893+
a = [],
894+
f = !0,
895+
o = !1;
896+
try {
897+
if (i = (t = t.call(r)).next, 0 === l) {
898+
if (Object(t) !== t) return;
899+
f = !1;
900+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
901+
} catch (r) {
902+
o = !0, n = r;
903+
} finally {
904+
try {
905+
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
906+
} finally {
907+
if (o) throw n;
908+
}
909+
}
910+
return a;
911+
}
912+
}
913+
914+
function _arrayLikeToArray(arr, len) {
915+
if (len == null || len > arr.length) len = arr.length;
916+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
917+
return arr2;
918+
}
919+
920+
function _unsupportedIterableToArray(o, minLen) {
921+
if (!o) return;
922+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
923+
var n = Object.prototype.toString.call(o).slice(8, -1);
924+
if (n === "Object" && o.constructor) n = o.constructor.name;
925+
if (n === "Map" || n === "Set") return Array.from(o);
926+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
927+
}
928+
929+
function _nonIterableRest() {
930+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
931+
}
932+
933+
function _slicedToArray(arr, i) {
934+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
935+
}
925936

926937
var sendIntervalId = null;
927938

@@ -963,8 +974,13 @@ function sendOnInterval(logs, config) {
963974
* @param {Object} config Configuration object to be read from.
964975
*/
965976
function sendOnClose(logs, config) {
966-
window.addEventListener('pagehide', function () {
977+
window.addEventListener("pagehide", function () {
967978
if (config.on && logs.length > 0) {
979+
// NOTE: sendBeacon does not support auth headers,
980+
// so this will fail if auth is required.
981+
// The alternative is to use fetch() with keepalive: true
982+
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon#description
983+
// https://stackoverflow.com/a/73062712/9263449
968984
navigator.sendBeacon(config.url, JSON.stringify(logs));
969985
logs.splice(0); // clear log queue
970986
}
@@ -982,14 +998,20 @@ function sendOnClose(logs, config) {
982998
// @todo expose config object to sendLogs replate url with config.url
983999
function sendLogs(logs, config, retries) {
9841000
var req = new XMLHttpRequest();
985-
986-
// @todo setRequestHeader for Auth
9871001
var data = JSON.stringify(logs);
988-
req.open('POST', config.url);
1002+
req.open("POST", config.url);
9891003
if (config.authHeader) {
990-
req.setRequestHeader('Authorization', config.authHeader);
1004+
req.setRequestHeader("Authorization", config.authHeader);
1005+
}
1006+
req.setRequestHeader("Content-type", "application/json;charset=UTF-8");
1007+
if (config.headers) {
1008+
Object.entries(config.headers).forEach(function (_ref) {
1009+
var _ref2 = _slicedToArray(_ref, 2),
1010+
header = _ref2[0],
1011+
value = _ref2[1];
1012+
req.setRequestHeader(header, value);
1013+
});
9911014
}
992-
req.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
9931015
req.onreadystatechange = function () {
9941016
if (req.readyState === 4 && req.status !== 200) {
9951017
if (retries > 0) {
@@ -1033,7 +1055,6 @@ function setup(config) {
10331055
started = config.on = true;
10341056
packageCustomLog({
10351057
type: 'load',
1036-
logType: 'raw',
10371058
details: {
10381059
pageLoadTime: endLoadTimestamp - startLoadTimestamp
10391060
}
@@ -1058,6 +1079,37 @@ function options(newConfig) {
10581079
return config;
10591080
}
10601081

1082+
/*
1083+
* Licensed to the Apache Software Foundation (ASF) under one or more
1084+
* contributor license agreements. See the NOTICE file distributed with
1085+
* this work for additional information regarding copyright ownership.
1086+
* The ASF licenses this file to You under the Apache License, Version 2.0
1087+
* (the "License"); you may not use this file except in compliance with
1088+
* the License. You may obtain a copy of the License at
1089+
*
1090+
* http://www.apache.org/licenses/LICENSE-2.0
1091+
*
1092+
* Unless required by applicable law or agreed to in writing, software
1093+
* distributed under the License is distributed on an "AS IS" BASIS,
1094+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1095+
* See the License for the specific language governing permissions and
1096+
* limitations under the License.
1097+
*/
1098+
1099+
1100+
// browser is defined in firefox, but chrome uses the 'chrome' global.
1101+
var browser = browser || chrome;
1102+
function rerouteLog(log) {
1103+
console.log("reroute");
1104+
browser.runtime.sendMessage({
1105+
type: ADD_LOG,
1106+
payload: log
1107+
});
1108+
return false;
1109+
}
1110+
1111+
/* eslint-enable */
1112+
10611113
/*
10621114
* Licensed to the Apache Software Foundation (ASF) under one or more
10631115
* contributor license agreements. See the NOTICE file distributed with
@@ -1075,59 +1127,15 @@ function options(newConfig) {
10751127
* limitations under the License.
10761128
*/
10771129

1078-
1079-
// browser is defined in firefox, but not in chrome. In chrome, they use
1080-
// the 'chrome' global instead. Let's map it to browser so we don't have
1081-
// to have if-conditions all over the place.
1082-
1083-
var browser = browser || chrome;
1084-
1085-
// creates a Future for retrieval of the named keys
1086-
// the value specified is the default value if one doesn't exist in the storage
1087-
browser.storage.local.get({
1088-
sessionId: null,
1089-
userAleHost: userAleHost,
1090-
userAleScript: userAleScript,
1091-
toolUser: toolUser,
1092-
toolName: toolName,
1093-
toolVersion: toolVersion
1094-
}, storeCallback);
1095-
function storeCallback(item) {
1096-
injectScript({
1097-
url: item.userAleHost,
1098-
userId: item.toolUser,
1099-
sessionID: item.sessionId,
1100-
toolName: item.toolName,
1101-
toolVersion: item.toolVersion
1102-
});
1103-
}
1104-
function queueLog(log) {
1105-
browser.runtime.sendMessage({
1106-
type: ADD_LOG,
1107-
payload: log
1108-
});
1109-
}
1110-
function injectScript(config) {
1111-
options(config);
1112-
// start(); not necessary given that autostart in place, and option is masked from WebExt users
1130+
browser.storage.local.get("useraleConfig", function (res) {
1131+
options(res.useraleConfig);
11131132
addCallbacks({
1114-
"function": function _function(log) {
1115-
queueLog(Object.assign({}, log, {
1116-
pageUrl: document.location.href
1117-
}));
1118-
console.log(log);
1119-
return false;
1120-
}
1133+
rerouteLog: rerouteLog
11211134
});
1122-
}
1135+
});
11231136
browser.runtime.onMessage.addListener(function (message) {
11241137
if (message.type === CONFIG_CHANGE) {
1125-
options({
1126-
url: message.payload.userAleHost,
1127-
userId: message.payload.toolUser,
1128-
toolName: message.payload.toolName,
1129-
toolVersion: message.payload.toolVersion
1130-
});
1138+
options(message.payload);
11311139
}
11321140
});
11331141

0 commit comments

Comments
 (0)