@axeptio/behavior-detection 1.0.0 → 1.0.2
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/dist/behavior-detection.esm.min.js.map +1 -1
- package/dist/behavior-detection.min.js.map +1 -1
- package/dist/behavior-detector.d.ts +2 -2
- package/dist/cjs/behavior-detector.d.ts +2 -2
- package/dist/cjs/browser.js +2 -2
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/strategies/click.d.ts +1 -1
- package/dist/cjs/strategies/click.js +2 -2
- package/dist/cjs/strategies/environment.d.ts +1 -1
- package/dist/cjs/strategies/environment.js +5 -5
- package/dist/cjs/strategies/index.d.ts +14 -14
- package/dist/cjs/strategies/index.js +28 -28
- package/dist/cjs/strategies/keyboard.d.ts +1 -1
- package/dist/cjs/strategies/keyboard.js +7 -7
- package/dist/cjs/strategies/mouse.d.ts +1 -1
- package/dist/cjs/strategies/mouse.js +6 -6
- package/dist/cjs/strategies/resize.d.ts +1 -1
- package/dist/cjs/strategies/resize.js +5 -5
- package/dist/cjs/strategies/scroll.d.ts +1 -1
- package/dist/cjs/strategies/scroll.js +8 -8
- package/dist/cjs/strategies/tap.d.ts +1 -1
- package/dist/cjs/strategies/tap.js +9 -9
- package/dist/esm/behavior-detector.d.ts +2 -2
- package/dist/esm/browser-iife.d.ts +5 -0
- package/dist/esm/browser-iife.js +157 -0
- package/dist/esm/browser.js +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +2 -2
- package/dist/esm/strategies/click.d.ts +1 -1
- package/dist/esm/strategies/click.js +1 -1
- package/dist/esm/strategies/environment.d.ts +1 -1
- package/dist/esm/strategies/environment.js +2 -2
- package/dist/esm/strategies/index.d.ts +14 -14
- package/dist/esm/strategies/index.js +14 -14
- package/dist/esm/strategies/keyboard.d.ts +1 -1
- package/dist/esm/strategies/keyboard.js +2 -2
- package/dist/esm/strategies/mouse.d.ts +1 -1
- package/dist/esm/strategies/mouse.js +2 -2
- package/dist/esm/strategies/resize.d.ts +1 -1
- package/dist/esm/strategies/resize.js +2 -2
- package/dist/esm/strategies/scroll.d.ts +1 -1
- package/dist/esm/strategies/scroll.js +2 -2
- package/dist/esm/strategies/tap.d.ts +1 -1
- package/dist/esm/strategies/tap.js +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/strategies/click.d.ts +1 -1
- package/dist/strategies/environment.d.ts +1 -1
- package/dist/strategies/index.d.ts +14 -14
- package/dist/strategies/keyboard.d.ts +1 -1
- package/dist/strategies/mouse.d.ts +1 -1
- package/dist/strategies/resize.d.ts +1 -1
- package/dist/strategies/scroll.d.ts +1 -1
- package/dist/strategies/tap.d.ts +1 -1
- package/package.json +6 -6
|
@@ -5,32 +5,32 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.Resize = exports.Environment = exports.Keyboard = exports.Tap = exports.Click = exports.Scroll = exports.Mouse = exports.ResizeStrategy = exports.EnvironmentStrategy = exports.KeyboardStrategy = exports.TapStrategy = exports.ClickStrategy = exports.ScrollStrategy = exports.MouseStrategy = void 0;
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "MouseStrategy", { enumerable: true, get: function () { return
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "ScrollStrategy", { enumerable: true, get: function () { return
|
|
12
|
-
var
|
|
13
|
-
Object.defineProperty(exports, "ClickStrategy", { enumerable: true, get: function () { return
|
|
14
|
-
var
|
|
15
|
-
Object.defineProperty(exports, "TapStrategy", { enumerable: true, get: function () { return
|
|
16
|
-
var
|
|
17
|
-
Object.defineProperty(exports, "KeyboardStrategy", { enumerable: true, get: function () { return
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "EnvironmentStrategy", { enumerable: true, get: function () { return
|
|
20
|
-
var
|
|
21
|
-
Object.defineProperty(exports, "ResizeStrategy", { enumerable: true, get: function () { return
|
|
8
|
+
var mouse_js_1 = require("./mouse.js");
|
|
9
|
+
Object.defineProperty(exports, "MouseStrategy", { enumerable: true, get: function () { return mouse_js_1.MouseStrategy; } });
|
|
10
|
+
var scroll_js_1 = require("./scroll.js");
|
|
11
|
+
Object.defineProperty(exports, "ScrollStrategy", { enumerable: true, get: function () { return scroll_js_1.ScrollStrategy; } });
|
|
12
|
+
var click_js_1 = require("./click.js");
|
|
13
|
+
Object.defineProperty(exports, "ClickStrategy", { enumerable: true, get: function () { return click_js_1.ClickStrategy; } });
|
|
14
|
+
var tap_js_1 = require("./tap.js");
|
|
15
|
+
Object.defineProperty(exports, "TapStrategy", { enumerable: true, get: function () { return tap_js_1.TapStrategy; } });
|
|
16
|
+
var keyboard_js_1 = require("./keyboard.js");
|
|
17
|
+
Object.defineProperty(exports, "KeyboardStrategy", { enumerable: true, get: function () { return keyboard_js_1.KeyboardStrategy; } });
|
|
18
|
+
var environment_js_1 = require("./environment.js");
|
|
19
|
+
Object.defineProperty(exports, "EnvironmentStrategy", { enumerable: true, get: function () { return environment_js_1.EnvironmentStrategy; } });
|
|
20
|
+
var resize_js_1 = require("./resize.js");
|
|
21
|
+
Object.defineProperty(exports, "ResizeStrategy", { enumerable: true, get: function () { return resize_js_1.ResizeStrategy; } });
|
|
22
22
|
// Convenience: All strategies
|
|
23
|
-
var
|
|
24
|
-
Object.defineProperty(exports, "Mouse", { enumerable: true, get: function () { return
|
|
25
|
-
var
|
|
26
|
-
Object.defineProperty(exports, "Scroll", { enumerable: true, get: function () { return
|
|
27
|
-
var
|
|
28
|
-
Object.defineProperty(exports, "Click", { enumerable: true, get: function () { return
|
|
29
|
-
var
|
|
30
|
-
Object.defineProperty(exports, "Tap", { enumerable: true, get: function () { return
|
|
31
|
-
var
|
|
32
|
-
Object.defineProperty(exports, "Keyboard", { enumerable: true, get: function () { return
|
|
33
|
-
var
|
|
34
|
-
Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return
|
|
35
|
-
var
|
|
36
|
-
Object.defineProperty(exports, "Resize", { enumerable: true, get: function () { return
|
|
23
|
+
var mouse_js_2 = require("./mouse.js");
|
|
24
|
+
Object.defineProperty(exports, "Mouse", { enumerable: true, get: function () { return mouse_js_2.MouseStrategy; } });
|
|
25
|
+
var scroll_js_2 = require("./scroll.js");
|
|
26
|
+
Object.defineProperty(exports, "Scroll", { enumerable: true, get: function () { return scroll_js_2.ScrollStrategy; } });
|
|
27
|
+
var click_js_2 = require("./click.js");
|
|
28
|
+
Object.defineProperty(exports, "Click", { enumerable: true, get: function () { return click_js_2.ClickStrategy; } });
|
|
29
|
+
var tap_js_2 = require("./tap.js");
|
|
30
|
+
Object.defineProperty(exports, "Tap", { enumerable: true, get: function () { return tap_js_2.TapStrategy; } });
|
|
31
|
+
var keyboard_js_2 = require("./keyboard.js");
|
|
32
|
+
Object.defineProperty(exports, "Keyboard", { enumerable: true, get: function () { return keyboard_js_2.KeyboardStrategy; } });
|
|
33
|
+
var environment_js_2 = require("./environment.js");
|
|
34
|
+
Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return environment_js_2.EnvironmentStrategy; } });
|
|
35
|
+
var resize_js_2 = require("./resize.js");
|
|
36
|
+
Object.defineProperty(exports, "Resize", { enumerable: true, get: function () { return resize_js_2.ResizeStrategy; } });
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Monitors typing in specific input fields
|
|
4
4
|
* Analyzes keydown/keyup timing and micro-variations
|
|
5
5
|
*/
|
|
6
|
-
import { BaseStrategy } from '../strategy';
|
|
6
|
+
import { BaseStrategy } from '../strategy.js';
|
|
7
7
|
export declare class KeyboardStrategy extends BaseStrategy {
|
|
8
8
|
readonly name = "keyboard";
|
|
9
9
|
readonly defaultWeight = 0.1;
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.KeyboardStrategy = void 0;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
class KeyboardStrategy extends
|
|
9
|
+
const strategy_js_1 = require("../strategy.js");
|
|
10
|
+
const math_utils_js_1 = require("../math-utils.js");
|
|
11
|
+
class KeyboardStrategy extends strategy_js_1.BaseStrategy {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super();
|
|
14
14
|
this.name = 'keyboard';
|
|
@@ -151,14 +151,14 @@ class KeyboardStrategy extends strategy_1.BaseStrategy {
|
|
|
151
151
|
for (let i = 1; i < downEvents.length; i++) {
|
|
152
152
|
keystrokeIntervals.push(downEvents[i].timestamp - downEvents[i - 1].timestamp);
|
|
153
153
|
}
|
|
154
|
-
const keystrokeAnalysis = (0,
|
|
154
|
+
const keystrokeAnalysis = (0, math_utils_js_1.analyzeIntervals)(keystrokeIntervals);
|
|
155
155
|
if (keystrokeAnalysis) {
|
|
156
156
|
const { statistics, allIdentical } = keystrokeAnalysis;
|
|
157
157
|
// Keyboard-specific heuristics for keystroke timing
|
|
158
158
|
if (allIdentical) {
|
|
159
159
|
return 0.1; // All identical - bot!
|
|
160
160
|
}
|
|
161
|
-
const keystrokeScore = (0,
|
|
161
|
+
const keystrokeScore = (0, math_utils_js_1.scoreCoefficientOfVariation)(statistics.cv);
|
|
162
162
|
score += keystrokeScore;
|
|
163
163
|
factors++;
|
|
164
164
|
// Early return if bot detected
|
|
@@ -173,7 +173,7 @@ class KeyboardStrategy extends strategy_1.BaseStrategy {
|
|
|
173
173
|
pressDurations.push(this.events[i + 1].timestamp - this.events[i].timestamp);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
const pressDurationAnalysis = (0,
|
|
176
|
+
const pressDurationAnalysis = (0, math_utils_js_1.analyzeIntervals)(pressDurations);
|
|
177
177
|
if (pressDurationAnalysis) {
|
|
178
178
|
const { statistics, allIdentical } = pressDurationAnalysis;
|
|
179
179
|
// Keyboard-specific heuristics for press duration
|
|
@@ -186,7 +186,7 @@ class KeyboardStrategy extends strategy_1.BaseStrategy {
|
|
|
186
186
|
factors++;
|
|
187
187
|
}
|
|
188
188
|
else {
|
|
189
|
-
const pressDurationScore = (0,
|
|
189
|
+
const pressDurationScore = (0, math_utils_js_1.scoreCoefficientOfVariation)(statistics.cv);
|
|
190
190
|
score += pressDurationScore;
|
|
191
191
|
factors++;
|
|
192
192
|
// Early return if bot detected
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Autonomous module that manages its own mouse event listeners and state
|
|
4
4
|
* Tracks distance and angle to detect unnatural jumps and sharp turns
|
|
5
5
|
*/
|
|
6
|
-
import { BaseStrategy, type TimeSeriesPoint } from '../strategy';
|
|
6
|
+
import { BaseStrategy, type TimeSeriesPoint } from '../strategy.js';
|
|
7
7
|
export declare class MouseStrategy extends BaseStrategy {
|
|
8
8
|
readonly name = "mouse";
|
|
9
9
|
readonly defaultWeight = 0.3;
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.MouseStrategy = void 0;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
class MouseStrategy extends
|
|
9
|
+
const strategy_js_1 = require("../strategy.js");
|
|
10
|
+
const math_utils_js_1 = require("../math-utils.js");
|
|
11
|
+
class MouseStrategy extends strategy_js_1.BaseStrategy {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super();
|
|
14
14
|
this.name = 'mouse';
|
|
@@ -124,11 +124,11 @@ class MouseStrategy extends strategy_1.BaseStrategy {
|
|
|
124
124
|
// 1. VELOCITY CONSISTENCY - Bots often move at constant speed
|
|
125
125
|
const distances = this.distanceSeries.map(p => p.value);
|
|
126
126
|
if (distances.length >= 3) {
|
|
127
|
-
const stats = (0,
|
|
127
|
+
const stats = (0, math_utils_js_1.calculateStatistics)(distances);
|
|
128
128
|
// Real human movement has high variation (CV ~0.8-1.2)
|
|
129
129
|
// page.mouse.move() with steps has lower CV (~0.4-0.6)
|
|
130
130
|
// Narrower gaussian to be strict
|
|
131
|
-
score += (0,
|
|
131
|
+
score += (0, math_utils_js_1.gaussian)(stats.cv, 0.9, 0.35);
|
|
132
132
|
factors++;
|
|
133
133
|
}
|
|
134
134
|
// 2. DIRECTION CHANGES - Bots often have too few or too many sharp turns
|
|
@@ -141,7 +141,7 @@ class MouseStrategy extends strategy_1.BaseStrategy {
|
|
|
141
141
|
const avgChange = angleChanges.reduce((a, b) => a + b, 0) / angleChanges.length;
|
|
142
142
|
// Real humans have moderate but varied direction changes
|
|
143
143
|
// page.mouse.move() linear interpolation has very small, consistent changes
|
|
144
|
-
score += (0,
|
|
144
|
+
score += (0, math_utils_js_1.gaussian)(avgChange, 0.15, 0.12);
|
|
145
145
|
factors++;
|
|
146
146
|
}
|
|
147
147
|
return factors > 0 ? score / factors : undefined;
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ResizeStrategy = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
class ResizeStrategy extends
|
|
7
|
+
const strategy_js_1 = require("../strategy.js");
|
|
8
|
+
const math_utils_js_1 = require("../math-utils.js");
|
|
9
|
+
class ResizeStrategy extends strategy_js_1.BaseStrategy {
|
|
10
10
|
constructor() {
|
|
11
11
|
super(...arguments);
|
|
12
12
|
this.name = 'resize';
|
|
@@ -76,13 +76,13 @@ class ResizeStrategy extends strategy_1.BaseStrategy {
|
|
|
76
76
|
let score = 0;
|
|
77
77
|
let factors = 0;
|
|
78
78
|
// Frequency
|
|
79
|
-
score += (0,
|
|
79
|
+
score += (0, math_utils_js_1.inverseSigmoid)(this.events.length, 5, 0.5);
|
|
80
80
|
factors++;
|
|
81
81
|
// Mouse near edge
|
|
82
82
|
const withMouse = this.events.filter(e => e.mouseX !== undefined);
|
|
83
83
|
if (withMouse.length > 0) {
|
|
84
84
|
const nearEdge = withMouse.filter(e => e.mouseNearEdge).length;
|
|
85
|
-
score += (0,
|
|
85
|
+
score += (0, math_utils_js_1.sigmoid)(nearEdge / withMouse.length, 0.5, 8);
|
|
86
86
|
factors++;
|
|
87
87
|
}
|
|
88
88
|
return factors > 0 ? score / factors : undefined;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Autonomous module managing scroll event listeners
|
|
4
4
|
* Tracks normalized scroll distance and velocity patterns
|
|
5
5
|
*/
|
|
6
|
-
import { BaseStrategy, type TimeSeriesPoint } from '../strategy';
|
|
6
|
+
import { BaseStrategy, type TimeSeriesPoint } from '../strategy.js';
|
|
7
7
|
export declare class ScrollStrategy extends BaseStrategy {
|
|
8
8
|
readonly name = "scroll";
|
|
9
9
|
readonly defaultWeight = 0.15;
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.ScrollStrategy = void 0;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
class ScrollStrategy extends
|
|
9
|
+
const strategy_js_1 = require("../strategy.js");
|
|
10
|
+
const math_utils_js_1 = require("../math-utils.js");
|
|
11
|
+
class ScrollStrategy extends strategy_js_1.BaseStrategy {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super();
|
|
14
14
|
this.name = 'scroll';
|
|
@@ -110,20 +110,20 @@ class ScrollStrategy extends strategy_1.BaseStrategy {
|
|
|
110
110
|
}
|
|
111
111
|
// 2. DISTANCE CONSISTENCY - Bots often scroll same amount repeatedly
|
|
112
112
|
if (distances.length >= 2) {
|
|
113
|
-
const stats = (0,
|
|
113
|
+
const stats = (0, math_utils_js_1.calculateStatistics)(distances);
|
|
114
114
|
// Real humans have high CV (>0.8) due to natural scroll acceleration/deceleration
|
|
115
115
|
// Simple automation has lower CV even with varied amounts
|
|
116
116
|
// Gaussian centered high with narrow width - be strict
|
|
117
|
-
score += (0,
|
|
117
|
+
score += (0, math_utils_js_1.gaussian)(stats.cv, 1.0, 0.4);
|
|
118
118
|
factors++;
|
|
119
119
|
}
|
|
120
120
|
// 3. VELOCITY VARIATION - Humans have highly variable scroll speeds
|
|
121
121
|
const velocities = this.velocitySeries.map(p => p.value);
|
|
122
122
|
if (velocities.length >= 2) {
|
|
123
|
-
const stats = (0,
|
|
123
|
+
const stats = (0, math_utils_js_1.calculateStatistics)(velocities);
|
|
124
124
|
// Human velocity is very chaotic (acceleration/deceleration)
|
|
125
125
|
// Automation has more consistent velocity even with delays
|
|
126
|
-
score += (0,
|
|
126
|
+
score += (0, math_utils_js_1.gaussian)(stats.cv, 1.2, 0.5);
|
|
127
127
|
factors++;
|
|
128
128
|
}
|
|
129
129
|
// 4. INSTANT JUMPS - Detect programmatic scrollTo
|
|
@@ -131,7 +131,7 @@ class ScrollStrategy extends strategy_1.BaseStrategy {
|
|
|
131
131
|
if (distances.length > 0) {
|
|
132
132
|
const jumpRatio = instantJumps / distances.length;
|
|
133
133
|
// Penalize high jump ratio (programmatic scrollTo)
|
|
134
|
-
score += (0,
|
|
134
|
+
score += (0, math_utils_js_1.inverseSigmoid)(jumpRatio, 0.3, 15);
|
|
135
135
|
factors++;
|
|
136
136
|
}
|
|
137
137
|
return factors > 0 ? score / factors : undefined;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Monitors touch interactions on specific elements
|
|
4
4
|
* Analyzes tap duration, precision, movement, and timing patterns
|
|
5
5
|
*/
|
|
6
|
-
import { BaseStrategy } from '../strategy';
|
|
6
|
+
import { BaseStrategy } from '../strategy.js';
|
|
7
7
|
export declare class TapStrategy extends BaseStrategy {
|
|
8
8
|
readonly name = "tap";
|
|
9
9
|
readonly defaultWeight = 0.35;
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.TapStrategy = void 0;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
class TapStrategy extends
|
|
9
|
+
const strategy_js_1 = require("../strategy.js");
|
|
10
|
+
const math_utils_js_1 = require("../math-utils.js");
|
|
11
|
+
class TapStrategy extends strategy_js_1.BaseStrategy {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super();
|
|
14
14
|
this.name = 'tap';
|
|
@@ -159,7 +159,7 @@ class TapStrategy extends strategy_1.BaseStrategy {
|
|
|
159
159
|
// 2. Tap duration variation - Humans have natural variation (50-150ms typical)
|
|
160
160
|
const durations = this.events.map(e => e.duration);
|
|
161
161
|
if (durations.length >= 2) {
|
|
162
|
-
const durationAnalysis = (0,
|
|
162
|
+
const durationAnalysis = (0, math_utils_js_1.analyzeIntervals)(durations);
|
|
163
163
|
if (durationAnalysis) {
|
|
164
164
|
const { statistics, allIdentical } = durationAnalysis;
|
|
165
165
|
// All identical = bot
|
|
@@ -167,10 +167,10 @@ class TapStrategy extends strategy_1.BaseStrategy {
|
|
|
167
167
|
return 0.05;
|
|
168
168
|
}
|
|
169
169
|
// Human tap durations have moderate CV (~0.3-0.5)
|
|
170
|
-
score += (0,
|
|
170
|
+
score += (0, math_utils_js_1.scoreCoefficientOfVariation)(statistics.cv);
|
|
171
171
|
factors++;
|
|
172
172
|
// Ideal duration: 70-120ms
|
|
173
|
-
score += (0,
|
|
173
|
+
score += (0, math_utils_js_1.gaussian)(statistics.mean, 95, 40);
|
|
174
174
|
factors++;
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -179,7 +179,7 @@ class TapStrategy extends strategy_1.BaseStrategy {
|
|
|
179
179
|
if (movements.length > 0) {
|
|
180
180
|
const avgMovement = movements.reduce((a, b) => a + b, 0) / movements.length;
|
|
181
181
|
// Some movement is natural (1-5px), too much is a swipe, zero is suspicious
|
|
182
|
-
score += (0,
|
|
182
|
+
score += (0, math_utils_js_1.gaussian)(avgMovement, 2, 3);
|
|
183
183
|
factors++;
|
|
184
184
|
}
|
|
185
185
|
// 4. Tap interval timing - Time between taps should vary naturally
|
|
@@ -188,9 +188,9 @@ class TapStrategy extends strategy_1.BaseStrategy {
|
|
|
188
188
|
for (let i = 1; i < this.events.length; i++) {
|
|
189
189
|
intervals.push(this.events[i].timestamp - this.events[i - 1].timestamp);
|
|
190
190
|
}
|
|
191
|
-
const intervalAnalysis = (0,
|
|
191
|
+
const intervalAnalysis = (0, math_utils_js_1.analyzeIntervals)(intervals);
|
|
192
192
|
if (intervalAnalysis && !intervalAnalysis.allIdentical) {
|
|
193
|
-
score += (0,
|
|
193
|
+
score += (0, math_utils_js_1.scoreCoefficientOfVariation)(intervalAnalysis.statistics.cv);
|
|
194
194
|
factors++;
|
|
195
195
|
}
|
|
196
196
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ScoreOptions, ScoreResult } from './types';
|
|
2
|
-
import type { DetectionStrategy, StrategyConfig, TickOptions } from './strategy';
|
|
1
|
+
import type { ScoreOptions, ScoreResult } from './types.js';
|
|
2
|
+
import type { DetectionStrategy, StrategyConfig, TickOptions } from './strategy.js';
|
|
3
3
|
/**
|
|
4
4
|
* Main class for behavior detection
|
|
5
5
|
* Uses modular strategy pattern for tree-shakeable, autonomous detection modules
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser Build (IIFE) - Pure browser bundle without ES module exports
|
|
3
|
+
* Auto-initializing standalone bundle for CDN usage
|
|
4
|
+
*/
|
|
5
|
+
import { BehaviorDetector } from './behavior-detector';
|
|
6
|
+
import { MouseStrategy, ScrollStrategy, ClickStrategy, TapStrategy, KeyboardStrategy, EnvironmentStrategy, ResizeStrategy, } from './strategies/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Detect if the current device is mobile
|
|
9
|
+
*/
|
|
10
|
+
function isMobileDevice() {
|
|
11
|
+
const hasTouchScreen = navigator.maxTouchPoints > 0 || 'ontouchstart' in window;
|
|
12
|
+
const mobileUA = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
13
|
+
const smallScreen = window.innerWidth < 768 && window.innerHeight < 1024;
|
|
14
|
+
return (hasTouchScreen && smallScreen) || mobileUA;
|
|
15
|
+
}
|
|
16
|
+
class BehaviorDetectionAPI {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.detector = null;
|
|
19
|
+
this.checkInterval = null;
|
|
20
|
+
this.settings = null;
|
|
21
|
+
}
|
|
22
|
+
init(settings) {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
24
|
+
if (this.detector) {
|
|
25
|
+
this.stop();
|
|
26
|
+
}
|
|
27
|
+
this.settings = settings;
|
|
28
|
+
this.detector = new BehaviorDetector({
|
|
29
|
+
pauseOnHidden: settings.pauseOnHidden !== undefined ? settings.pauseOnHidden : true
|
|
30
|
+
});
|
|
31
|
+
const isMobile = isMobileDevice();
|
|
32
|
+
const strategies = settings.strategies || {};
|
|
33
|
+
const defaultWeights = isMobile ? {
|
|
34
|
+
mouse: 0,
|
|
35
|
+
scroll: 0.35,
|
|
36
|
+
click: 0,
|
|
37
|
+
tap: 0.35,
|
|
38
|
+
keyboard: 0.15,
|
|
39
|
+
environment: 0.10,
|
|
40
|
+
resize: 0.05,
|
|
41
|
+
} : {
|
|
42
|
+
mouse: 0.30,
|
|
43
|
+
scroll: 0.15,
|
|
44
|
+
click: 0.30,
|
|
45
|
+
tap: 0,
|
|
46
|
+
keyboard: 0.10,
|
|
47
|
+
environment: 0.08,
|
|
48
|
+
resize: 0.02,
|
|
49
|
+
};
|
|
50
|
+
if (!isMobile && ((_a = strategies.mouse) === null || _a === void 0 ? void 0 : _a.enabled) !== false) {
|
|
51
|
+
const strategy = new MouseStrategy();
|
|
52
|
+
const weight = (_c = (_b = strategies.mouse) === null || _b === void 0 ? void 0 : _b.weight) !== null && _c !== void 0 ? _c : defaultWeights.mouse;
|
|
53
|
+
this.detector.addStrategy(strategy, weight);
|
|
54
|
+
}
|
|
55
|
+
if (((_d = strategies.scroll) === null || _d === void 0 ? void 0 : _d.enabled) !== false) {
|
|
56
|
+
const strategy = new ScrollStrategy();
|
|
57
|
+
const weight = (_f = (_e = strategies.scroll) === null || _e === void 0 ? void 0 : _e.weight) !== null && _f !== void 0 ? _f : defaultWeights.scroll;
|
|
58
|
+
this.detector.addStrategy(strategy, weight);
|
|
59
|
+
}
|
|
60
|
+
if (!isMobile && ((_g = strategies.click) === null || _g === void 0 ? void 0 : _g.enabled) !== false) {
|
|
61
|
+
const strategy = new ClickStrategy();
|
|
62
|
+
const weight = (_j = (_h = strategies.click) === null || _h === void 0 ? void 0 : _h.weight) !== null && _j !== void 0 ? _j : defaultWeights.click;
|
|
63
|
+
this.detector.addStrategy(strategy, weight);
|
|
64
|
+
}
|
|
65
|
+
if (isMobile && ((_k = strategies.tap) === null || _k === void 0 ? void 0 : _k.enabled) !== false) {
|
|
66
|
+
const strategy = new TapStrategy();
|
|
67
|
+
const weight = (_m = (_l = strategies.tap) === null || _l === void 0 ? void 0 : _l.weight) !== null && _m !== void 0 ? _m : defaultWeights.tap;
|
|
68
|
+
this.detector.addStrategy(strategy, weight);
|
|
69
|
+
}
|
|
70
|
+
if (((_o = strategies.keyboard) === null || _o === void 0 ? void 0 : _o.enabled) !== false) {
|
|
71
|
+
const strategy = new KeyboardStrategy();
|
|
72
|
+
const weight = (_q = (_p = strategies.keyboard) === null || _p === void 0 ? void 0 : _p.weight) !== null && _q !== void 0 ? _q : defaultWeights.keyboard;
|
|
73
|
+
this.detector.addStrategy(strategy, weight);
|
|
74
|
+
}
|
|
75
|
+
if (((_r = strategies.environment) === null || _r === void 0 ? void 0 : _r.enabled) !== false) {
|
|
76
|
+
const strategy = new EnvironmentStrategy();
|
|
77
|
+
const weight = (_t = (_s = strategies.environment) === null || _s === void 0 ? void 0 : _s.weight) !== null && _t !== void 0 ? _t : defaultWeights.environment;
|
|
78
|
+
this.detector.addStrategy(strategy, weight);
|
|
79
|
+
}
|
|
80
|
+
if (((_u = strategies.resize) === null || _u === void 0 ? void 0 : _u.enabled) !== false) {
|
|
81
|
+
const strategy = new ResizeStrategy();
|
|
82
|
+
const weight = (_w = (_v = strategies.resize) === null || _v === void 0 ? void 0 : _v.weight) !== null && _w !== void 0 ? _w : defaultWeights.resize;
|
|
83
|
+
this.detector.addStrategy(strategy, weight);
|
|
84
|
+
}
|
|
85
|
+
if (settings.autoStart !== false) {
|
|
86
|
+
this.start();
|
|
87
|
+
}
|
|
88
|
+
if (settings.checkMs && settings.checkMs > 0) {
|
|
89
|
+
this.startPeriodicCheck(settings.checkMs);
|
|
90
|
+
}
|
|
91
|
+
if (settings.onReady) {
|
|
92
|
+
settings.onReady(this);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
start() {
|
|
96
|
+
if (!this.detector) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.detector.start();
|
|
100
|
+
}
|
|
101
|
+
stop() {
|
|
102
|
+
if (this.detector) {
|
|
103
|
+
this.detector.stop();
|
|
104
|
+
}
|
|
105
|
+
if (this.checkInterval !== null) {
|
|
106
|
+
clearInterval(this.checkInterval);
|
|
107
|
+
this.checkInterval = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async score() {
|
|
111
|
+
if (!this.detector) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return this.detector.score({ breakdown: true });
|
|
115
|
+
}
|
|
116
|
+
startPeriodicCheck(intervalMs) {
|
|
117
|
+
if (this.checkInterval !== null) {
|
|
118
|
+
clearInterval(this.checkInterval);
|
|
119
|
+
}
|
|
120
|
+
this.checkInterval = window.setInterval(async () => {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
const result = await this.score();
|
|
123
|
+
if (!result || !this.settings)
|
|
124
|
+
return;
|
|
125
|
+
if (this.settings.onScore) {
|
|
126
|
+
this.settings.onScore(result);
|
|
127
|
+
}
|
|
128
|
+
const botThreshold = (_a = this.settings.botThreshold) !== null && _a !== void 0 ? _a : 0.3;
|
|
129
|
+
const humanThreshold = (_b = this.settings.humanThreshold) !== null && _b !== void 0 ? _b : 0.7;
|
|
130
|
+
if (result.score < botThreshold && this.settings.ifBot) {
|
|
131
|
+
this.settings.ifBot(result);
|
|
132
|
+
}
|
|
133
|
+
else if (result.score >= humanThreshold && this.settings.ifHuman) {
|
|
134
|
+
this.settings.ifHuman(result);
|
|
135
|
+
}
|
|
136
|
+
}, intervalMs);
|
|
137
|
+
}
|
|
138
|
+
getDetector() {
|
|
139
|
+
return this.detector;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Create global API instance
|
|
143
|
+
const api = new BehaviorDetectionAPI();
|
|
144
|
+
// Auto-initialize if settings are already present
|
|
145
|
+
if (typeof window !== 'undefined') {
|
|
146
|
+
window.BehaviorDetector = api;
|
|
147
|
+
const checkAndInit = () => {
|
|
148
|
+
const settings = window.bdSettings;
|
|
149
|
+
if (settings) {
|
|
150
|
+
api.init(settings);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
checkAndInit();
|
|
154
|
+
if (document.readyState === 'loading') {
|
|
155
|
+
document.addEventListener('DOMContentLoaded', checkAndInit);
|
|
156
|
+
}
|
|
157
|
+
}
|
package/dist/esm/browser.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
* }
|
|
31
31
|
* </script>
|
|
32
32
|
*/
|
|
33
|
-
import { BehaviorDetector } from './behavior-detector';
|
|
33
|
+
import { BehaviorDetector } from './behavior-detector.js';
|
|
34
34
|
import { MouseStrategy, ScrollStrategy, ClickStrategy, TapStrategy, KeyboardStrategy, EnvironmentStrategy, ResizeStrategy, } from './strategies/index.js';
|
|
35
35
|
/**
|
|
36
36
|
* Detect if the current device is mobile
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
* const result = await detector.score();
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export { BehaviorDetector } from './behavior-detector';
|
|
35
|
-
export type { DetectionStrategy, StrategyConfig } from './strategy';
|
|
34
|
+
export { BehaviorDetector } from './behavior-detector.js';
|
|
35
|
+
export type { DetectionStrategy, StrategyConfig } from './strategy.js';
|
|
36
36
|
export { Mouse, Scroll, Click, Tap, Keyboard, Environment, Resize, MouseStrategy, ScrollStrategy, ClickStrategy, TapStrategy, KeyboardStrategy, EnvironmentStrategy, ResizeStrategy, } from './strategies/index.js';
|
|
37
|
-
export type { BehaviorSettings, ScoreOptions, ScoreResult, ScoreBreakdown, TrackedEvent, EventType, ScoringFunction, } from './types';
|
|
38
|
-
export { DEFAULT_SETTINGS } from './types';
|
|
37
|
+
export type { BehaviorSettings, ScoreOptions, ScoreResult, ScoreBreakdown, TrackedEvent, EventType, ScoringFunction, } from './types.js';
|
|
38
|
+
export { DEFAULT_SETTINGS } from './types.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
* const result = await detector.score();
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export { BehaviorDetector } from './behavior-detector';
|
|
34
|
+
export { BehaviorDetector } from './behavior-detector.js';
|
|
35
35
|
export { Mouse, Scroll, Click, Tap, Keyboard, Environment, Resize, MouseStrategy, ScrollStrategy, ClickStrategy, TapStrategy, KeyboardStrategy, EnvironmentStrategy, ResizeStrategy, } from './strategies/index.js';
|
|
36
|
-
export { DEFAULT_SETTINGS } from './types';
|
|
36
|
+
export { DEFAULT_SETTINGS } from './types.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Click Behavior Detection Strategy
|
|
3
3
|
* Monitors specific elements for click positioning patterns
|
|
4
4
|
*/
|
|
5
|
-
import { BaseStrategy } from '../strategy';
|
|
5
|
+
import { BaseStrategy } from '../strategy.js';
|
|
6
6
|
export declare class ClickStrategy extends BaseStrategy {
|
|
7
7
|
readonly name = "click";
|
|
8
8
|
readonly defaultWeight = 0.3;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Click Behavior Detection Strategy
|
|
3
3
|
* Monitors specific elements for click positioning patterns
|
|
4
4
|
*/
|
|
5
|
-
import { BaseStrategy } from '../strategy';
|
|
5
|
+
import { BaseStrategy } from '../strategy.js';
|
|
6
6
|
export class ClickStrategy extends BaseStrategy {
|
|
7
7
|
constructor(options) {
|
|
8
8
|
super();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Environment Fingerprinting Strategy
|
|
3
3
|
* Captures browser environment on initialization and tick updates
|
|
4
4
|
*/
|
|
5
|
-
import { BaseStrategy } from '../strategy';
|
|
5
|
+
import { BaseStrategy } from '../strategy.js';
|
|
6
6
|
interface EnvironmentData {
|
|
7
7
|
screenWidth: number;
|
|
8
8
|
screenHeight: number;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Environment Fingerprinting Strategy
|
|
3
3
|
* Captures browser environment on initialization and tick updates
|
|
4
4
|
*/
|
|
5
|
-
import { BaseStrategy } from '../strategy';
|
|
6
|
-
import { inverseSigmoid, gaussian } from '../math-utils';
|
|
5
|
+
import { BaseStrategy } from '../strategy.js';
|
|
6
|
+
import { inverseSigmoid, gaussian } from '../math-utils.js';
|
|
7
7
|
export class EnvironmentStrategy extends BaseStrategy {
|
|
8
8
|
constructor() {
|
|
9
9
|
super(...arguments);
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Detection Strategies - Modular behavior analysis
|
|
3
3
|
* Import only what you need for optimal bundle size
|
|
4
4
|
*/
|
|
5
|
-
export { MouseStrategy } from './mouse';
|
|
6
|
-
export { ScrollStrategy } from './scroll';
|
|
7
|
-
export { ClickStrategy } from './click';
|
|
8
|
-
export { TapStrategy } from './tap';
|
|
9
|
-
export { KeyboardStrategy } from './keyboard';
|
|
10
|
-
export { EnvironmentStrategy } from './environment';
|
|
11
|
-
export { ResizeStrategy } from './resize';
|
|
12
|
-
export { MouseStrategy as Mouse } from './mouse';
|
|
13
|
-
export { ScrollStrategy as Scroll } from './scroll';
|
|
14
|
-
export { ClickStrategy as Click } from './click';
|
|
15
|
-
export { TapStrategy as Tap } from './tap';
|
|
16
|
-
export { KeyboardStrategy as Keyboard } from './keyboard';
|
|
17
|
-
export { EnvironmentStrategy as Environment } from './environment';
|
|
18
|
-
export { ResizeStrategy as Resize } from './resize';
|
|
5
|
+
export { MouseStrategy } from './mouse.js';
|
|
6
|
+
export { ScrollStrategy } from './scroll.js';
|
|
7
|
+
export { ClickStrategy } from './click.js';
|
|
8
|
+
export { TapStrategy } from './tap.js';
|
|
9
|
+
export { KeyboardStrategy } from './keyboard.js';
|
|
10
|
+
export { EnvironmentStrategy } from './environment.js';
|
|
11
|
+
export { ResizeStrategy } from './resize.js';
|
|
12
|
+
export { MouseStrategy as Mouse } from './mouse.js';
|
|
13
|
+
export { ScrollStrategy as Scroll } from './scroll.js';
|
|
14
|
+
export { ClickStrategy as Click } from './click.js';
|
|
15
|
+
export { TapStrategy as Tap } from './tap.js';
|
|
16
|
+
export { KeyboardStrategy as Keyboard } from './keyboard.js';
|
|
17
|
+
export { EnvironmentStrategy as Environment } from './environment.js';
|
|
18
|
+
export { ResizeStrategy as Resize } from './resize.js';
|