@constructor-io/constructorio-client-javascript 2.61.0 → 2.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/humanity-check.js +23 -22
- package/lib/utils/request-queue.js +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -13,11 +13,12 @@ var HumanityCheck = /*#__PURE__*/function () {
|
|
|
13
13
|
function HumanityCheck() {
|
|
14
14
|
var _this = this;
|
|
15
15
|
(0, _classCallCheck2["default"])(this, HumanityCheck);
|
|
16
|
-
|
|
16
|
+
// Check if a human event has been performed in the past
|
|
17
|
+
this.hasPerformedHumanEvent = !!store.session.get(storageKey) || false;
|
|
17
18
|
|
|
18
|
-
// Humanity proved, remove handlers
|
|
19
|
+
// Humanity proved, remove handlers
|
|
19
20
|
var remove = function remove() {
|
|
20
|
-
_this.
|
|
21
|
+
_this.hasPerformedHumanEvent = true;
|
|
21
22
|
store.session.set(storageKey, true);
|
|
22
23
|
humanEvents.forEach(function (eventType) {
|
|
23
24
|
helpers.removeEventListener(eventType, remove, true);
|
|
@@ -25,37 +26,37 @@ var HumanityCheck = /*#__PURE__*/function () {
|
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
// Add handlers to prove humanity
|
|
28
|
-
if (!this.
|
|
29
|
+
if (!this.hasPerformedHumanEvent) {
|
|
29
30
|
humanEvents.forEach(function (eventType) {
|
|
30
31
|
helpers.addEventListener(eventType, remove, true);
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
(0, _createClass2["default"])(HumanityCheck, [{
|
|
35
|
-
key: "getIsHumanFromSessionStorage",
|
|
36
|
-
value: function getIsHumanFromSessionStorage() {
|
|
37
|
-
return !!store.session.get(storageKey) || false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Return boolean indicating if is human
|
|
41
|
-
}, {
|
|
42
|
-
key: "isHuman",
|
|
43
|
-
value: function isHuman() {
|
|
44
|
-
return this.isHumanBoolean || !!store.session.get(storageKey);
|
|
45
|
-
}
|
|
46
35
|
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
// Return boolean indicating if user is a bot
|
|
37
|
+
// ...if it has a bot-like useragent
|
|
38
|
+
// ...or uses webdriver
|
|
39
|
+
// ...or has not performed a human event
|
|
40
|
+
(0, _createClass2["default"])(HumanityCheck, [{
|
|
49
41
|
key: "isBot",
|
|
50
42
|
value: function isBot() {
|
|
51
|
-
if (this.getIsHumanFromSessionStorage()) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
43
|
var _helpers$getNavigator = helpers.getNavigator(),
|
|
55
44
|
userAgent = _helpers$getNavigator.userAgent,
|
|
56
45
|
webdriver = _helpers$getNavigator.webdriver;
|
|
57
46
|
var botRegex = new RegExp("(".concat(botList.join('|'), ")"));
|
|
58
|
-
|
|
47
|
+
|
|
48
|
+
// Always check the user agent and webdriver fields first to determine if the user is a bot
|
|
49
|
+
if (Boolean(userAgent.match(botRegex)) || Boolean(webdriver)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// If the user hasn't performed a human event, it indicates it is a bot
|
|
54
|
+
if (!this.hasPerformedHumanEvent) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Otherwise, it is a human
|
|
59
|
+
return false;
|
|
59
60
|
}
|
|
60
61
|
}]);
|
|
61
62
|
return HumanityCheck;
|
|
@@ -62,7 +62,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
62
62
|
var queue = RequestQueue.get();
|
|
63
63
|
if (
|
|
64
64
|
// Consider user "human" if no DOM context is available
|
|
65
|
-
(!helpers.canUseDOM() || this.humanity.
|
|
65
|
+
(!helpers.canUseDOM() || !this.humanity.isBot()) && !this.requestPending && !this.pageUnloading && queue.length) {
|
|
66
66
|
var request;
|
|
67
67
|
var nextInQueue = queue.shift();
|
|
68
68
|
var _nextInQueue = nextInQueue,
|
package/lib/version.js
CHANGED