wreq-js 1.4.0 → 1.5.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/README.md +45 -228
- package/dist/wreq-js.cjs +1174 -0
- package/dist/wreq-js.cjs.map +1 -0
- package/dist/{types.d.ts → wreq-js.d.cts} +244 -22
- package/dist/wreq-js.d.ts +479 -27
- package/dist/wreq-js.js +1049 -1095
- package/dist/wreq-js.js.map +1 -1
- package/package.json +23 -14
- package/rust/wreq-js.darwin-arm64.node +0 -0
- package/rust/wreq-js.darwin-x64.node +0 -0
- package/rust/wreq-js.linux-arm64-gnu.node +0 -0
- package/rust/wreq-js.linux-x64-gnu.node +0 -0
- package/rust/wreq-js.linux-x64-musl.node +0 -0
- package/rust/wreq-js.win32-x64-msvc.node +0 -0
- package/dist/generated-types.d.ts +0 -13
- package/dist/generated-types.d.ts.map +0 -1
- package/dist/generated-types.js +0 -7
- package/dist/generated-types.js.map +0 -1
- package/dist/test/helpers/http.d.ts +0 -4
- package/dist/test/helpers/http.d.ts.map +0 -1
- package/dist/test/helpers/http.js +0 -14
- package/dist/test/helpers/http.js.map +0 -1
- package/dist/test/helpers/local-test-server.d.ts +0 -7
- package/dist/test/helpers/local-test-server.d.ts.map +0 -1
- package/dist/test/helpers/local-test-server.js +0 -406
- package/dist/test/helpers/local-test-server.js.map +0 -1
- package/dist/test/http/errors.spec.d.ts +0 -2
- package/dist/test/http/errors.spec.d.ts.map +0 -1
- package/dist/test/http/errors.spec.js +0 -33
- package/dist/test/http/errors.spec.js.map +0 -1
- package/dist/test/http/headers.spec.d.ts +0 -2
- package/dist/test/http/headers.spec.d.ts.map +0 -1
- package/dist/test/http/headers.spec.js +0 -98
- package/dist/test/http/headers.spec.js.map +0 -1
- package/dist/test/http/insecure.spec.d.ts +0 -2
- package/dist/test/http/insecure.spec.d.ts.map +0 -1
- package/dist/test/http/insecure.spec.js +0 -126
- package/dist/test/http/insecure.spec.js.map +0 -1
- package/dist/test/http/profiles.spec.d.ts +0 -2
- package/dist/test/http/profiles.spec.d.ts.map +0 -1
- package/dist/test/http/profiles.spec.js +0 -28
- package/dist/test/http/profiles.spec.js.map +0 -1
- package/dist/test/http/requests.spec.d.ts +0 -2
- package/dist/test/http/requests.spec.d.ts.map +0 -1
- package/dist/test/http/requests.spec.js +0 -198
- package/dist/test/http/requests.spec.js.map +0 -1
- package/dist/test/http/sessions.spec.d.ts +0 -2
- package/dist/test/http/sessions.spec.d.ts.map +0 -1
- package/dist/test/http/sessions.spec.js +0 -68
- package/dist/test/http/sessions.spec.js.map +0 -1
- package/dist/test/run-with-local-server.d.ts +0 -2
- package/dist/test/run-with-local-server.d.ts.map +0 -1
- package/dist/test/run-with-local-server.js +0 -71
- package/dist/test/run-with-local-server.js.map +0 -1
- package/dist/test/websocket.spec.d.ts +0 -2
- package/dist/test/websocket.spec.d.ts.map +0 -1
- package/dist/test/websocket.spec.js +0 -122
- package/dist/test/websocket.spec.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -26
- package/dist/types.js.map +0 -1
- package/dist/wreq-js.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
# wreq-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/wreq-js)
|
|
4
|
+
[](https://github.com/sqdshguy/wreq-js/actions/workflows/test.yml)
|
|
5
|
+
[](https://deepwiki.com/sqdshguy/wreq-js)
|
|
4
6
|
|
|
5
|
-
-
|
|
6
|
-
- When it comes to web scraping and automation, keeping up with the latest developments is NOT optional. Detection systems like Akamai and Cloudflare change every day using machine learning, old fingerprints are quickly detected.
|
|
7
|
-
- `wreq-js` builds upon the Rust-based [`wreq`](https://github.com/0x676e67/wreq) engine to deliver drop-in Node.js bindings that feel like `fetch()` but behave like a real browser.
|
|
7
|
+
High-performance HTTP client for Node.js with real-browser TLS and HTTP/2 fingerprints, powered by Rust.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- Native performance (no browser/process spawning)
|
|
10
|
+
- Real browser TLS fingerprints (JA3/JA4)
|
|
11
|
+
- HTTP/2 impersonation (SETTINGS/PRIORITY/header ordering)
|
|
12
|
+
- Multiple browser profiles (Chrome/Firefox/Safari/Edge/Opera/OkHttp)
|
|
13
|
+
- WebSocket support with fingerprint consistency
|
|
14
|
+
- Prebuilt native binaries for macOS/Linux/Windows
|
|
15
|
+
- TypeScript-ready with generated definitions
|
|
10
16
|
|
|
11
|
-
##
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
All guides, concepts, and API reference live at:
|
|
20
|
+
|
|
21
|
+
- https://wreq.sqdsh.win
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
- **Real browser TLS fingerprints** (JA3/JA4)
|
|
15
|
-
- **HTTP/2 impersonation** — replicates SETTINGS, PRIORITY, and header ordering
|
|
16
|
-
- **Multiple browser profiles** — Chrome, Firefox, Safari, Edge, Opera, OkHttp
|
|
17
|
-
- **WebSocket support** with browser fingerprint consistency
|
|
18
|
-
- **Prebuilt native binaries** for macOS, Linux, and Windows
|
|
19
|
-
- **TypeScript-ready** with generated definitions
|
|
23
|
+
(If you're looking for examples, sessions/cookies, proxy usage, streaming, WebSockets, or the full API surface - it's all there.)
|
|
20
24
|
|
|
21
25
|
## Installation
|
|
22
26
|
|
|
@@ -33,244 +37,57 @@ Prebuilt binaries are provided for:
|
|
|
33
37
|
- Linux (x64 & ARM64, glibc & musl)
|
|
34
38
|
- Windows (x64)
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
> Make sure a Rust toolchain and required build dependencies are installed.
|
|
38
|
-
|
|
39
|
-
## Why It Exists
|
|
40
|
-
|
|
41
|
-
HTTP clients like `axios`, `fetch`, `got`, `curl` do not behave like browsers on the network layer.
|
|
42
|
-
They differ in:
|
|
43
|
-
|
|
44
|
-
- **TLS handshake** - unique cipher suite order and extension sets
|
|
45
|
-
- **HTTP/2 frames** - different SETTINGS and PRIORITY sequences
|
|
46
|
-
- **Header ordering** - deterministic but non-browser-compliant
|
|
47
|
-
|
|
48
|
-
These subtle differences are enough for modern detection systems to identify automation.
|
|
49
|
-
`wreq-js` reproduces browser networking behavior using the `wreq` Rust engine underneath.
|
|
50
|
-
Your job is to write scripts, ours is to make them undetectable, yet effortless.
|
|
51
|
-
|
|
52
|
-
## Architecture Overview
|
|
53
|
-
|
|
54
|
-
`wreq-js` provides Node.js bindings over [`wreq`](https://github.com/0x676e67/wreq), a Rust HTTP client built on **BoringSSL** to emulate browser TLS and HTTP/2 stacks.
|
|
55
|
-
Browser profiles are defined in the upstream [`wreq-util`](https://github.com/0x676e67/wreq-util) project and automatically synchronized here for faster updates.
|
|
56
|
-
|
|
57
|
-
To query supported profiles:
|
|
40
|
+
If a prebuilt binary for your platform/commit is unavailable, the package will build from source (requires a Rust toolchain).
|
|
58
41
|
|
|
59
|
-
|
|
60
|
-
import { getProfiles } from 'wreq-js';
|
|
61
|
-
console.log(getProfiles());
|
|
62
|
-
// ['chrome_142', 'firefox_139', 'edge_120', 'safari_18', ...]
|
|
42
|
+
## Quick start
|
|
63
43
|
|
|
64
|
-
|
|
65
|
-
console.log(getOperatingSystems());
|
|
66
|
-
// ['windows', 'macos', 'linux', 'android', 'ios']
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Quick Start
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
44
|
+
```ts
|
|
72
45
|
import { fetch } from 'wreq-js';
|
|
73
46
|
|
|
74
|
-
const
|
|
47
|
+
const res = await fetch('https://example.com/api', {
|
|
75
48
|
browser: 'chrome_142',
|
|
76
|
-
os: 'windows',
|
|
49
|
+
os: 'windows',
|
|
77
50
|
});
|
|
78
51
|
|
|
79
|
-
console.log(await
|
|
52
|
+
console.log(await res.json());
|
|
80
53
|
```
|
|
81
54
|
|
|
82
|
-
|
|
55
|
+
## Use sessions (recommended)
|
|
83
56
|
|
|
84
|
-
|
|
57
|
+
For **most real-world workloads**, start with a session and reuse it across requests.
|
|
58
|
+
This keeps TLS/cookies warm and avoids paying setup costs on every call.
|
|
85
59
|
|
|
86
|
-
|
|
60
|
+
```ts
|
|
61
|
+
import { createSession } from 'wreq-js';
|
|
87
62
|
|
|
88
|
-
|
|
89
|
-
import { fetch, Headers } from 'wreq-js';
|
|
63
|
+
const session = await createSession({ browser: 'chrome_142', os: 'windows' });
|
|
90
64
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
By default, browser emulation headers (like `Accept`, `Accept-Language`, `User-Agent`, etc.) are automatically added and may be appended to your custom headers. To prevent this and use **only** your custom headers:
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
const response = await fetch('https://api.example.com/data', {
|
|
104
|
-
browser: 'chrome_142',
|
|
105
|
-
headers: {
|
|
106
|
-
'Accept': '*/*',
|
|
107
|
-
'User-Agent': 'CustomBot/1.0',
|
|
108
|
-
},
|
|
109
|
-
disableDefaultHeaders: true, // Disable emulation headers
|
|
110
|
-
});
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### POST Request
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
const res = await fetch('https://api.example.com/submit', {
|
|
117
|
-
method: 'POST',
|
|
118
|
-
browser: 'chrome_142',
|
|
119
|
-
headers: { 'Content-Type': 'application/json' },
|
|
120
|
-
body: JSON.stringify({ foo: 'bar' }),
|
|
121
|
-
});
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Disabling Certificate Verification
|
|
125
|
-
|
|
126
|
-
For development or testing against servers with self-signed or expired certificates, you can disable certificate verification:
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
const response = await fetch('https://self-signed.example.com', {
|
|
130
|
-
browser: 'chrome_142',
|
|
131
|
-
insecure: true, // Accept invalid/self-signed certificates
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
**⚠️ Security Warning:** Only use `insecure: true` in development or controlled testing environments. When enabled, **any** certificate for **any** site will be trusted, including expired and self-signed certificates. This introduces significant security vulnerabilities and should never be used in production.
|
|
136
|
-
|
|
137
|
-
The `insecure` option works with both direct `fetch()` calls and sessions:
|
|
138
|
-
|
|
139
|
-
```typescript
|
|
140
|
-
// Per-request
|
|
141
|
-
await fetch('https://localhost:8443', { insecure: true });
|
|
142
|
-
|
|
143
|
-
// For all requests in a session
|
|
144
|
-
const session = await createSession({
|
|
145
|
-
browser: 'chrome_142',
|
|
146
|
-
insecure: true, // All requests in this session accept invalid certificates
|
|
147
|
-
});
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### Streaming Responses
|
|
151
|
-
|
|
152
|
-
The `Response` object supports streaming via the standard `body` property, which returns a `ReadableStream<Uint8Array>`. This allows you to process large responses incrementally without loading the entire body into memory.
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
const response = await fetch('https://example.com/large-file', {
|
|
156
|
-
browser: 'chrome_142',
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Access the body stream
|
|
160
|
-
const stream = response.body;
|
|
161
|
-
if (stream) {
|
|
162
|
-
const reader = stream.getReader();
|
|
163
|
-
|
|
164
|
-
while (true) {
|
|
165
|
-
const { done, value } = await reader.read();
|
|
166
|
-
|
|
167
|
-
if (done) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Process chunk (value is Uint8Array)
|
|
172
|
-
console.log(`Received ${value.byteLength} bytes`);
|
|
173
|
-
}
|
|
65
|
+
try {
|
|
66
|
+
const a = await session.fetch('https://example.com/a');
|
|
67
|
+
const b = await session.fetch('https://example.com/b');
|
|
68
|
+
console.log(a.status, b.status);
|
|
69
|
+
} finally {
|
|
70
|
+
await session.close();
|
|
174
71
|
}
|
|
175
72
|
```
|
|
176
73
|
|
|
177
|
-
|
|
178
|
-
- The `body` property is lazily initialized - it returns `null` for empty responses or a `ReadableStream` for non-empty responses
|
|
179
|
-
- Accessing `response.body` does **not** mark it as consumed - only reading from the stream does
|
|
180
|
-
- The `bodyUsed` flag becomes `true` only when you start reading from the stream
|
|
181
|
-
- You can call `response.clone()` to create a duplicate response before the body is consumed
|
|
182
|
-
- Once consumed via `json()`, `text()`, `arrayBuffer()`, or stream reading, the body cannot be read again
|
|
183
|
-
|
|
184
|
-
## Session & Cookie Isolation
|
|
185
|
-
|
|
186
|
-
Each `fetch()` call runs in **ephemeral mode** so that TLS caches, cookies, and session data never leak across requests.
|
|
187
|
-
To persist state, use `createSession()` or `withSession()`:
|
|
188
|
-
|
|
189
|
-
```typescript
|
|
190
|
-
import { createSession, withSession } from 'wreq-js';
|
|
191
|
-
|
|
192
|
-
const session = await createSession({ browser: 'chrome_142' });
|
|
193
|
-
await session.fetch('https://example.com/login', { method: 'POST', body: '...' });
|
|
194
|
-
await session.fetch('https://example.com/dashboard');
|
|
195
|
-
await session.close();
|
|
196
|
-
|
|
197
|
-
// Auto-disposing helper
|
|
198
|
-
await withSession(async (s) => {
|
|
199
|
-
await s.fetch('https://example.com/a');
|
|
200
|
-
await s.fetch('https://example.com/b');
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
For finer control:
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
await fetch('https://example.com', {
|
|
207
|
-
sessionId: 'user-42',
|
|
208
|
-
cookieMode: 'session',
|
|
209
|
-
});
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## WebSocket Example
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
import { websocket } from 'wreq-js';
|
|
216
|
-
|
|
217
|
-
const ws = await websocket({
|
|
218
|
-
url: 'wss://echo.websocket.org',
|
|
219
|
-
browser: 'chrome_142',
|
|
220
|
-
onMessage: (data) => console.log('Received:', data),
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
await ws.send('Hello!');
|
|
224
|
-
await ws.close();
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## API Reference
|
|
228
|
-
|
|
229
|
-
The API is aiming to be `fetch`-compatible, with a few `wreq`-specific extensions.
|
|
230
|
-
See inline TypeScript definitions for complete typings.
|
|
74
|
+
More session patterns: https://wreq.sqdsh.win
|
|
231
75
|
|
|
232
|
-
|
|
233
|
-
interface RequestInit {
|
|
234
|
-
method?: string;
|
|
235
|
-
headers?: HeadersInit;
|
|
236
|
-
body?: BodyInit | null;
|
|
237
|
-
signal?: AbortSignal | null;
|
|
238
|
-
redirect?: 'follow';
|
|
239
|
-
browser?: BrowserProfile;
|
|
240
|
-
proxy?: string;
|
|
241
|
-
timeout?: number;
|
|
242
|
-
cookieMode?: 'session' | 'ephemeral';
|
|
243
|
-
session?: Session;
|
|
244
|
-
sessionId?: string;
|
|
245
|
-
disableDefaultHeaders?: boolean; // Prevent emulation headers from being appended
|
|
246
|
-
insecure?: boolean; // Disable certificate verification (use with caution)
|
|
247
|
-
}
|
|
76
|
+
## When to use
|
|
248
77
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
os?: EmulationOS;
|
|
252
|
-
proxy?: string;
|
|
253
|
-
sessionId?: string;
|
|
254
|
-
timeout?: number;
|
|
255
|
-
insecure?: boolean; // Disable certificate verification for all session requests
|
|
256
|
-
}
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
## Documentation
|
|
260
|
-
|
|
261
|
-
- **[Architecture Guide](docs/ARCHITECTURE.md)** - How fingerprinting and impersonation work
|
|
262
|
-
- **[Build Instructions](docs/BUILD.md)** - Build from source
|
|
78
|
+
Use `wreq-js` when you need `fetch()`-style ergonomics but want the network layer to look like a real browser.
|
|
79
|
+
If you need DOM/JS execution, CAPTCHA solving, or full browser automation, use Playwright/Puppeteer instead.
|
|
263
80
|
|
|
264
81
|
## Contributing
|
|
265
82
|
|
|
266
|
-
|
|
83
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
267
84
|
|
|
268
85
|
## Origins
|
|
269
|
-
|
|
86
|
+
|
|
87
|
+
This is a maintained fork of [will-work-for-meal/node-wreq](https://github.com/will-work-for-meal/node-wreq) (originally named `node-wreq`), with ongoing updates, compatibility fixes, and performance work.
|
|
270
88
|
|
|
271
89
|
## Acknowledgments
|
|
272
90
|
|
|
273
|
-
- [wreq](https://github.com/0x676e67/wreq) - Rust HTTP client with browser impersonation
|
|
274
|
-
- [wreq-util](https://github.com/0x676e67/wreq-util) -
|
|
275
|
-
- [Neon](https://neon-bindings.com/) - Rust ↔ Node.js bindings
|
|
276
|
-
- [will-work-for-meal/node-wreq](https://github.com/will-work-for-meal/node-wreq) - Original Node.js wrapper foundation
|
|
91
|
+
- [wreq](https://github.com/0x676e67/wreq) - Rust HTTP client with browser impersonation
|
|
92
|
+
- [wreq-util](https://github.com/0x676e67/wreq-util) - source of up-to-date browser profiles
|
|
93
|
+
- [Neon](https://neon-bindings.com/) - Rust ↔ Node.js bindings
|