@naturalcycles/js-lib 14.262.0 → 14.263.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.js CHANGED
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.BotReason = exports.BotDetectionService = void 0;
6
6
  const env_1 = require("./env");
7
+ const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview/i;
7
8
  /**
8
9
  * Service to detect bots and CDP (Chrome DevTools Protocol).
9
10
  *
@@ -40,7 +41,7 @@ class BotDetectionService {
40
41
  const { userAgent } = navigator;
41
42
  if (!userAgent)
42
43
  return BotReason.NoUserAgent;
43
- if (/bot|headless|electron|phantom|slimer/i.test(userAgent)) {
44
+ if (botRegex.test(userAgent)) {
44
45
  return BotReason.UserAgent;
45
46
  }
46
47
  if (navigator.webdriver) {
package/dist-esm/bot.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // Relevant material:
2
2
  // https://deviceandbrowserinfo.com/learning_zone/articles/detecting-headless-chrome-puppeteer-2024
3
3
  import { isServerSide } from './env';
4
+ const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview/i;
4
5
  /**
5
6
  * Service to detect bots and CDP (Chrome DevTools Protocol).
6
7
  *
@@ -37,7 +38,7 @@ export class BotDetectionService {
37
38
  const { userAgent } = navigator;
38
39
  if (!userAgent)
39
40
  return BotReason.NoUserAgent;
40
- if (/bot|headless|electron|phantom|slimer/i.test(userAgent)) {
41
+ if (botRegex.test(userAgent)) {
41
42
  return BotReason.UserAgent;
42
43
  }
43
44
  if (navigator.webdriver) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.262.0",
3
+ "version": "14.263.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
package/src/bot.ts CHANGED
@@ -19,6 +19,9 @@ export interface BotDetectionServiceCfg {
19
19
  treatCDPAsBotReason?: boolean
20
20
  }
21
21
 
22
+ const botRegex =
23
+ /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview/i
24
+
22
25
  /**
23
26
  * Service to detect bots and CDP (Chrome DevTools Protocol).
24
27
  *
@@ -60,7 +63,7 @@ export class BotDetectionService {
60
63
  const { userAgent } = navigator
61
64
  if (!userAgent) return BotReason.NoUserAgent
62
65
 
63
- if (/bot|headless|electron|phantom|slimer/i.test(userAgent)) {
66
+ if (botRegex.test(userAgent)) {
64
67
  return BotReason.UserAgent
65
68
  }
66
69