is-antibot 1.3.3 → 1.3.4
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/README.md +20 -5
- package/package.json +1 -1
- package/src/index.js +0 -8
package/README.md
CHANGED
|
@@ -59,22 +59,37 @@ $ npm install is-antibot --save
|
|
|
59
59
|
|
|
60
60
|
## Usage
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
Just pass `headers`, `html`, and `url` from any HTTP response:
|
|
63
63
|
|
|
64
64
|
```js
|
|
65
65
|
const isAntibot = require('is-antibot')
|
|
66
66
|
|
|
67
|
-
const response = await fetch('https://
|
|
68
|
-
const
|
|
67
|
+
const response = await fetch('https://www.linkedin.com/in/kikobeats/')
|
|
68
|
+
const html = await response.text()
|
|
69
|
+
|
|
70
|
+
const { detected, provider } = isAntibot({
|
|
71
|
+
headers: response.headers,
|
|
72
|
+
html,
|
|
73
|
+
url: response.url
|
|
74
|
+
})
|
|
69
75
|
|
|
70
76
|
if (detected) {
|
|
71
77
|
console.log(`Antibot detected: ${provider}`)
|
|
72
78
|
}
|
|
73
79
|
```
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
It also works with [got](https://github.com/sindresorhus/got) or any library where `body` is a string:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const response = await got('https://www.linkedin.com/in/kikobeats/')
|
|
85
|
+
.catch(error => errorresponse)
|
|
86
|
+
|
|
87
|
+
const { detected, provider } = isAntibot(response)
|
|
76
88
|
|
|
77
|
-
|
|
89
|
+
if (detected) {
|
|
90
|
+
console.log(`Antibot detected: ${provider}`)
|
|
91
|
+
}
|
|
92
|
+
```
|
|
78
93
|
|
|
79
94
|
The library returns an object with the following properties:
|
|
80
95
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "is-antibot",
|
|
3
3
|
"description": "Identify if a response is an antibot challenge from CloudFlare, Akamai, DataDome, Vercel, PerimeterX, Shape Security, and more, including CAPTCHA providers like reCAPTCHA and hCaptcha.",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/is-antibot",
|
|
5
|
-
"version": "1.3.
|
|
5
|
+
"version": "1.3.4",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./src/index.js"
|
|
8
8
|
},
|
package/src/index.js
CHANGED
|
@@ -387,14 +387,6 @@ const detect = ({ headers = {}, html = '', url = '' } = {}) => {
|
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
const isAntibot = (input = {}) => {
|
|
390
|
-
// Response-like object (e.g., Fetch Response): clone to keep the original body unconsumed
|
|
391
|
-
if (typeof input.text === 'function') {
|
|
392
|
-
return input
|
|
393
|
-
.clone()
|
|
394
|
-
.text()
|
|
395
|
-
.then(html => detect({ headers: input.headers, html, url: input.url }))
|
|
396
|
-
}
|
|
397
|
-
// Plain object: use `html` directly, or fall back to `body` if it's a string (e.g., got response)
|
|
398
390
|
const { headers, html, body, url } = input
|
|
399
391
|
return detect({ headers, html: html || body, url })
|
|
400
392
|
}
|