wreq-js 1.7.0 → 2.0.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/README.md +110 -26
- package/dist/wreq-js.cjs +796 -94
- package/dist/wreq-js.cjs.map +1 -1
- package/dist/wreq-js.d.cts +248 -102
- package/dist/wreq-js.d.ts +248 -102
- package/dist/wreq-js.js +796 -94
- package/dist/wreq-js.js.map +1 -1
- package/package.json +4 -1
- 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/wreq-js.d.cts
CHANGED
|
@@ -76,7 +76,35 @@ type BodyInit = string | ArrayBuffer | ArrayBufferView | URLSearchParams | Buffe
|
|
|
76
76
|
/**
|
|
77
77
|
* Details about why a WebSocket connection closed.
|
|
78
78
|
*/
|
|
79
|
+
type WebSocketBinaryType = "nodebuffer" | "arraybuffer" | "blob";
|
|
80
|
+
type WebSocketEventType = "open" | "message" | "close" | "error";
|
|
81
|
+
interface WebSocketOpenEvent {
|
|
82
|
+
type: "open";
|
|
83
|
+
isTrusted: false;
|
|
84
|
+
timeStamp: number;
|
|
85
|
+
target: WebSocket;
|
|
86
|
+
currentTarget: WebSocket;
|
|
87
|
+
}
|
|
88
|
+
interface WebSocketMessageEvent {
|
|
89
|
+
type: "message";
|
|
90
|
+
isTrusted: false;
|
|
91
|
+
timeStamp: number;
|
|
92
|
+
data: string | Buffer | ArrayBuffer | Blob;
|
|
93
|
+
target: WebSocket;
|
|
94
|
+
currentTarget: WebSocket;
|
|
95
|
+
}
|
|
96
|
+
interface WebSocketErrorEvent {
|
|
97
|
+
type: "error";
|
|
98
|
+
isTrusted: false;
|
|
99
|
+
timeStamp: number;
|
|
100
|
+
message?: string;
|
|
101
|
+
target: WebSocket;
|
|
102
|
+
currentTarget: WebSocket;
|
|
103
|
+
}
|
|
79
104
|
interface WebSocketCloseEvent {
|
|
105
|
+
type: "close";
|
|
106
|
+
isTrusted: false;
|
|
107
|
+
timeStamp: number;
|
|
80
108
|
/**
|
|
81
109
|
* WebSocket close status code (RFC 6455).
|
|
82
110
|
*/
|
|
@@ -85,10 +113,13 @@ interface WebSocketCloseEvent {
|
|
|
85
113
|
* UTF-8 close reason sent by the peer.
|
|
86
114
|
*/
|
|
87
115
|
reason: string;
|
|
116
|
+
wasClean: boolean;
|
|
117
|
+
target: WebSocket;
|
|
118
|
+
currentTarget: WebSocket;
|
|
88
119
|
}
|
|
89
120
|
/**
|
|
90
|
-
* Options for configuring a fetch request
|
|
91
|
-
*
|
|
121
|
+
* Options for configuring a fetch style request with wreq-specific extensions
|
|
122
|
+
* for browser impersonation, proxies, sessions, and timeouts.
|
|
92
123
|
*
|
|
93
124
|
* @example
|
|
94
125
|
* ```typescript
|
|
@@ -133,27 +164,28 @@ interface RequestInit {
|
|
|
133
164
|
transport?: Transport;
|
|
134
165
|
/**
|
|
135
166
|
* Browser profile to impersonate for this request.
|
|
136
|
-
*
|
|
167
|
+
* Applies browser profile behavior handled by the native layer.
|
|
137
168
|
* Ignored when `transport` is provided.
|
|
138
169
|
* @default 'chrome_142'
|
|
139
170
|
*/
|
|
140
171
|
browser?: BrowserProfile;
|
|
141
172
|
/**
|
|
142
173
|
* Operating system to emulate for this request.
|
|
143
|
-
* Influences platform-specific
|
|
174
|
+
* Influences platform-specific behavior handled by the native layer.
|
|
144
175
|
* Ignored when `transport` is provided.
|
|
145
176
|
* @default 'macos'
|
|
146
177
|
*/
|
|
147
178
|
os?: EmulationOS;
|
|
148
179
|
/**
|
|
149
180
|
* Proxy URL to route the request through (e.g., 'http://proxy.example.com:8080').
|
|
150
|
-
*
|
|
181
|
+
* Proxy support depends on the native layer and proxy scheme.
|
|
151
182
|
* Ignored when `transport` is provided.
|
|
152
183
|
*/
|
|
153
184
|
proxy?: string;
|
|
154
185
|
/**
|
|
155
186
|
* Request timeout in milliseconds. If the request takes longer than this value,
|
|
156
|
-
* it will be aborted.
|
|
187
|
+
* it will be aborted.
|
|
188
|
+
* @default 30000
|
|
157
189
|
*/
|
|
158
190
|
timeout?: number;
|
|
159
191
|
/**
|
|
@@ -208,20 +240,14 @@ interface CreateSessionOptions {
|
|
|
208
240
|
defaultHeaders?: HeadersInit;
|
|
209
241
|
/**
|
|
210
242
|
* Browser profile to bind to this session. Defaults to 'chrome_142'.
|
|
211
|
-
*
|
|
212
|
-
* @deprecated Use {@link createTransport} and pass the transport to requests instead.
|
|
213
243
|
*/
|
|
214
244
|
browser?: BrowserProfile;
|
|
215
245
|
/**
|
|
216
246
|
* Operating system to bind to this session. Defaults to 'macos'.
|
|
217
|
-
*
|
|
218
|
-
* @deprecated Use {@link createTransport} and pass the transport to requests instead.
|
|
219
247
|
*/
|
|
220
248
|
os?: EmulationOS;
|
|
221
249
|
/**
|
|
222
250
|
* Optional proxy for every request made through the session.
|
|
223
|
-
*
|
|
224
|
-
* @deprecated Use {@link createTransport} and pass the transport to requests instead.
|
|
225
251
|
*/
|
|
226
252
|
proxy?: string;
|
|
227
253
|
/**
|
|
@@ -233,8 +259,6 @@ interface CreateSessionOptions {
|
|
|
233
259
|
* Disable HTTPS certificate verification. When enabled, self-signed and invalid
|
|
234
260
|
* certificates will be accepted for all requests made through this session.
|
|
235
261
|
*
|
|
236
|
-
* @deprecated Use {@link createTransport} and pass the transport to requests instead.
|
|
237
|
-
*
|
|
238
262
|
* # Warning
|
|
239
263
|
*
|
|
240
264
|
* You should think very carefully before using this method. If invalid
|
|
@@ -315,7 +339,7 @@ interface RequestOptions {
|
|
|
315
339
|
url: string;
|
|
316
340
|
/**
|
|
317
341
|
* Browser profile to impersonate.
|
|
318
|
-
*
|
|
342
|
+
* Applies browser profile behavior handled by the native layer.
|
|
319
343
|
* @default 'chrome_142'
|
|
320
344
|
*/
|
|
321
345
|
browser?: BrowserProfile;
|
|
@@ -337,7 +361,7 @@ interface RequestOptions {
|
|
|
337
361
|
/**
|
|
338
362
|
* Request body data (for POST, PUT, PATCH requests).
|
|
339
363
|
*/
|
|
340
|
-
body?:
|
|
364
|
+
body?: BodyInit | null;
|
|
341
365
|
/**
|
|
342
366
|
* Transport instance to use for this request. When provided, transport-level
|
|
343
367
|
* options such as `browser`, `os`, `proxy`, and `insecure` must not be set.
|
|
@@ -345,7 +369,7 @@ interface RequestOptions {
|
|
|
345
369
|
transport?: Transport;
|
|
346
370
|
/**
|
|
347
371
|
* Proxy URL to route the request through (e.g., 'http://proxy.example.com:8080').
|
|
348
|
-
*
|
|
372
|
+
* Proxy support depends on the native layer and proxy scheme.
|
|
349
373
|
*/
|
|
350
374
|
proxy?: string;
|
|
351
375
|
/**
|
|
@@ -355,9 +379,22 @@ interface RequestOptions {
|
|
|
355
379
|
redirect?: "follow" | "manual" | "error";
|
|
356
380
|
/**
|
|
357
381
|
* Request timeout in milliseconds. If the request takes longer than this value,
|
|
358
|
-
* it will be aborted.
|
|
382
|
+
* it will be aborted.
|
|
383
|
+
* @default 30000
|
|
359
384
|
*/
|
|
360
385
|
timeout?: number;
|
|
386
|
+
/**
|
|
387
|
+
* Signal used to abort the request.
|
|
388
|
+
*/
|
|
389
|
+
signal?: AbortSignal | null;
|
|
390
|
+
/**
|
|
391
|
+
* Session instance to bind this request to.
|
|
392
|
+
*/
|
|
393
|
+
session?: Session;
|
|
394
|
+
/**
|
|
395
|
+
* Controls cookie scoping behavior for this request.
|
|
396
|
+
*/
|
|
397
|
+
cookieMode?: CookieMode;
|
|
361
398
|
/**
|
|
362
399
|
* Identifier for the session that should handle this request.
|
|
363
400
|
* @internal
|
|
@@ -438,27 +475,17 @@ interface NativeResponse {
|
|
|
438
475
|
*
|
|
439
476
|
* @example
|
|
440
477
|
* ```typescript
|
|
441
|
-
* const ws = await
|
|
442
|
-
* url: 'wss://echo.websocket.org',
|
|
478
|
+
* const ws = await websocket('wss://example.com/socket', {
|
|
443
479
|
* browser: 'chrome_142',
|
|
444
480
|
* headers: { 'Authorization': 'Bearer token' },
|
|
445
|
-
* onMessage: (data) => {
|
|
446
|
-
* console.log('Received:', data);
|
|
447
|
-
* },
|
|
448
|
-
* onClose: (event) => {
|
|
449
|
-
* console.log('Connection closed:', event.code, event.reason);
|
|
450
|
-
* },
|
|
451
|
-
* onError: (error) => {
|
|
452
|
-
* console.error('WebSocket error:', error);
|
|
453
|
-
* }
|
|
454
481
|
* });
|
|
482
|
+
*
|
|
483
|
+
* ws.onmessage = (event) => {
|
|
484
|
+
* console.log('Received:', event.data);
|
|
485
|
+
* };
|
|
455
486
|
* ```
|
|
456
487
|
*/
|
|
457
488
|
interface WebSocketOptions {
|
|
458
|
-
/**
|
|
459
|
-
* The WebSocket URL to connect to. Must use wss:// (secure) or ws:// (insecure) protocol.
|
|
460
|
-
*/
|
|
461
|
-
url: string;
|
|
462
489
|
/**
|
|
463
490
|
* Browser profile to impersonate for the WebSocket upgrade request.
|
|
464
491
|
* Automatically applies browser-specific headers and TLS fingerprints.
|
|
@@ -474,28 +501,60 @@ interface WebSocketOptions {
|
|
|
474
501
|
* Additional headers to send with the WebSocket upgrade request.
|
|
475
502
|
* Common headers include Authorization, Origin, or custom application headers.
|
|
476
503
|
*/
|
|
477
|
-
headers?:
|
|
504
|
+
headers?: HeadersInit;
|
|
478
505
|
/**
|
|
479
506
|
* Proxy URL to route the connection through (e.g., 'http://proxy.example.com:8080').
|
|
480
|
-
*
|
|
507
|
+
* Proxy support depends on the native layer and proxy scheme.
|
|
481
508
|
*/
|
|
482
509
|
proxy?: string;
|
|
483
510
|
/**
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* @param data - The received message as a string or Buffer
|
|
511
|
+
* Optional subprotocols for compatibility with the WHATWG WebSocket constructor.
|
|
512
|
+
* Values are validated for non-empty, unique entries and sent in
|
|
513
|
+
* the `Sec-WebSocket-Protocol` handshake header.
|
|
488
514
|
*/
|
|
489
|
-
|
|
515
|
+
protocols?: string | string[];
|
|
516
|
+
/**
|
|
517
|
+
* Controls the binary payload type exposed via `MessageEvent.data`.
|
|
518
|
+
* - "nodebuffer": delivers Node.js Buffer instances (default)
|
|
519
|
+
* - "arraybuffer": delivers ArrayBuffer instances
|
|
520
|
+
* - "blob": delivers Blob instances
|
|
521
|
+
*/
|
|
522
|
+
binaryType?: WebSocketBinaryType;
|
|
523
|
+
}
|
|
524
|
+
interface LegacyWebSocketOptions extends WebSocketOptions {
|
|
525
|
+
/**
|
|
526
|
+
* @deprecated Use `websocket(url, options)` or `new WebSocket(...)`.
|
|
527
|
+
*/
|
|
528
|
+
url: string;
|
|
490
529
|
/**
|
|
491
|
-
*
|
|
492
|
-
|
|
530
|
+
* @deprecated Use `onmessage` or `addEventListener("message", ...)`.
|
|
531
|
+
*/
|
|
532
|
+
onMessage?: (data: string | Buffer) => void;
|
|
533
|
+
/**
|
|
534
|
+
* @deprecated Use `onclose` or `addEventListener("close", ...)`.
|
|
493
535
|
*/
|
|
494
536
|
onClose?: (event: WebSocketCloseEvent) => void;
|
|
495
537
|
/**
|
|
496
|
-
*
|
|
497
|
-
|
|
498
|
-
|
|
538
|
+
* @deprecated Use `onerror` or `addEventListener("error", ...)`.
|
|
539
|
+
*/
|
|
540
|
+
onError?: (error: string) => void;
|
|
541
|
+
}
|
|
542
|
+
type SessionWebSocketOptions = Omit<WebSocketOptions, "browser" | "os" | "proxy">;
|
|
543
|
+
interface LegacySessionWebSocketOptions extends SessionWebSocketOptions {
|
|
544
|
+
/**
|
|
545
|
+
* @deprecated Use `session.websocket(url, options)`.
|
|
546
|
+
*/
|
|
547
|
+
url: string;
|
|
548
|
+
/**
|
|
549
|
+
* @deprecated Use `onmessage` or `addEventListener("message", ...)`.
|
|
550
|
+
*/
|
|
551
|
+
onMessage?: (data: string | Buffer) => void;
|
|
552
|
+
/**
|
|
553
|
+
* @deprecated Use `onclose` or `addEventListener("close", ...)`.
|
|
554
|
+
*/
|
|
555
|
+
onClose?: (event: WebSocketCloseEvent) => void;
|
|
556
|
+
/**
|
|
557
|
+
* @deprecated Use `onerror` or `addEventListener("error", ...)`.
|
|
499
558
|
*/
|
|
500
559
|
onError?: (error: string) => void;
|
|
501
560
|
}
|
|
@@ -513,6 +572,16 @@ interface NativeWebSocketConnection {
|
|
|
513
572
|
* @internal
|
|
514
573
|
*/
|
|
515
574
|
_id: number;
|
|
575
|
+
/**
|
|
576
|
+
* Selected subprotocol returned by the server, when present.
|
|
577
|
+
* @internal
|
|
578
|
+
*/
|
|
579
|
+
protocol?: string;
|
|
580
|
+
/**
|
|
581
|
+
* Negotiated extension string returned by the server, when present.
|
|
582
|
+
* @internal
|
|
583
|
+
*/
|
|
584
|
+
extensions?: string;
|
|
516
585
|
}
|
|
517
586
|
/**
|
|
518
587
|
* Error thrown when a request fails. This can occur due to network errors,
|
|
@@ -529,10 +598,14 @@ interface NativeWebSocketConnection {
|
|
|
529
598
|
* }
|
|
530
599
|
* ```
|
|
531
600
|
*/
|
|
532
|
-
declare class RequestError extends
|
|
601
|
+
declare class RequestError extends TypeError {
|
|
533
602
|
constructor(message: string);
|
|
534
603
|
}
|
|
535
604
|
|
|
605
|
+
interface NativeWebSocketCloseEvent {
|
|
606
|
+
code: number;
|
|
607
|
+
reason: string;
|
|
608
|
+
}
|
|
536
609
|
type SessionDefaults = {
|
|
537
610
|
browser: BrowserProfile;
|
|
538
611
|
os: EmulationOS;
|
|
@@ -543,6 +616,24 @@ type SessionDefaults = {
|
|
|
543
616
|
transportId?: string;
|
|
544
617
|
ownsTransport?: boolean;
|
|
545
618
|
};
|
|
619
|
+
type LegacyWebSocketCallbacks = {
|
|
620
|
+
onMessage?: (data: string | Buffer) => void;
|
|
621
|
+
onClose?: (event: WebSocketCloseEvent) => void;
|
|
622
|
+
onError?: (error: string) => void;
|
|
623
|
+
};
|
|
624
|
+
type WebSocketOpenDispatchMode = "automatic" | "deferred";
|
|
625
|
+
type InternalWebSocketInit = {
|
|
626
|
+
readonly _internal: true;
|
|
627
|
+
url: string;
|
|
628
|
+
options: WebSocketOptions;
|
|
629
|
+
openDispatchMode: WebSocketOpenDispatchMode;
|
|
630
|
+
connect: (callbacks: {
|
|
631
|
+
onMessage: (data: string | Buffer) => void;
|
|
632
|
+
onClose: (event: NativeWebSocketCloseEvent) => void;
|
|
633
|
+
onError: (message: string) => void;
|
|
634
|
+
}) => Promise<NativeWebSocketConnection>;
|
|
635
|
+
legacyCallbacks: LegacyWebSocketCallbacks | undefined;
|
|
636
|
+
};
|
|
546
637
|
declare class Headers implements Iterable<[string, string]> {
|
|
547
638
|
private readonly store;
|
|
548
639
|
constructor(init?: HeadersInit);
|
|
@@ -591,6 +682,8 @@ declare class Response {
|
|
|
591
682
|
json<T = unknown>(): Promise<T>;
|
|
592
683
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
593
684
|
text(): Promise<string>;
|
|
685
|
+
blob(): Promise<Blob>;
|
|
686
|
+
formData(): Promise<FormData>;
|
|
594
687
|
clone(): Response;
|
|
595
688
|
private assertBodyAvailable;
|
|
596
689
|
private consumeBody;
|
|
@@ -613,27 +706,36 @@ declare class Session implements SessionHandle {
|
|
|
613
706
|
getDefaults(): SessionDefaults;
|
|
614
707
|
/** @internal */
|
|
615
708
|
_defaultsRef(): SessionDefaults;
|
|
616
|
-
fetch(input: string | URL, init?: RequestInit): Promise<Response>;
|
|
709
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
617
710
|
clearCookies(): Promise<void>;
|
|
711
|
+
/**
|
|
712
|
+
* Create a WebSocket connection that shares this session's cookies and TLS configuration.
|
|
713
|
+
*
|
|
714
|
+
* @param urlOrOptions - WebSocket URL or legacy options object
|
|
715
|
+
* @param options - Session WebSocket options
|
|
716
|
+
* @returns Promise that resolves to the WebSocket instance
|
|
717
|
+
*/
|
|
718
|
+
websocket(url: string | URL, options?: SessionWebSocketOptions): Promise<WebSocket>;
|
|
719
|
+
websocket(options: LegacySessionWebSocketOptions): Promise<WebSocket>;
|
|
618
720
|
close(): Promise<void>;
|
|
619
721
|
}
|
|
620
722
|
/**
|
|
621
723
|
* Fetch-compatible entry point that adds browser impersonation controls.
|
|
622
724
|
*
|
|
623
|
-
* **Important:** The default fetch is isolated and non-persistent by design.
|
|
624
|
-
*
|
|
625
|
-
* TLS
|
|
725
|
+
* **Important:** The default fetch path is isolated and non-persistent by design.
|
|
726
|
+
* Each call uses an isolated request context, so cookies are not shared across calls.
|
|
727
|
+
* Connection and TLS reuse behavior is handled by the native layer.
|
|
626
728
|
*
|
|
627
729
|
* **Use {@link createSession} or {@link withSession} if you need:**
|
|
628
730
|
* - Cookie persistence across requests
|
|
629
|
-
* -
|
|
630
|
-
* -
|
|
731
|
+
* - Shared session defaults across requests
|
|
732
|
+
* - A single session context for multi-step flows
|
|
631
733
|
*
|
|
632
734
|
* **Concurrency:** The core is unthrottled by design. Callers are expected to implement
|
|
633
735
|
* their own concurrency control (e.g., p-limit) if needed. Built-in throttling would
|
|
634
736
|
* reduce performance for high-throughput workloads.
|
|
635
737
|
*
|
|
636
|
-
* @param input - Request URL (string or URL
|
|
738
|
+
* @param input - Request URL (string or URL) or a Request object
|
|
637
739
|
* @param init - Fetch-compatible init options
|
|
638
740
|
*
|
|
639
741
|
* @example
|
|
@@ -648,7 +750,7 @@ declare class Session implements SessionHandle {
|
|
|
648
750
|
* });
|
|
649
751
|
* ```
|
|
650
752
|
*/
|
|
651
|
-
declare function fetch(input: string | URL, init?: RequestInit): Promise<Response>;
|
|
753
|
+
declare function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
652
754
|
declare function createTransport(options?: CreateTransportOptions): Promise<Transport>;
|
|
653
755
|
declare function createSession(options?: CreateSessionOptions): Promise<Session>;
|
|
654
756
|
declare function withSession<T>(fn: (session: Session) => Promise<T> | T, options?: CreateSessionOptions): Promise<T>;
|
|
@@ -679,64 +781,107 @@ declare function getOperatingSystems(): EmulationOS[];
|
|
|
679
781
|
/**
|
|
680
782
|
* Convenience helper for GET requests using {@link fetch}.
|
|
681
783
|
*/
|
|
682
|
-
declare function get(url: string, init?: Omit<RequestInit, "method">): Promise<Response>;
|
|
784
|
+
declare function get(url: string | URL | Request, init?: Omit<RequestInit, "method">): Promise<Response>;
|
|
683
785
|
/**
|
|
684
786
|
* Convenience helper for POST requests using {@link fetch}.
|
|
685
787
|
*/
|
|
686
|
-
declare function post(url: string, body?: BodyInit | null, init?: Omit<RequestInit, "method" | "body">): Promise<Response>;
|
|
788
|
+
declare function post(url: string | URL | Request, body?: BodyInit | null, init?: Omit<RequestInit, "method" | "body">): Promise<Response>;
|
|
789
|
+
type WebSocketAddEventListenerOptions = boolean | {
|
|
790
|
+
once?: boolean;
|
|
791
|
+
signal?: AbortSignal | null;
|
|
792
|
+
};
|
|
687
793
|
/**
|
|
688
|
-
* WebSocket connection
|
|
689
|
-
*
|
|
690
|
-
* @example
|
|
691
|
-
* ```typescript
|
|
692
|
-
* import { websocket } from 'wreq-js';
|
|
693
|
-
*
|
|
694
|
-
* const ws = await websocket({
|
|
695
|
-
* url: 'wss://echo.websocket.org',
|
|
696
|
-
* browser: 'chrome_142',
|
|
697
|
-
* onMessage: (data) => {
|
|
698
|
-
* console.log('Received:', data);
|
|
699
|
-
* },
|
|
700
|
-
* onClose: (event) => {
|
|
701
|
-
* console.log('Connection closed:', event.code, event.reason);
|
|
702
|
-
* },
|
|
703
|
-
* onError: (error) => {
|
|
704
|
-
* console.error('Error:', error);
|
|
705
|
-
* }
|
|
706
|
-
* });
|
|
707
|
-
*
|
|
708
|
-
* // Send text message
|
|
709
|
-
* await ws.send('Hello World');
|
|
710
|
-
*
|
|
711
|
-
* // Send binary message
|
|
712
|
-
* await ws.send(Buffer.from([1, 2, 3]));
|
|
713
|
-
*
|
|
714
|
-
* // Close connection
|
|
715
|
-
* await ws.close();
|
|
716
|
-
* ```
|
|
794
|
+
* WHATWG-style WebSocket API with async connection establishment.
|
|
717
795
|
*/
|
|
718
796
|
declare class WebSocket {
|
|
797
|
+
static readonly CONNECTING = 0;
|
|
798
|
+
static readonly OPEN = 1;
|
|
799
|
+
static readonly CLOSING = 2;
|
|
800
|
+
static readonly CLOSED = 3;
|
|
801
|
+
readonly url: string;
|
|
802
|
+
protocol: string;
|
|
803
|
+
extensions: string;
|
|
804
|
+
readyState: number;
|
|
805
|
+
private _binaryType;
|
|
806
|
+
private _bufferedAmount;
|
|
807
|
+
private _onopen;
|
|
808
|
+
private _onmessage;
|
|
809
|
+
private _onclose;
|
|
810
|
+
private _onerror;
|
|
811
|
+
private _onHandlerOrder;
|
|
812
|
+
private _listenerOrderCounter;
|
|
813
|
+
private readonly _listeners;
|
|
814
|
+
private readonly _legacyCallbacks;
|
|
815
|
+
private readonly _openDispatchMode;
|
|
719
816
|
private _connection;
|
|
817
|
+
private _connectPromise;
|
|
818
|
+
private _closeOptions;
|
|
720
819
|
private _finalizerToken;
|
|
721
|
-
private
|
|
722
|
-
private
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
820
|
+
private _openEventDispatched;
|
|
821
|
+
private _openEventQueued;
|
|
822
|
+
private _closeEventDispatched;
|
|
823
|
+
private _nativeCloseStarted;
|
|
824
|
+
private _pendingMessages;
|
|
825
|
+
private _sendChain;
|
|
826
|
+
constructor(init: InternalWebSocketInit);
|
|
827
|
+
constructor(url: string | URL, protocols?: string | string[]);
|
|
828
|
+
constructor(url: string | URL, protocols?: string | string[], options?: WebSocketOptions);
|
|
829
|
+
constructor(url: string | URL, options?: WebSocketOptions);
|
|
830
|
+
get binaryType(): WebSocketBinaryType;
|
|
831
|
+
set binaryType(value: WebSocketBinaryType);
|
|
832
|
+
get bufferedAmount(): number;
|
|
833
|
+
get onopen(): ((this: WebSocket, event: WebSocketOpenEvent) => void) | null;
|
|
834
|
+
set onopen(listener: ((this: WebSocket, event: WebSocketOpenEvent) => void) | null);
|
|
835
|
+
get onmessage(): ((this: WebSocket, event: WebSocketMessageEvent) => void) | null;
|
|
836
|
+
set onmessage(listener: ((this: WebSocket, event: WebSocketMessageEvent) => void) | null);
|
|
837
|
+
get onclose(): ((this: WebSocket, event: WebSocketCloseEvent) => void) | null;
|
|
838
|
+
set onclose(listener: ((this: WebSocket, event: WebSocketCloseEvent) => void) | null);
|
|
839
|
+
get onerror(): ((this: WebSocket, event: WebSocketErrorEvent) => void) | null;
|
|
840
|
+
set onerror(listener: ((this: WebSocket, event: WebSocketErrorEvent) => void) | null);
|
|
841
|
+
static _connectWithInit(init: InternalWebSocketInit): Promise<WebSocket>;
|
|
842
|
+
private static buildStandaloneInit;
|
|
843
|
+
private connect;
|
|
844
|
+
private _waitUntilConnected;
|
|
845
|
+
private scheduleOpenEventAfterConnect;
|
|
846
|
+
private scheduleOpenEventAfterAwait;
|
|
847
|
+
private scheduleOpenEventWithDepth;
|
|
848
|
+
private releaseConnectionTracking;
|
|
849
|
+
private toMessageEventData;
|
|
850
|
+
private invokeListener;
|
|
851
|
+
private createBaseEvent;
|
|
852
|
+
private getOnHandler;
|
|
853
|
+
private getOnHandlerOrder;
|
|
854
|
+
private getListenerMap;
|
|
855
|
+
private dispatchEvent;
|
|
856
|
+
private dispatchOpenEvent;
|
|
857
|
+
private dispatchMessageEvent;
|
|
858
|
+
private dispatchCloseEvent;
|
|
859
|
+
private dispatchErrorEvent;
|
|
860
|
+
private handleNativeMessage;
|
|
861
|
+
private handleNativeError;
|
|
862
|
+
private handleNativeClose;
|
|
863
|
+
private finalizeClosed;
|
|
864
|
+
private startNativeClose;
|
|
865
|
+
addEventListener(type: "open", listener: ((event: WebSocketOpenEvent) => void) | null, options?: WebSocketAddEventListenerOptions): void;
|
|
866
|
+
addEventListener(type: "message", listener: ((event: WebSocketMessageEvent) => void) | null, options?: WebSocketAddEventListenerOptions): void;
|
|
867
|
+
addEventListener(type: "close", listener: ((event: WebSocketCloseEvent) => void) | null, options?: WebSocketAddEventListenerOptions): void;
|
|
868
|
+
addEventListener(type: "error", listener: ((event: WebSocketErrorEvent) => void) | null, options?: WebSocketAddEventListenerOptions): void;
|
|
869
|
+
addEventListener(type: string, listener: unknown, options?: WebSocketAddEventListenerOptions): void;
|
|
870
|
+
removeEventListener(type: "open", listener: ((event: WebSocketOpenEvent) => void) | null): void;
|
|
871
|
+
removeEventListener(type: "message", listener: ((event: WebSocketMessageEvent) => void) | null): void;
|
|
872
|
+
removeEventListener(type: "close", listener: ((event: WebSocketCloseEvent) => void) | null): void;
|
|
873
|
+
removeEventListener(type: "error", listener: ((event: WebSocketErrorEvent) => void) | null): void;
|
|
874
|
+
removeEventListener(type: string, listener: unknown): void;
|
|
875
|
+
private getSendByteLength;
|
|
876
|
+
private normalizeSendPayload;
|
|
877
|
+
send(data: string | Buffer | ArrayBuffer | ArrayBufferView | Blob): void;
|
|
878
|
+
close(code?: number, reason?: string): void;
|
|
732
879
|
}
|
|
733
880
|
/**
|
|
734
|
-
* Create a WebSocket connection with browser impersonation
|
|
735
|
-
*
|
|
736
|
-
* @param options - WebSocket options
|
|
737
|
-
* @returns Promise that resolves to the WebSocket instance
|
|
881
|
+
* Create a WebSocket connection with browser impersonation.
|
|
738
882
|
*/
|
|
739
|
-
declare function websocket(
|
|
883
|
+
declare function websocket(url: string | URL, options?: WebSocketOptions): Promise<WebSocket>;
|
|
884
|
+
declare function websocket(options: LegacyWebSocketOptions): Promise<WebSocket>;
|
|
740
885
|
|
|
741
886
|
declare const _default: {
|
|
742
887
|
fetch: typeof fetch;
|
|
@@ -754,6 +899,7 @@ declare const _default: {
|
|
|
754
899
|
Response: typeof Response;
|
|
755
900
|
Transport: typeof Transport;
|
|
756
901
|
Session: typeof Session;
|
|
902
|
+
RequestError: typeof RequestError;
|
|
757
903
|
};
|
|
758
904
|
|
|
759
|
-
export { type BodyInit, type BrowserProfile, type CookieMode, type CreateSessionOptions, type CreateTransportOptions, type EmulationOS, Headers, type HeadersInit, RequestError, type RequestInit, type RequestOptions, Response, Session, type SessionHandle, Transport, WebSocket, type WebSocketOptions, createSession, createTransport, _default as default, fetch, get, getOperatingSystems, getProfiles, post, request, websocket, withSession };
|
|
905
|
+
export { type BodyInit, type BrowserProfile, type CookieMode, type CreateSessionOptions, type CreateTransportOptions, type EmulationOS, Headers, type HeadersInit, RequestError, type RequestInit, type RequestOptions, Response, Session, type SessionHandle, type SessionWebSocketOptions, Transport, WebSocket, type WebSocketBinaryType, type WebSocketCloseEvent, type WebSocketErrorEvent, type WebSocketEventType, type WebSocketMessageEvent, type WebSocketOpenEvent, type WebSocketOptions, createSession, createTransport, _default as default, fetch, get, getOperatingSystems, getProfiles, post, request, websocket, withSession };
|