@naturalcycles/js-lib 14.264.0 → 14.265.1

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 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
  }
@@ -62,7 +64,7 @@ class BotDetectionService {
62
64
  // if (userAgent.includes('Chrome') && !(globalThis as any).chrome) {
63
65
  // return BotReason.ChromeWithoutChrome // Headless Chrome
64
66
  // }
65
- if (this.cfg.treatCDPAsBotReason && this.detectCDP()) {
67
+ if (this.cfg.treatCDPAsBotReason && this.isCDP()) {
66
68
  return BotReason.CDP;
67
69
  }
68
70
  return null;
@@ -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
  }
@@ -59,7 +61,7 @@ export class BotDetectionService {
59
61
  // if (userAgent.includes('Chrome') && !(globalThis as any).chrome) {
60
62
  // return BotReason.ChromeWithoutChrome // Headless Chrome
61
63
  // }
62
- if (this.cfg.treatCDPAsBotReason && this.detectCDP()) {
64
+ if (this.cfg.treatCDPAsBotReason && this.isCDP()) {
63
65
  return BotReason.CDP;
64
66
  }
65
67
  return null;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.264.0",
3
+ "version": "14.265.1",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
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
  }
@@ -89,7 +96,7 @@ export class BotDetectionService {
89
96
  // return BotReason.ChromeWithoutChrome // Headless Chrome
90
97
  // }
91
98
 
92
- if (this.cfg.treatCDPAsBotReason && this.detectCDP()) {
99
+ if (this.cfg.treatCDPAsBotReason && this.isCDP()) {
93
100
  return BotReason.CDP
94
101
  }
95
102
 
@@ -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
  }