@naturalcycles/js-lib 14.264.0 → 14.265.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/dist/bot.d.ts +5 -0
- package/dist/bot.js +4 -0
- package/dist-esm/bot.js +4 -0
- package/package.json +1 -1
- package/src/bot.ts +8 -0
package/dist/bot.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export interface BotDetectionServiceCfg {
|
|
2
|
+
/**
|
|
3
|
+
* Defaults to true.
|
|
4
|
+
* Set to false if you need to disable it under certain conditions (e.g in Angular unit tests so it doesn't scream 'Error!')
|
|
5
|
+
*/
|
|
6
|
+
enabled?: boolean;
|
|
2
7
|
/**
|
|
3
8
|
* Defaults to false.
|
|
4
9
|
* If true - the instance will memoize (remember) the results of the detection
|
package/dist/bot.js
CHANGED
|
@@ -25,6 +25,8 @@ class BotDetectionService {
|
|
|
25
25
|
* otherwise a truthy BotReason.
|
|
26
26
|
*/
|
|
27
27
|
getBotReason() {
|
|
28
|
+
if (this.cfg.enabled === false)
|
|
29
|
+
return null;
|
|
28
30
|
if (this.cfg.memoizeResults && this.botReason !== undefined) {
|
|
29
31
|
return this.botReason;
|
|
30
32
|
}
|
|
@@ -81,6 +83,8 @@ class BotDetectionService {
|
|
|
81
83
|
* Based on: https://deviceandbrowserinfo.com/learning_zone/articles/detecting-headless-chrome-puppeteer-2024
|
|
82
84
|
*/
|
|
83
85
|
isCDP() {
|
|
86
|
+
if (this.cfg.enabled === false)
|
|
87
|
+
return false;
|
|
84
88
|
if (this.cfg.memoizeResults && this.cdp !== undefined) {
|
|
85
89
|
return this.cdp;
|
|
86
90
|
}
|
package/dist-esm/bot.js
CHANGED
|
@@ -22,6 +22,8 @@ export class BotDetectionService {
|
|
|
22
22
|
* otherwise a truthy BotReason.
|
|
23
23
|
*/
|
|
24
24
|
getBotReason() {
|
|
25
|
+
if (this.cfg.enabled === false)
|
|
26
|
+
return null;
|
|
25
27
|
if (this.cfg.memoizeResults && this.botReason !== undefined) {
|
|
26
28
|
return this.botReason;
|
|
27
29
|
}
|
|
@@ -78,6 +80,8 @@ export class BotDetectionService {
|
|
|
78
80
|
* Based on: https://deviceandbrowserinfo.com/learning_zone/articles/detecting-headless-chrome-puppeteer-2024
|
|
79
81
|
*/
|
|
80
82
|
isCDP() {
|
|
83
|
+
if (this.cfg.enabled === false)
|
|
84
|
+
return false;
|
|
81
85
|
if (this.cfg.memoizeResults && this.cdp !== undefined) {
|
|
82
86
|
return this.cdp;
|
|
83
87
|
}
|
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
import { isServerSide } from './env'
|
|
5
5
|
|
|
6
6
|
export interface BotDetectionServiceCfg {
|
|
7
|
+
/**
|
|
8
|
+
* Defaults to true.
|
|
9
|
+
* Set to false if you need to disable it under certain conditions (e.g in Angular unit tests so it doesn't scream 'Error!')
|
|
10
|
+
*/
|
|
11
|
+
enabled?: boolean
|
|
12
|
+
|
|
7
13
|
/**
|
|
8
14
|
* Defaults to false.
|
|
9
15
|
* If true - the instance will memoize (remember) the results of the detection
|
|
@@ -47,6 +53,7 @@ export class BotDetectionService {
|
|
|
47
53
|
* otherwise a truthy BotReason.
|
|
48
54
|
*/
|
|
49
55
|
getBotReason(): BotReason | null {
|
|
56
|
+
if (this.cfg.enabled === false) return null
|
|
50
57
|
if (this.cfg.memoizeResults && this.botReason !== undefined) {
|
|
51
58
|
return this.botReason
|
|
52
59
|
}
|
|
@@ -110,6 +117,7 @@ export class BotDetectionService {
|
|
|
110
117
|
* Based on: https://deviceandbrowserinfo.com/learning_zone/articles/detecting-headless-chrome-puppeteer-2024
|
|
111
118
|
*/
|
|
112
119
|
isCDP(): boolean {
|
|
120
|
+
if (this.cfg.enabled === false) return false
|
|
113
121
|
if (this.cfg.memoizeResults && this.cdp !== undefined) {
|
|
114
122
|
return this.cdp
|
|
115
123
|
}
|