@querying/sneaky 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +171 -2
- package/bin/sneaky-mcp.mjs +5 -0
- package/bin/sneaky.mjs +51 -0
- package/dist/agent/index.d.ts +277 -0
- package/dist/agent/index.js +319 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/browser/index.d.ts +69 -0
- package/dist/browser/index.js +326 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/cli/index.d.ts +51 -0
- package/dist/cli/index.js +189 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/driver/cdp.d.ts +36 -0
- package/dist/driver/cdp.js +240 -0
- package/dist/driver/cdp.js.map +1 -0
- package/dist/driver/frame.d.ts +229 -0
- package/dist/driver/frame.js +794 -0
- package/dist/driver/frame.js.map +1 -0
- package/dist/driver/index.d.ts +13 -0
- package/dist/driver/index.js +6 -0
- package/dist/driver/index.js.map +1 -0
- package/dist/driver/keys.d.ts +9 -0
- package/dist/driver/keys.js +65 -0
- package/dist/driver/keys.js.map +1 -0
- package/dist/driver/launcher.d.ts +49 -0
- package/dist/driver/launcher.js +251 -0
- package/dist/driver/launcher.js.map +1 -0
- package/dist/driver/page.d.ts +391 -0
- package/dist/driver/page.js +1594 -0
- package/dist/driver/page.js.map +1 -0
- package/dist/index.d.ts +501 -0
- package/dist/index.js +688 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +35 -0
- package/dist/mcp/server.js +548 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/repl/cli.d.ts +1 -0
- package/dist/repl/cli.js +246 -0
- package/dist/repl/cli.js.map +1 -0
- package/dist/repl/host.d.ts +46 -0
- package/dist/repl/host.js +167 -0
- package/dist/repl/host.js.map +1 -0
- package/dist/repl/index.d.ts +246 -0
- package/dist/repl/index.js +923 -0
- package/dist/repl/index.js.map +1 -0
- package/dist/repl/transform.d.ts +19 -0
- package/dist/repl/transform.js +590 -0
- package/dist/repl/transform.js.map +1 -0
- package/dist/request/index.d.ts +265 -0
- package/dist/request/index.js +898 -0
- package/dist/request/index.js.map +1 -0
- package/package.json +83 -4
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
/** Options of one session: a browser profile's worth of network state. */
|
|
3
|
+
export interface SessionOptions {
|
|
4
|
+
/** Session id. Random when omitted. */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** `http://user:pass@host:port`, `https://...` or `socks5://user:pass@host:port`. Omit for a direct connection. */
|
|
7
|
+
proxy?: string;
|
|
8
|
+
/** User-Agent of the CONNECT request to the proxy, and of a request that sets none. */
|
|
9
|
+
userAgent?: string;
|
|
10
|
+
/** Accept-Language of a request that sets none. */
|
|
11
|
+
acceptLanguage?: string;
|
|
12
|
+
/** Keep cookies between requests in the session's jar. Default true. */
|
|
13
|
+
cookies?: boolean;
|
|
14
|
+
/** Allow HTTP/3. Default true. */
|
|
15
|
+
http3?: boolean;
|
|
16
|
+
/** Accept any certificate. For test servers only. */
|
|
17
|
+
ignoreCertErrors?: boolean;
|
|
18
|
+
/** The daemon closes a session that ran no request for this long. Default 15 minutes; 0 keeps it. */
|
|
19
|
+
idleTtlMs?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Checks every HTTP/2 connection of the session at this interval and sends a PING on one that has
|
|
22
|
+
* received nothing for 10 seconds, which keeps a proxy tunnel open while a slow response is awaited.
|
|
23
|
+
* A connection whose PING goes unanswered fails with net::ERR_HTTP2_PING_FAILED. Off when omitted.
|
|
24
|
+
*/
|
|
25
|
+
h2PingMs?: number;
|
|
26
|
+
/**
|
|
27
|
+
* The proxy must accept a TCP connection within this. A request whose connection is closed for it
|
|
28
|
+
* fails with `proxyTimedOut`. No limit of the daemon's own when omitted.
|
|
29
|
+
*/
|
|
30
|
+
proxyDialTimeoutMs?: number;
|
|
31
|
+
/**
|
|
32
|
+
* The proxy must send its first byte on a connection within this of the start of the connection. An
|
|
33
|
+
* HTTP proxy sends it once it has reached the target, so this bounds the CONNECT exchange.
|
|
34
|
+
*/
|
|
35
|
+
proxyAnswerTimeoutMs?: number;
|
|
36
|
+
/**
|
|
37
|
+
* SETTINGS_INITIAL_WINDOW_SIZE of the session's HTTP/2 connections: how many bytes of one response
|
|
38
|
+
* the server may send before the session has read any. Chrome's 6291456 when omitted. With a small
|
|
39
|
+
* value and a request's bodyWindow, a response that the caller stops reading stops arriving.
|
|
40
|
+
*/
|
|
41
|
+
h2InitialWindowSize?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface RequestOptions {
|
|
44
|
+
method?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Sent in this order. Chromium adds what is missing, as it does for a page: Host, Accept-Encoding, Cookie.
|
|
47
|
+
* Referer, Accept-Encoding, Accept-Language and Cookie go after the other headers, in that order, which
|
|
48
|
+
* is where Chrome's network stack puts them.
|
|
49
|
+
*/
|
|
50
|
+
headers?: ReadonlyArray<readonly [string, string]> | Record<string, string>;
|
|
51
|
+
body?: string | Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Chromium's priority of the request, which sets its HTTP/2 weight and its `priority` header.
|
|
54
|
+
* A navigation is "highest", a fetch() or XHR "medium". Default "highest".
|
|
55
|
+
*/
|
|
56
|
+
priority?: "highest" | "medium" | "low" | "lowest" | "idle";
|
|
57
|
+
/** Fails the request with net::ERR_TIMED_OUT after this long, the body included. */
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
/** Default true. False returns the 3xx response. */
|
|
60
|
+
followRedirects?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The daemon reads at most this many bytes of the response body ahead of the caller. The body stream
|
|
63
|
+
* then holds nothing the caller has not asked for, and a body that is cancelled early costs at most
|
|
64
|
+
* this plus the HTTP/2 window. No limit when omitted.
|
|
65
|
+
*/
|
|
66
|
+
bodyWindow?: number;
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
}
|
|
69
|
+
export interface WebSocketOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Sent with the opening handshake. Origin sets the page the socket is opened from; without it the
|
|
72
|
+
* socket's own site is the origin. The headers of the handshake itself are Chromium's.
|
|
73
|
+
*/
|
|
74
|
+
headers?: ReadonlyArray<readonly [string, string]> | Record<string, string>;
|
|
75
|
+
/** Subprotocols to offer. */
|
|
76
|
+
protocols?: readonly string[];
|
|
77
|
+
/** Fails the opening handshake with net::ERR_TIMED_OUT after this long. */
|
|
78
|
+
timeoutMs?: number;
|
|
79
|
+
/** Aborts the socket, open or not. */
|
|
80
|
+
signal?: AbortSignal;
|
|
81
|
+
}
|
|
82
|
+
/** How a WebSocket ended. "clean" is true when both sides sent a Close frame. */
|
|
83
|
+
export interface WebSocketClose {
|
|
84
|
+
clean: boolean;
|
|
85
|
+
code: number;
|
|
86
|
+
reason: string;
|
|
87
|
+
/** The session's wire totals when the socket ended. */
|
|
88
|
+
session: WireBytes;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Bytes the session has moved over its TCP connections since it was created: TLS handshakes, the proxy
|
|
92
|
+
* CONNECT exchange and HTTP framing included. This is what a proxy provider meters. HTTP/3 runs over UDP
|
|
93
|
+
* and is not counted; a session with a proxy does not use it.
|
|
94
|
+
*/
|
|
95
|
+
export interface WireBytes {
|
|
96
|
+
wireBytesSent: number;
|
|
97
|
+
wireBytesReceived: number;
|
|
98
|
+
}
|
|
99
|
+
/** Bytes of one request after TLS, HTTP framing included, as Chromium counts them. */
|
|
100
|
+
export interface Transfer {
|
|
101
|
+
bytesSent: number;
|
|
102
|
+
bytesReceived: number;
|
|
103
|
+
/** The session's totals when the request ended. With one request at a time, the difference between two is that request's share. */
|
|
104
|
+
session: WireBytes;
|
|
105
|
+
}
|
|
106
|
+
export interface Stats {
|
|
107
|
+
sessionCount: number;
|
|
108
|
+
sessions: Record<string, WireBytes & {
|
|
109
|
+
bytesSent: number;
|
|
110
|
+
bytesReceived: number;
|
|
111
|
+
activeRequests: number;
|
|
112
|
+
requests: number;
|
|
113
|
+
}>;
|
|
114
|
+
}
|
|
115
|
+
/** `closed` is false when the session does not exist or a request is running on it. The totals are final. */
|
|
116
|
+
export type CloseResult = {
|
|
117
|
+
closed: true;
|
|
118
|
+
} & WireBytes | {
|
|
119
|
+
closed: false;
|
|
120
|
+
};
|
|
121
|
+
/** A request that Chromium could not complete. `code` is Chromium's name, such as `net::ERR_TIMED_OUT`. */
|
|
122
|
+
export declare class RequestError extends Error {
|
|
123
|
+
readonly code: string;
|
|
124
|
+
readonly netError: number | undefined;
|
|
125
|
+
/** True when the failure came after the response head, in the middle of the body. */
|
|
126
|
+
readonly headSent: boolean;
|
|
127
|
+
/** The session's wire totals when the request failed. */
|
|
128
|
+
readonly session: WireBytes | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* The status an `http://` proxy answered CONNECT with, when the request failed before its response
|
|
131
|
+
* head. A proxy reached over TLS or SOCKS5 reports none.
|
|
132
|
+
*/
|
|
133
|
+
readonly proxyStatus: number | undefined;
|
|
134
|
+
/** True when a connection to the proxy was closed for `proxyDialTimeoutMs` or `proxyAnswerTimeoutMs`. */
|
|
135
|
+
readonly proxyTimedOut: boolean;
|
|
136
|
+
/** The status the server answered a WebSocket handshake with, when it refused the socket. */
|
|
137
|
+
readonly status: number | undefined;
|
|
138
|
+
constructor(detail: {
|
|
139
|
+
code: string;
|
|
140
|
+
netError?: number;
|
|
141
|
+
message?: string;
|
|
142
|
+
headSent?: boolean;
|
|
143
|
+
session?: WireBytes;
|
|
144
|
+
proxyStatus?: number;
|
|
145
|
+
proxyTimedOut?: boolean;
|
|
146
|
+
status?: number;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
interface Head {
|
|
150
|
+
status: number;
|
|
151
|
+
statusText: string;
|
|
152
|
+
headers: [string, string][];
|
|
153
|
+
url: string;
|
|
154
|
+
protocol: string;
|
|
155
|
+
remote: string;
|
|
156
|
+
}
|
|
157
|
+
export declare class Response {
|
|
158
|
+
#private;
|
|
159
|
+
readonly status: number;
|
|
160
|
+
readonly statusText: string;
|
|
161
|
+
/** Response headers in the order the server sent them. */
|
|
162
|
+
readonly rawHeaders: ReadonlyArray<readonly [string, string]>;
|
|
163
|
+
/** The URL that answered, after redirects. */
|
|
164
|
+
readonly url: string;
|
|
165
|
+
/** "h2", "h3" or "http/1.1". */
|
|
166
|
+
readonly protocol: string;
|
|
167
|
+
/** Address the response came from: the proxy's when the session has one. */
|
|
168
|
+
readonly remote: string;
|
|
169
|
+
/** The body with Content-Encoding already undone. */
|
|
170
|
+
readonly body: ReadableStream<Uint8Array>;
|
|
171
|
+
/** Resolves when the body has been received in full. It rejects when the body fails. */
|
|
172
|
+
readonly finished: Promise<Transfer>;
|
|
173
|
+
/** @internal */
|
|
174
|
+
constructor(head: Head, body: ReadableStream<Uint8Array>, finished: Promise<Transfer>);
|
|
175
|
+
get headers(): Headers;
|
|
176
|
+
get ok(): boolean;
|
|
177
|
+
bytes(): Promise<Uint8Array>;
|
|
178
|
+
text(): Promise<string>;
|
|
179
|
+
json(): Promise<unknown>;
|
|
180
|
+
}
|
|
181
|
+
interface WebSocketHead {
|
|
182
|
+
status: number;
|
|
183
|
+
headers: [string, string][];
|
|
184
|
+
url: string;
|
|
185
|
+
subprotocol: string;
|
|
186
|
+
extensions: string;
|
|
187
|
+
remote: string;
|
|
188
|
+
}
|
|
189
|
+
/** An open WebSocket. Messages arrive whole: a text message as a string, a binary one as bytes. */
|
|
190
|
+
export declare class WebSocketConnection implements AsyncIterable<string | Uint8Array> {
|
|
191
|
+
#private;
|
|
192
|
+
/** 101 over HTTP/1.1, 200 over HTTP/2. */
|
|
193
|
+
readonly status: number;
|
|
194
|
+
/** Headers of the server's answer to the handshake, in the order it sent them. */
|
|
195
|
+
readonly rawHeaders: ReadonlyArray<readonly [string, string]>;
|
|
196
|
+
readonly url: string;
|
|
197
|
+
/** The subprotocol the server chose, or "". */
|
|
198
|
+
readonly subprotocol: string;
|
|
199
|
+
/** The extensions in use, such as "permessage-deflate". */
|
|
200
|
+
readonly extensions: string;
|
|
201
|
+
readonly remote: string;
|
|
202
|
+
/** Resolves when the socket has ended with a closing handshake or a dropped connection. Rejects when it failed. */
|
|
203
|
+
readonly closed: Promise<WebSocketClose>;
|
|
204
|
+
/** @internal */
|
|
205
|
+
constructor(head: WebSocketHead, socket: net.Socket, closed: Promise<WebSocketClose>);
|
|
206
|
+
get headers(): Headers;
|
|
207
|
+
/** Sends one message: a string as text, bytes as binary. A message sent after the socket has ended is dropped. */
|
|
208
|
+
send(data: string | Uint8Array): void;
|
|
209
|
+
/** The next message, or undefined when the socket has ended. Rejects when the socket failed. */
|
|
210
|
+
receive(): Promise<string | Uint8Array | undefined>;
|
|
211
|
+
[Symbol.asyncIterator](): AsyncGenerator<string | Uint8Array, void, undefined>;
|
|
212
|
+
/** Starts the closing handshake. Resolves, as "closed" does, when the socket has ended. */
|
|
213
|
+
close(code?: number, reason?: string): Promise<WebSocketClose>;
|
|
214
|
+
/** Drops the socket without a closing handshake. */
|
|
215
|
+
abort(): void;
|
|
216
|
+
/** @internal */
|
|
217
|
+
push(message: string | Uint8Array): void;
|
|
218
|
+
/** @internal */
|
|
219
|
+
end(error?: unknown): void;
|
|
220
|
+
}
|
|
221
|
+
export interface SpawnOptions {
|
|
222
|
+
/** Path of the tfrd binary. `icudtl.dat` must sit next to it. */
|
|
223
|
+
binary: string;
|
|
224
|
+
/** `unix:<path>` or `tcp:<host>:<port>`. */
|
|
225
|
+
listen: string;
|
|
226
|
+
/** More switches for the daemon; Chromium's own apply, such as `--fingerprint-tls-profile=chrome-149`. */
|
|
227
|
+
args?: readonly string[];
|
|
228
|
+
/** Where the daemon's log goes. Default "inherit". */
|
|
229
|
+
stderr?: "inherit" | "ignore";
|
|
230
|
+
}
|
|
231
|
+
export declare class Daemon {
|
|
232
|
+
#private;
|
|
233
|
+
readonly address: string;
|
|
234
|
+
private constructor();
|
|
235
|
+
/** Uses a daemon that is already running. */
|
|
236
|
+
static connect(address: string): Daemon;
|
|
237
|
+
/** Starts a daemon and resolves when it accepts connections. `close()` stops it. */
|
|
238
|
+
static spawn(options: SpawnOptions): Promise<Daemon>;
|
|
239
|
+
createSession(options?: SessionOptions): Promise<Session>;
|
|
240
|
+
/** Counts of every session, or of session `id` only. */
|
|
241
|
+
stats(id?: string): Promise<Stats>;
|
|
242
|
+
/** The Chromium version the daemon is built from, such as "157.0.8103.78". */
|
|
243
|
+
chromiumVersion(): Promise<string>;
|
|
244
|
+
/** Stops the daemon when this object started it, and closes idle pooled connections. */
|
|
245
|
+
close(): Promise<void>;
|
|
246
|
+
/** @internal */
|
|
247
|
+
closeSession(id: string): Promise<CloseResult>;
|
|
248
|
+
/** @internal */
|
|
249
|
+
request(session: string, url: string, options: RequestOptions): Promise<Response>;
|
|
250
|
+
/** @internal */
|
|
251
|
+
webSocket(session: string, url: string, options: WebSocketOptions): Promise<WebSocketConnection>;
|
|
252
|
+
}
|
|
253
|
+
export declare class Session {
|
|
254
|
+
#private;
|
|
255
|
+
readonly id: string;
|
|
256
|
+
/** @internal */
|
|
257
|
+
constructor(daemon: Daemon, id: string);
|
|
258
|
+
/** Resolves with the response head; the body streams. Rejects with RequestError when Chromium fails. */
|
|
259
|
+
fetch(url: string | URL, options?: RequestOptions): Promise<Response>;
|
|
260
|
+
/** Opens a WebSocket with the session's connections, proxy and cookies. Rejects with RequestError when the handshake fails. */
|
|
261
|
+
webSocket(url: string | URL, options?: WebSocketOptions): Promise<WebSocketConnection>;
|
|
262
|
+
/** Drops the session's connections and cookies, and returns its final wire totals. */
|
|
263
|
+
close(): Promise<CloseResult>;
|
|
264
|
+
}
|
|
265
|
+
export {};
|