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/dist/wreq-js.d.ts
CHANGED
|
@@ -1,6 +1,457 @@
|
|
|
1
|
-
import { ReadableStream } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ReadableStream } from 'node:stream/web';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Auto-generated from Rust build script
|
|
5
|
+
* DO NOT EDIT MANUALLY
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Browser profile names supported
|
|
9
|
+
*/
|
|
10
|
+
type BrowserProfile = 'chrome_100' | 'chrome_101' | 'chrome_104' | 'chrome_105' | 'chrome_106' | 'chrome_107' | 'chrome_108' | 'chrome_109' | 'chrome_110' | 'chrome_114' | 'chrome_116' | 'chrome_117' | 'chrome_118' | 'chrome_119' | 'chrome_120' | 'chrome_123' | 'chrome_124' | 'chrome_126' | 'chrome_127' | 'chrome_128' | 'chrome_129' | 'chrome_130' | 'chrome_131' | 'chrome_132' | 'chrome_133' | 'chrome_134' | 'chrome_135' | 'chrome_136' | 'chrome_137' | 'chrome_138' | 'chrome_139' | 'chrome_140' | 'chrome_141' | 'chrome_142' | 'chrome_143' | 'edge_101' | 'edge_122' | 'edge_127' | 'edge_131' | 'edge_134' | 'edge_135' | 'edge_136' | 'edge_137' | 'edge_138' | 'edge_139' | 'edge_140' | 'edge_141' | 'edge_142' | 'opera_116' | 'opera_117' | 'opera_118' | 'opera_119' | 'safari_ios_17.2' | 'safari_ios_17.4.1' | 'safari_ios_16.5' | 'safari_15.3' | 'safari_15.5' | 'safari_15.6.1' | 'safari_16' | 'safari_16.5' | 'safari_17.0' | 'safari_17.2.1' | 'safari_17.4.1' | 'safari_17.5' | 'safari_17.6' | 'safari_18' | 'safari_ipad_18' | 'safari_18.2' | 'safari_ios_18.1.1' | 'safari_18.3' | 'safari_18.3.1' | 'safari_18.5' | 'safari_26' | 'safari_26.1' | 'safari_26.2' | 'safari_ipad_26' | 'safari_ipad_26.2' | 'safari_ios_26' | 'safari_ios_26.2' | 'firefox_109' | 'firefox_117' | 'firefox_128' | 'firefox_133' | 'firefox_135' | 'firefox_private_135' | 'firefox_android_135' | 'firefox_136' | 'firefox_private_136' | 'firefox_139' | 'firefox_142' | 'firefox_143' | 'firefox_144' | 'firefox_145' | 'okhttp_3.9' | 'okhttp_3.11' | 'okhttp_3.13' | 'okhttp_3.14' | 'okhttp_4.9' | 'okhttp_4.10' | 'okhttp_4.12' | 'okhttp_5';
|
|
11
|
+
/**
|
|
12
|
+
* Operating systems supported for emulation
|
|
13
|
+
*/
|
|
14
|
+
type EmulationOS = 'windows' | 'macos' | 'linux' | 'android' | 'ios';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Controls how cookies are scoped for a request.
|
|
18
|
+
* - "session": reuse an explicit Session or sessionId across calls.
|
|
19
|
+
* - "ephemeral": create an isolated, single-use session.
|
|
20
|
+
*/
|
|
21
|
+
type CookieMode = "session" | "ephemeral";
|
|
22
|
+
/**
|
|
23
|
+
* Minimal handle implemented by {@link Session}. Exposed for integrations
|
|
24
|
+
* that only need to carry a session id.
|
|
25
|
+
*/
|
|
26
|
+
interface SessionHandle {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A tuple of [name, value] pairs used for initializing headers.
|
|
31
|
+
* Both name and value must be strings.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const headers: HeaderTuple = ['Content-Type', 'application/json'];
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
type HeaderTuple = [string, string];
|
|
39
|
+
/**
|
|
40
|
+
* Represents various input types accepted when creating or initializing headers.
|
|
41
|
+
* Can be an iterable of header tuples, an array of tuples, or a plain object.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // As an object
|
|
46
|
+
* const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
47
|
+
*
|
|
48
|
+
* // As an array of tuples
|
|
49
|
+
* const headers: HeadersInit = [['Content-Type', 'application/json']];
|
|
50
|
+
*
|
|
51
|
+
* // As an iterable
|
|
52
|
+
* const headers: HeadersInit = new Map([['Content-Type', 'application/json']]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
type HeadersInit = Iterable<HeaderTuple> | Array<HeaderTuple> | Record<string, string | number | boolean | null | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Represents the various types of data that can be used as a request body.
|
|
58
|
+
* Supports string, binary data (ArrayBuffer, ArrayBufferView), URL-encoded parameters, and Node.js Buffer.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // String body
|
|
63
|
+
* const body: BodyInit = JSON.stringify({ key: 'value' });
|
|
64
|
+
*
|
|
65
|
+
* // URLSearchParams
|
|
66
|
+
* const body: BodyInit = new URLSearchParams({ key: 'value' });
|
|
67
|
+
*
|
|
68
|
+
* // Buffer
|
|
69
|
+
* const body: BodyInit = Buffer.from('data');
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
type BodyInit = string | ArrayBuffer | ArrayBufferView | URLSearchParams | Buffer;
|
|
73
|
+
/**
|
|
74
|
+
* Options for configuring a fetch request. Compatible with the standard Fetch API
|
|
75
|
+
* with additional wreq-specific extensions for browser impersonation, proxies, and timeouts.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const options: RequestInit = {
|
|
80
|
+
* method: 'POST',
|
|
81
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
82
|
+
* body: JSON.stringify({ key: 'value' }),
|
|
83
|
+
* browser: 'chrome_142',
|
|
84
|
+
* proxy: 'http://proxy.example.com:8080',
|
|
85
|
+
* timeout: 5000
|
|
86
|
+
* };
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
interface RequestInit {
|
|
90
|
+
/**
|
|
91
|
+
* A string to set request's method.
|
|
92
|
+
* @default 'GET'
|
|
93
|
+
*/
|
|
94
|
+
method?: string;
|
|
95
|
+
/**
|
|
96
|
+
* A Headers object, an object literal, or an array of two-item arrays to set request's headers.
|
|
97
|
+
*/
|
|
98
|
+
headers?: HeadersInit;
|
|
99
|
+
/**
|
|
100
|
+
* A BodyInit object or null to set request's body.
|
|
101
|
+
*/
|
|
102
|
+
body?: BodyInit | null;
|
|
103
|
+
/**
|
|
104
|
+
* An AbortSignal to set request's signal.
|
|
105
|
+
*/
|
|
106
|
+
signal?: AbortSignal | null;
|
|
107
|
+
/**
|
|
108
|
+
* A string indicating whether request follows redirects, results in an error upon
|
|
109
|
+
* encountering a redirect, or returns the redirect (in an opaque fashion).
|
|
110
|
+
* @default 'follow'
|
|
111
|
+
*/
|
|
112
|
+
redirect?: "follow" | "manual" | "error";
|
|
113
|
+
/**
|
|
114
|
+
* Browser profile to impersonate for this request.
|
|
115
|
+
* Automatically applies browser-specific headers, TLS fingerprints, and HTTP/2 settings.
|
|
116
|
+
* @default 'chrome_142'
|
|
117
|
+
*/
|
|
118
|
+
browser?: BrowserProfile;
|
|
119
|
+
/**
|
|
120
|
+
* Operating system to emulate for this request.
|
|
121
|
+
* Influences platform-specific headers and TLS fingerprints.
|
|
122
|
+
* @default 'macos'
|
|
123
|
+
*/
|
|
124
|
+
os?: EmulationOS;
|
|
125
|
+
/**
|
|
126
|
+
* Proxy URL to route the request through (e.g., 'http://proxy.example.com:8080').
|
|
127
|
+
* Supports HTTP and SOCKS5 proxies.
|
|
128
|
+
*/
|
|
129
|
+
proxy?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Request timeout in milliseconds. If the request takes longer than this value,
|
|
132
|
+
* it will be aborted.
|
|
133
|
+
* @default 30000
|
|
134
|
+
*/
|
|
135
|
+
timeout?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Controls how cookies are managed for this call.
|
|
138
|
+
* - "ephemeral": default when no session/sessionId is provided. Creates an isolated session per request.
|
|
139
|
+
* - "session": requires an explicit session or sessionId and reuses its cookie jar.
|
|
140
|
+
*/
|
|
141
|
+
cookieMode?: CookieMode;
|
|
142
|
+
/**
|
|
143
|
+
* Session instance to bind this request to. When provided, {@link cookieMode}
|
|
144
|
+
* automatically behaves like `"session"`.
|
|
145
|
+
*/
|
|
146
|
+
session?: Session;
|
|
147
|
+
/**
|
|
148
|
+
* Identifier of an existing session created elsewhere (e.g., via {@link createSession}).
|
|
149
|
+
*/
|
|
150
|
+
sessionId?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Disable default headers from browser emulation. When enabled, only explicitly
|
|
153
|
+
* provided headers will be sent with the request, preventing emulation headers
|
|
154
|
+
* from being automatically added or appended.
|
|
155
|
+
* @default false
|
|
156
|
+
*/
|
|
157
|
+
disableDefaultHeaders?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Disable HTTPS certificate verification. When enabled, self-signed and invalid
|
|
160
|
+
* certificates will be accepted.
|
|
161
|
+
*
|
|
162
|
+
* # Warning
|
|
163
|
+
*
|
|
164
|
+
* You should think very carefully before using this method. If invalid
|
|
165
|
+
* certificates are trusted, *any* certificate for *any* site will be
|
|
166
|
+
* trusted for use. This includes expired certificates. This introduces
|
|
167
|
+
* significant vulnerabilities, and should only be used as a last resort.
|
|
168
|
+
*
|
|
169
|
+
* @default false
|
|
170
|
+
*/
|
|
171
|
+
insecure?: boolean;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Configuration for {@link createSession}.
|
|
175
|
+
*/
|
|
176
|
+
interface CreateSessionOptions {
|
|
177
|
+
/**
|
|
178
|
+
* Provide a custom identifier instead of an auto-generated random ID.
|
|
179
|
+
*/
|
|
180
|
+
sessionId?: string;
|
|
181
|
+
/**
|
|
182
|
+
* Browser profile to bind to this session. Defaults to 'chrome_142'.
|
|
183
|
+
*/
|
|
184
|
+
browser?: BrowserProfile;
|
|
185
|
+
/**
|
|
186
|
+
* Operating system to bind to this session. Defaults to 'macos'.
|
|
187
|
+
*/
|
|
188
|
+
os?: EmulationOS;
|
|
189
|
+
/**
|
|
190
|
+
* Optional proxy for every request made through the session.
|
|
191
|
+
*/
|
|
192
|
+
proxy?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Default timeout applied when {@link Session.fetch} is called without
|
|
195
|
+
* overriding `timeout`.
|
|
196
|
+
*/
|
|
197
|
+
timeout?: number;
|
|
198
|
+
/**
|
|
199
|
+
* Disable HTTPS certificate verification. When enabled, self-signed and invalid
|
|
200
|
+
* certificates will be accepted for all requests made through this session.
|
|
201
|
+
*
|
|
202
|
+
* # Warning
|
|
203
|
+
*
|
|
204
|
+
* You should think very carefully before using this method. If invalid
|
|
205
|
+
* certificates are trusted, *any* certificate for *any* site will be
|
|
206
|
+
* trusted for use. This includes expired certificates. This introduces
|
|
207
|
+
* significant vulnerabilities, and should only be used as a last resort.
|
|
208
|
+
*
|
|
209
|
+
* @default false
|
|
210
|
+
*/
|
|
211
|
+
insecure?: boolean;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Legacy request options interface. This interface is deprecated and will be removed in a future version.
|
|
215
|
+
*
|
|
216
|
+
* @deprecated Use {@link RequestInit} with the standard `fetch()` API instead.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* // Old (deprecated):
|
|
221
|
+
* const options: RequestOptions = {
|
|
222
|
+
* url: 'https://api.example.com',
|
|
223
|
+
* method: 'POST',
|
|
224
|
+
* body: JSON.stringify({ data: 'value' })
|
|
225
|
+
* };
|
|
226
|
+
*
|
|
227
|
+
* // New (recommended):
|
|
228
|
+
* const response = await fetch('https://api.example.com', {
|
|
229
|
+
* method: 'POST',
|
|
230
|
+
* body: JSON.stringify({ data: 'value' })
|
|
231
|
+
* });
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
interface RequestOptions {
|
|
235
|
+
/**
|
|
236
|
+
* The URL to request.
|
|
237
|
+
*/
|
|
238
|
+
url: string;
|
|
239
|
+
/**
|
|
240
|
+
* Browser profile to impersonate.
|
|
241
|
+
* Automatically applies browser-specific headers, TLS fingerprints, and HTTP/2 settings.
|
|
242
|
+
* @default 'chrome_142'
|
|
243
|
+
*/
|
|
244
|
+
browser?: BrowserProfile;
|
|
245
|
+
/**
|
|
246
|
+
* Operating system to emulate.
|
|
247
|
+
* @default 'macos'
|
|
248
|
+
*/
|
|
249
|
+
os?: EmulationOS;
|
|
250
|
+
/**
|
|
251
|
+
* HTTP method to use for the request.
|
|
252
|
+
* @default 'GET'
|
|
253
|
+
*/
|
|
254
|
+
method?: string;
|
|
255
|
+
/**
|
|
256
|
+
* Additional headers to send with the request.
|
|
257
|
+
* Browser-specific headers will be automatically added based on the selected browser profile.
|
|
258
|
+
*/
|
|
259
|
+
headers?: Record<string, string> | HeaderTuple[];
|
|
260
|
+
/**
|
|
261
|
+
* Request body data (for POST, PUT, PATCH requests).
|
|
262
|
+
*/
|
|
263
|
+
body?: Buffer;
|
|
264
|
+
/**
|
|
265
|
+
* Proxy URL to route the request through (e.g., 'http://proxy.example.com:8080').
|
|
266
|
+
* Supports HTTP and SOCKS5 proxies.
|
|
267
|
+
*/
|
|
268
|
+
proxy?: string;
|
|
269
|
+
/**
|
|
270
|
+
* Redirect policy applied to this request. Matches the `redirect` option accepted by {@link fetch}.
|
|
271
|
+
* @default "follow"
|
|
272
|
+
*/
|
|
273
|
+
redirect?: "follow" | "manual" | "error";
|
|
274
|
+
/**
|
|
275
|
+
* Request timeout in milliseconds. If the request takes longer than this value,
|
|
276
|
+
* it will be aborted.
|
|
277
|
+
* @default 30000
|
|
278
|
+
*/
|
|
279
|
+
timeout?: number;
|
|
280
|
+
/**
|
|
281
|
+
* Identifier for the session that should handle this request.
|
|
282
|
+
* @internal
|
|
283
|
+
*/
|
|
284
|
+
sessionId?: string;
|
|
285
|
+
/**
|
|
286
|
+
* Internal flag indicating whether the session should be discarded once the
|
|
287
|
+
* request finishes.
|
|
288
|
+
* @internal
|
|
289
|
+
*/
|
|
290
|
+
ephemeral?: boolean;
|
|
291
|
+
/**
|
|
292
|
+
* Disable default headers from browser emulation. When enabled, only explicitly
|
|
293
|
+
* provided headers will be sent with the request, preventing emulation headers
|
|
294
|
+
* from being automatically added or appended.
|
|
295
|
+
* @default false
|
|
296
|
+
*/
|
|
297
|
+
disableDefaultHeaders?: boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Disable HTTPS certificate verification. When enabled, self-signed and invalid
|
|
300
|
+
* certificates will be accepted.
|
|
301
|
+
*
|
|
302
|
+
* # Warning
|
|
303
|
+
*
|
|
304
|
+
* You should think very carefully before using this method. If invalid
|
|
305
|
+
* certificates are trusted, *any* certificate for *any* site will be
|
|
306
|
+
* trusted for use. This includes expired certificates. This introduces
|
|
307
|
+
* significant vulnerabilities, and should only be used as a last resort.
|
|
308
|
+
*
|
|
309
|
+
* @default false
|
|
310
|
+
*/
|
|
311
|
+
insecure?: boolean;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Internal response payload returned from the native Rust binding.
|
|
315
|
+
* This interface represents the raw response data before it's converted
|
|
316
|
+
* to a standard Response object.
|
|
317
|
+
*
|
|
318
|
+
* @internal
|
|
319
|
+
*/
|
|
320
|
+
interface NativeResponse {
|
|
321
|
+
/**
|
|
322
|
+
* HTTP status code (e.g., 200, 404, 500).
|
|
323
|
+
*/
|
|
324
|
+
status: number;
|
|
325
|
+
/**
|
|
326
|
+
* Response headers as [name, value] tuples.
|
|
327
|
+
* Header names are normalized to lowercase.
|
|
328
|
+
*/
|
|
329
|
+
headers: HeaderTuple[];
|
|
330
|
+
/**
|
|
331
|
+
* Handle for streaming response body chunks from the native layer.
|
|
332
|
+
* When `null`, the response does not have a body (e.g., HEAD/204/304).
|
|
333
|
+
*/
|
|
334
|
+
bodyHandle: number | null;
|
|
335
|
+
/**
|
|
336
|
+
* Inline body buffer returned for small payloads. When present, `bodyHandle`
|
|
337
|
+
* will be `null` to avoid a second native round-trip to read the body.
|
|
338
|
+
*/
|
|
339
|
+
bodyBytes: Buffer | null;
|
|
340
|
+
/**
|
|
341
|
+
* Optional Content-Length hint reported by the server after decompression.
|
|
342
|
+
*/
|
|
343
|
+
contentLength: number | null;
|
|
344
|
+
/**
|
|
345
|
+
* Cookies set by the server as [name, value] tuples.
|
|
346
|
+
*/
|
|
347
|
+
cookies: HeaderTuple[];
|
|
348
|
+
/**
|
|
349
|
+
* Final URL after following any redirects.
|
|
350
|
+
* If no redirects occurred, this will match the original request URL.
|
|
351
|
+
*/
|
|
352
|
+
url: string;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Configuration options for creating a WebSocket connection.
|
|
356
|
+
* Supports browser impersonation and proxies, similar to HTTP requests.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const ws = await createWebSocket({
|
|
361
|
+
* url: 'wss://echo.websocket.org',
|
|
362
|
+
* browser: 'chrome_142',
|
|
363
|
+
* headers: { 'Authorization': 'Bearer token' },
|
|
364
|
+
* onMessage: (data) => {
|
|
365
|
+
* console.log('Received:', data);
|
|
366
|
+
* },
|
|
367
|
+
* onClose: () => {
|
|
368
|
+
* console.log('Connection closed');
|
|
369
|
+
* },
|
|
370
|
+
* onError: (error) => {
|
|
371
|
+
* console.error('WebSocket error:', error);
|
|
372
|
+
* }
|
|
373
|
+
* });
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
interface WebSocketOptions {
|
|
377
|
+
/**
|
|
378
|
+
* The WebSocket URL to connect to. Must use wss:// (secure) or ws:// (insecure) protocol.
|
|
379
|
+
*/
|
|
380
|
+
url: string;
|
|
381
|
+
/**
|
|
382
|
+
* Browser profile to impersonate for the WebSocket upgrade request.
|
|
383
|
+
* Automatically applies browser-specific headers and TLS fingerprints.
|
|
384
|
+
* @default 'chrome_142'
|
|
385
|
+
*/
|
|
386
|
+
browser?: BrowserProfile;
|
|
387
|
+
/**
|
|
388
|
+
* Operating system to emulate for the WebSocket handshake.
|
|
389
|
+
* @default 'macos'
|
|
390
|
+
*/
|
|
391
|
+
os?: EmulationOS;
|
|
392
|
+
/**
|
|
393
|
+
* Additional headers to send with the WebSocket upgrade request.
|
|
394
|
+
* Common headers include Authorization, Origin, or custom application headers.
|
|
395
|
+
*/
|
|
396
|
+
headers?: Record<string, string> | HeaderTuple[];
|
|
397
|
+
/**
|
|
398
|
+
* Proxy URL to route the connection through (e.g., 'http://proxy.example.com:8080').
|
|
399
|
+
* Supports HTTP and SOCKS5 proxies.
|
|
400
|
+
*/
|
|
401
|
+
proxy?: string;
|
|
402
|
+
/**
|
|
403
|
+
* Callback function invoked when a message is received from the server.
|
|
404
|
+
* The data parameter will be a string for text frames or a Buffer for binary frames.
|
|
405
|
+
*
|
|
406
|
+
* @param data - The received message as a string or Buffer
|
|
407
|
+
*/
|
|
408
|
+
onMessage: (data: string | Buffer) => void;
|
|
409
|
+
/**
|
|
410
|
+
* Callback function invoked when the WebSocket connection is closed.
|
|
411
|
+
* This is called for both clean closes and connection errors.
|
|
412
|
+
*/
|
|
413
|
+
onClose?: () => void;
|
|
414
|
+
/**
|
|
415
|
+
* Callback function invoked when a connection or protocol error occurs.
|
|
416
|
+
*
|
|
417
|
+
* @param error - A string describing the error that occurred
|
|
418
|
+
*/
|
|
419
|
+
onError?: (error: string) => void;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Internal WebSocket connection object returned from the native Rust binding.
|
|
423
|
+
* This interface contains the connection ID used to reference the WebSocket
|
|
424
|
+
* in subsequent operations like sending messages or closing the connection.
|
|
425
|
+
*
|
|
426
|
+
* @internal
|
|
427
|
+
*/
|
|
428
|
+
interface NativeWebSocketConnection {
|
|
429
|
+
/**
|
|
430
|
+
* Unique identifier for this WebSocket connection.
|
|
431
|
+
* Used internally to track and manage the connection.
|
|
432
|
+
* @internal
|
|
433
|
+
*/
|
|
434
|
+
_id: number;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Error thrown when a request fails. This can occur due to network errors,
|
|
438
|
+
* timeouts, invalid URLs, or other request-related issues.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* try {
|
|
443
|
+
* const response = await fetch('https://api.example.com');
|
|
444
|
+
* } catch (error) {
|
|
445
|
+
* if (error instanceof RequestError) {
|
|
446
|
+
* console.error('Request failed:', error.message);
|
|
447
|
+
* }
|
|
448
|
+
* }
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
declare class RequestError extends Error {
|
|
452
|
+
constructor(message: string);
|
|
453
|
+
}
|
|
454
|
+
|
|
4
455
|
type SessionDefaults = {
|
|
5
456
|
browser: BrowserProfile;
|
|
6
457
|
os: EmulationOS;
|
|
@@ -8,7 +459,7 @@ type SessionDefaults = {
|
|
|
8
459
|
timeout?: number;
|
|
9
460
|
insecure?: boolean;
|
|
10
461
|
};
|
|
11
|
-
|
|
462
|
+
declare class Headers implements Iterable<[string, string]> {
|
|
12
463
|
private readonly store;
|
|
13
464
|
constructor(init?: HeadersInit);
|
|
14
465
|
private applyInit;
|
|
@@ -28,26 +479,29 @@ export declare class Headers implements Iterable<[string, string]> {
|
|
|
28
479
|
toTuples(): HeaderTuple[];
|
|
29
480
|
}
|
|
30
481
|
type ResponseType = "basic" | "cors" | "error" | "opaque" | "opaqueredirect";
|
|
31
|
-
|
|
482
|
+
declare class Response {
|
|
32
483
|
readonly status: number;
|
|
33
|
-
readonly statusText: string;
|
|
34
484
|
readonly ok: boolean;
|
|
35
485
|
readonly contentLength: number | null;
|
|
36
486
|
readonly url: string;
|
|
37
|
-
readonly redirected: boolean;
|
|
38
487
|
readonly type: ResponseType;
|
|
39
|
-
readonly cookies: Record<string, string>;
|
|
40
488
|
bodyUsed: boolean;
|
|
41
489
|
private readonly payload;
|
|
42
490
|
private readonly requestUrl;
|
|
491
|
+
private redirectedMemo;
|
|
43
492
|
private readonly headersInit;
|
|
44
493
|
private headersInstance;
|
|
494
|
+
private readonly cookiesInit;
|
|
495
|
+
private cookiesRecord;
|
|
45
496
|
private inlineBody;
|
|
46
497
|
private bodySource;
|
|
47
498
|
private bodyStream;
|
|
48
499
|
private nativeHandleAvailable;
|
|
49
500
|
constructor(payload: NativeResponse, requestUrl: string, bodySource?: ReadableStream<Uint8Array> | null);
|
|
501
|
+
get redirected(): boolean;
|
|
502
|
+
get statusText(): string;
|
|
50
503
|
get headers(): Headers;
|
|
504
|
+
get cookies(): Record<string, string | string[]>;
|
|
51
505
|
get body(): ReadableStream<Uint8Array> | null;
|
|
52
506
|
json<T = unknown>(): Promise<T>;
|
|
53
507
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
@@ -56,7 +510,7 @@ export declare class Response {
|
|
|
56
510
|
private assertBodyAvailable;
|
|
57
511
|
private consumeBody;
|
|
58
512
|
}
|
|
59
|
-
|
|
513
|
+
declare class Session implements SessionHandle {
|
|
60
514
|
readonly id: string;
|
|
61
515
|
private disposed;
|
|
62
516
|
private readonly defaults;
|
|
@@ -65,10 +519,9 @@ export declare class Session implements SessionHandle {
|
|
|
65
519
|
private ensureActive;
|
|
66
520
|
/** @internal */
|
|
67
521
|
getDefaults(): SessionDefaults;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
fetch(input: string | URL, init?: WreqRequestInit): Promise<Response>;
|
|
522
|
+
/** @internal */
|
|
523
|
+
_defaultsRef(): SessionDefaults;
|
|
524
|
+
fetch(input: string | URL, init?: RequestInit): Promise<Response>;
|
|
72
525
|
clearCookies(): Promise<void>;
|
|
73
526
|
close(): Promise<void>;
|
|
74
527
|
}
|
|
@@ -103,13 +556,13 @@ export declare class Session implements SessionHandle {
|
|
|
103
556
|
* });
|
|
104
557
|
* ```
|
|
105
558
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
559
|
+
declare function fetch(input: string | URL, init?: RequestInit): Promise<Response>;
|
|
560
|
+
declare function createSession(options?: CreateSessionOptions): Promise<Session>;
|
|
561
|
+
declare function withSession<T>(fn: (session: Session) => Promise<T> | T, options?: CreateSessionOptions): Promise<T>;
|
|
109
562
|
/**
|
|
110
563
|
* @deprecated Use {@link fetch} instead.
|
|
111
564
|
*/
|
|
112
|
-
|
|
565
|
+
declare function request(options: RequestOptions): Promise<Response>;
|
|
113
566
|
/**
|
|
114
567
|
* Get list of available browser profiles
|
|
115
568
|
*
|
|
@@ -123,21 +576,21 @@ export declare function request(options: RequestOptions): Promise<Response>;
|
|
|
123
576
|
* console.log(profiles); // ['chrome_120', 'chrome_131', 'firefox', ...]
|
|
124
577
|
* ```
|
|
125
578
|
*/
|
|
126
|
-
|
|
579
|
+
declare function getProfiles(): BrowserProfile[];
|
|
127
580
|
/**
|
|
128
581
|
* Get list of supported operating systems for emulation.
|
|
129
582
|
*
|
|
130
583
|
* @returns Array of operating system identifiers
|
|
131
584
|
*/
|
|
132
|
-
|
|
585
|
+
declare function getOperatingSystems(): EmulationOS[];
|
|
133
586
|
/**
|
|
134
587
|
* Convenience helper for GET requests using {@link fetch}.
|
|
135
588
|
*/
|
|
136
|
-
|
|
589
|
+
declare function get(url: string, init?: Omit<RequestInit, "method">): Promise<Response>;
|
|
137
590
|
/**
|
|
138
591
|
* Convenience helper for POST requests using {@link fetch}.
|
|
139
592
|
*/
|
|
140
|
-
|
|
593
|
+
declare function post(url: string, body?: BodyInit | null, init?: Omit<RequestInit, "method" | "body">): Promise<Response>;
|
|
141
594
|
/**
|
|
142
595
|
* WebSocket connection class
|
|
143
596
|
*
|
|
@@ -169,7 +622,7 @@ export declare function post(url: string, body?: BodyInit | null, init?: Omit<Wr
|
|
|
169
622
|
* await ws.close();
|
|
170
623
|
* ```
|
|
171
624
|
*/
|
|
172
|
-
|
|
625
|
+
declare class WebSocket {
|
|
173
626
|
private _connection;
|
|
174
627
|
private _finalizerToken;
|
|
175
628
|
private _closed;
|
|
@@ -189,9 +642,8 @@ export declare class WebSocket {
|
|
|
189
642
|
* @param options - WebSocket options
|
|
190
643
|
* @returns Promise that resolves to the WebSocket instance
|
|
191
644
|
*/
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
export { RequestError };
|
|
645
|
+
declare function websocket(options: WebSocketOptions): Promise<WebSocket>;
|
|
646
|
+
|
|
195
647
|
declare const _default: {
|
|
196
648
|
fetch: typeof fetch;
|
|
197
649
|
request: typeof request;
|
|
@@ -207,5 +659,5 @@ declare const _default: {
|
|
|
207
659
|
Response: typeof Response;
|
|
208
660
|
Session: typeof Session;
|
|
209
661
|
};
|
|
210
|
-
|
|
211
|
-
|
|
662
|
+
|
|
663
|
+
export { type BodyInit, type BrowserProfile, type CookieMode, type CreateSessionOptions, type EmulationOS, Headers, type HeadersInit, RequestError, type RequestInit, type RequestOptions, Response, Session, type SessionHandle, WebSocket, type WebSocketOptions, createSession, _default as default, fetch, get, getOperatingSystems, getProfiles, post, request, websocket, withSession };
|