@querying/sneaky 0.0.0-stage → 0.1.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 +159 -2
- package/bin/sneaky-mcp.mjs +36 -0
- package/bin/sneaky.mjs +36 -0
- package/dist/agent/index.d.ts +275 -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 +319 -0
- package/dist/index.js +511 -0
- package/dist/index.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 +79 -4
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { CDPConnection, SneakyCDPSession } from "./cdp.js";
|
|
3
|
+
import { type FramePageHost, type ScreenshotOptions, SneakyElementHandle, SneakyFrame, SneakyLocator, type WaitForOptions } from "./frame.js";
|
|
4
|
+
import { type LaunchOptions, type LaunchedBrowserProcess, type ProxyOptions } from "./launcher.js";
|
|
5
|
+
export type WaitUntilState = "commit" | "domcontentloaded" | "load" | "networkidle";
|
|
6
|
+
export interface ContextOptions {
|
|
7
|
+
userAgent?: string;
|
|
8
|
+
viewport?: {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
} | null;
|
|
12
|
+
locale?: string;
|
|
13
|
+
timezoneId?: string;
|
|
14
|
+
extraHTTPHeaders?: Record<string, string>;
|
|
15
|
+
ignoreHTTPSErrors?: boolean;
|
|
16
|
+
bypassCSP?: boolean;
|
|
17
|
+
serviceWorkers?: "allow" | "block";
|
|
18
|
+
acceptDownloads?: boolean;
|
|
19
|
+
colorScheme?: "light" | "dark" | "no-preference" | "null";
|
|
20
|
+
reducedMotion?: "reduce" | "no-preference" | "null";
|
|
21
|
+
proxy?: ProxyOptions;
|
|
22
|
+
deviceScaleFactor?: number;
|
|
23
|
+
isMobile?: boolean;
|
|
24
|
+
hasTouch?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface Cookie {
|
|
27
|
+
name: string;
|
|
28
|
+
value: string;
|
|
29
|
+
url?: string;
|
|
30
|
+
domain?: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
expires?: number;
|
|
33
|
+
httpOnly?: boolean;
|
|
34
|
+
secure?: boolean;
|
|
35
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
36
|
+
}
|
|
37
|
+
export interface PDFOptions {
|
|
38
|
+
format?: string;
|
|
39
|
+
width?: string | number;
|
|
40
|
+
height?: string | number;
|
|
41
|
+
landscape?: boolean;
|
|
42
|
+
printBackground?: boolean;
|
|
43
|
+
preferCSSPageSize?: boolean;
|
|
44
|
+
scale?: number;
|
|
45
|
+
displayHeaderFooter?: boolean;
|
|
46
|
+
headerTemplate?: string;
|
|
47
|
+
footerTemplate?: string;
|
|
48
|
+
pageRanges?: string;
|
|
49
|
+
margin?: {
|
|
50
|
+
top?: string | number;
|
|
51
|
+
right?: string | number;
|
|
52
|
+
bottom?: string | number;
|
|
53
|
+
left?: string | number;
|
|
54
|
+
};
|
|
55
|
+
path?: string;
|
|
56
|
+
}
|
|
57
|
+
export type RouteMatcher = string | RegExp | ((url: URL) => boolean);
|
|
58
|
+
export interface RouteFulfillOptions {
|
|
59
|
+
status?: number;
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
contentType?: string;
|
|
62
|
+
body?: string | Buffer;
|
|
63
|
+
}
|
|
64
|
+
export interface RouteContinueOptions {
|
|
65
|
+
url?: string;
|
|
66
|
+
method?: string;
|
|
67
|
+
headers?: Record<string, string>;
|
|
68
|
+
postData?: string | Buffer;
|
|
69
|
+
}
|
|
70
|
+
export declare class SneakyRequest {
|
|
71
|
+
private readonly data;
|
|
72
|
+
constructor(data: {
|
|
73
|
+
url: string;
|
|
74
|
+
method: string;
|
|
75
|
+
resourceType: string;
|
|
76
|
+
headers: Record<string, string>;
|
|
77
|
+
postData?: string;
|
|
78
|
+
frame: SneakyFrame | null;
|
|
79
|
+
isNavigation: boolean;
|
|
80
|
+
failureText?: string;
|
|
81
|
+
redirectedFrom?: SneakyRequest | null;
|
|
82
|
+
});
|
|
83
|
+
url(): string;
|
|
84
|
+
method(): string;
|
|
85
|
+
resourceType(): string;
|
|
86
|
+
headers(): Record<string, string>;
|
|
87
|
+
allHeaders(): Promise<Record<string, string>>;
|
|
88
|
+
postData(): string | null;
|
|
89
|
+
frame(): SneakyFrame;
|
|
90
|
+
isNavigationRequest(): boolean;
|
|
91
|
+
redirectedFrom(): SneakyRequest | null;
|
|
92
|
+
failure(): {
|
|
93
|
+
errorText: string;
|
|
94
|
+
} | null;
|
|
95
|
+
}
|
|
96
|
+
export declare class SneakyResponse {
|
|
97
|
+
private readonly cdp;
|
|
98
|
+
private readonly sessionId;
|
|
99
|
+
private readonly data;
|
|
100
|
+
constructor(cdp: CDPConnection, sessionId: string, data: {
|
|
101
|
+
requestId: string;
|
|
102
|
+
url: string;
|
|
103
|
+
status: number;
|
|
104
|
+
statusText: string;
|
|
105
|
+
headers: Record<string, string>;
|
|
106
|
+
request: SneakyRequest;
|
|
107
|
+
});
|
|
108
|
+
url(): string;
|
|
109
|
+
status(): number;
|
|
110
|
+
statusText(): string;
|
|
111
|
+
ok(): boolean;
|
|
112
|
+
headers(): Record<string, string>;
|
|
113
|
+
allHeaders(): Promise<Record<string, string>>;
|
|
114
|
+
request(): SneakyRequest;
|
|
115
|
+
frame(): SneakyFrame;
|
|
116
|
+
body(): Promise<Buffer>;
|
|
117
|
+
text(): Promise<string>;
|
|
118
|
+
json<T = unknown>(): Promise<T>;
|
|
119
|
+
}
|
|
120
|
+
export declare class SneakyRoute {
|
|
121
|
+
private readonly cdp;
|
|
122
|
+
private readonly sessionId;
|
|
123
|
+
private readonly fetchRequestId;
|
|
124
|
+
private readonly req;
|
|
125
|
+
private handled;
|
|
126
|
+
constructor(cdp: CDPConnection, sessionId: string, fetchRequestId: string, req: SneakyRequest);
|
|
127
|
+
request(): SneakyRequest;
|
|
128
|
+
isHandled(): boolean;
|
|
129
|
+
fulfill(options?: RouteFulfillOptions): Promise<void>;
|
|
130
|
+
continue(options?: RouteContinueOptions): Promise<void>;
|
|
131
|
+
abort(errorCode?: string): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
export declare class SneakyDialog {
|
|
134
|
+
private readonly cdp;
|
|
135
|
+
private readonly sessionId;
|
|
136
|
+
private readonly info;
|
|
137
|
+
private handled;
|
|
138
|
+
constructor(cdp: CDPConnection, sessionId: string, info: {
|
|
139
|
+
type: string;
|
|
140
|
+
message: string;
|
|
141
|
+
defaultPrompt?: string;
|
|
142
|
+
});
|
|
143
|
+
type(): string;
|
|
144
|
+
message(): string;
|
|
145
|
+
defaultValue(): string;
|
|
146
|
+
accept(promptText?: string): Promise<void>;
|
|
147
|
+
dismiss(): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
export declare class SneakyMouse {
|
|
150
|
+
private readonly cdp;
|
|
151
|
+
private readonly sessionId;
|
|
152
|
+
private readonly beforeDown?;
|
|
153
|
+
private x;
|
|
154
|
+
private y;
|
|
155
|
+
private buttons;
|
|
156
|
+
constructor(cdp: CDPConnection, sessionId: string, beforeDown?: (() => Promise<void>) | undefined);
|
|
157
|
+
private buttonMask;
|
|
158
|
+
move(x: number, y: number, options?: {
|
|
159
|
+
steps?: number;
|
|
160
|
+
}): Promise<void>;
|
|
161
|
+
down(options?: {
|
|
162
|
+
button?: "left" | "right" | "middle";
|
|
163
|
+
clickCount?: number;
|
|
164
|
+
}): Promise<void>;
|
|
165
|
+
up(options?: {
|
|
166
|
+
button?: "left" | "right" | "middle";
|
|
167
|
+
clickCount?: number;
|
|
168
|
+
}): Promise<void>;
|
|
169
|
+
click(x: number, y: number, options?: {
|
|
170
|
+
button?: "left" | "right" | "middle";
|
|
171
|
+
clickCount?: number;
|
|
172
|
+
delay?: number;
|
|
173
|
+
}): Promise<void>;
|
|
174
|
+
dblclick(x: number, y: number, options?: {
|
|
175
|
+
button?: "left" | "right" | "middle";
|
|
176
|
+
delay?: number;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
wheel(deltaX: number, deltaY: number): Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
export declare class SneakyKeyboard {
|
|
181
|
+
private readonly cdp;
|
|
182
|
+
private readonly sessionId;
|
|
183
|
+
private readonly beforeDown?;
|
|
184
|
+
private modifiers;
|
|
185
|
+
constructor(cdp: CDPConnection, sessionId: string, beforeDown?: (() => Promise<void>) | undefined);
|
|
186
|
+
down(key: string): Promise<void>;
|
|
187
|
+
up(key: string): Promise<void>;
|
|
188
|
+
press(combo: string, options?: {
|
|
189
|
+
delay?: number;
|
|
190
|
+
}): Promise<void>;
|
|
191
|
+
type(text: string, options?: {
|
|
192
|
+
delay?: number;
|
|
193
|
+
}): Promise<void>;
|
|
194
|
+
insertText(text: string): Promise<void>;
|
|
195
|
+
}
|
|
196
|
+
export declare class SneakyWebSocketRoute {
|
|
197
|
+
private readonly rawUrl;
|
|
198
|
+
private closed;
|
|
199
|
+
constructor(rawUrl: string);
|
|
200
|
+
url(): string;
|
|
201
|
+
close(_options?: {
|
|
202
|
+
code?: number;
|
|
203
|
+
reason?: string;
|
|
204
|
+
}): Promise<void>;
|
|
205
|
+
isClosed(): boolean;
|
|
206
|
+
}
|
|
207
|
+
type RouteEntry = {
|
|
208
|
+
matcher: RouteMatcher;
|
|
209
|
+
handler: (route: SneakyRoute, request: SneakyRequest) => void | Promise<void>;
|
|
210
|
+
};
|
|
211
|
+
export declare class SneakyPage extends EventEmitter implements FramePageHost {
|
|
212
|
+
private readonly ctx;
|
|
213
|
+
readonly cdp: CDPConnection;
|
|
214
|
+
readonly targetId: string;
|
|
215
|
+
readonly sessionId: string;
|
|
216
|
+
readonly mouse: SneakyMouse;
|
|
217
|
+
readonly keyboard: SneakyKeyboard;
|
|
218
|
+
defaultTimeoutMs: number;
|
|
219
|
+
defaultNavigationTimeoutMs: number;
|
|
220
|
+
private closed;
|
|
221
|
+
private viewport;
|
|
222
|
+
private deviceScaleFactor;
|
|
223
|
+
private isMobile;
|
|
224
|
+
private readonly framesMap;
|
|
225
|
+
private readonly oopifSessions;
|
|
226
|
+
private readonly oopifSettles;
|
|
227
|
+
private readonly routes;
|
|
228
|
+
private fetchEnabled;
|
|
229
|
+
private readonly inflight;
|
|
230
|
+
private lastNetworkDone;
|
|
231
|
+
private readonly requestsById;
|
|
232
|
+
private readonly unsubs;
|
|
233
|
+
private rootFrameId;
|
|
234
|
+
constructor(ctx: SneakyContext, cdp: CDPConnection, targetId: string, sessionId: string, initialViewport: {
|
|
235
|
+
width: number;
|
|
236
|
+
height: number;
|
|
237
|
+
} | null);
|
|
238
|
+
private awaitOOPIFHitTest;
|
|
239
|
+
/** Internal bootstrap: enables Page/Network/OOPIF auto-attach (NEVER Runtime.enable). */
|
|
240
|
+
init(contextOpts: ContextOptions, initScripts: string[], proxyAuth?: {
|
|
241
|
+
username: string;
|
|
242
|
+
password: string;
|
|
243
|
+
}): Promise<void>;
|
|
244
|
+
private attachOOPIF;
|
|
245
|
+
private ingestFrameTree;
|
|
246
|
+
private bindSessionEvents;
|
|
247
|
+
private handleFetchPaused;
|
|
248
|
+
/** Internal: enable or disable CDP Fetch domain based on registered routes or proxy auth. */
|
|
249
|
+
syncFetchInterception(proxyAuth?: {
|
|
250
|
+
username: string;
|
|
251
|
+
password: string;
|
|
252
|
+
}): Promise<void>;
|
|
253
|
+
context(): SneakyContext;
|
|
254
|
+
isClosed(): boolean;
|
|
255
|
+
setDefaultTimeout(timeout: number): void;
|
|
256
|
+
setDefaultNavigationTimeout(timeout: number): void;
|
|
257
|
+
viewportSize(): {
|
|
258
|
+
width: number;
|
|
259
|
+
height: number;
|
|
260
|
+
} | null;
|
|
261
|
+
setViewportSize(size: {
|
|
262
|
+
width: number;
|
|
263
|
+
height: number;
|
|
264
|
+
}): Promise<void>;
|
|
265
|
+
mainFrame(): SneakyFrame;
|
|
266
|
+
frames(): SneakyFrame[];
|
|
267
|
+
frameById(frameId: string): SneakyFrame | undefined;
|
|
268
|
+
childFramesOf(frameId: string): SneakyFrame[];
|
|
269
|
+
url(): string;
|
|
270
|
+
title(): Promise<string>;
|
|
271
|
+
content(): Promise<string>;
|
|
272
|
+
setContent(html: string, options?: {
|
|
273
|
+
waitUntil?: WaitUntilState;
|
|
274
|
+
timeout?: number;
|
|
275
|
+
}): Promise<void>;
|
|
276
|
+
private prepareLoadWait;
|
|
277
|
+
goto(url: string, options?: {
|
|
278
|
+
waitUntil?: WaitUntilState;
|
|
279
|
+
timeout?: number;
|
|
280
|
+
}): Promise<SneakyResponse | null>;
|
|
281
|
+
reload(options?: {
|
|
282
|
+
waitUntil?: WaitUntilState;
|
|
283
|
+
timeout?: number;
|
|
284
|
+
}): Promise<void>;
|
|
285
|
+
waitForLoadState(state?: WaitUntilState, options?: {
|
|
286
|
+
timeout?: number;
|
|
287
|
+
}): Promise<void>;
|
|
288
|
+
waitForTimeout(ms: number): Promise<void>;
|
|
289
|
+
addInitScript(fn: string | ((...args: never[]) => unknown), arg?: unknown): Promise<void>;
|
|
290
|
+
addStyleTag(options: {
|
|
291
|
+
content?: string;
|
|
292
|
+
url?: string;
|
|
293
|
+
}): Promise<void>;
|
|
294
|
+
emulateMedia(options: {
|
|
295
|
+
media?: "screen" | "print" | null;
|
|
296
|
+
colorScheme?: string | null;
|
|
297
|
+
reducedMotion?: string | null;
|
|
298
|
+
}): Promise<void>;
|
|
299
|
+
route(matcher: RouteMatcher, handler: (route: SneakyRoute, request: SneakyRequest) => void | Promise<void>): Promise<void>;
|
|
300
|
+
unroute(matcher: RouteMatcher, handler?: (route: SneakyRoute, request: SneakyRequest) => void | Promise<void>): Promise<void>;
|
|
301
|
+
unrouteAll(_options?: {
|
|
302
|
+
behavior?: "default" | "ignoreErrors" | "wait";
|
|
303
|
+
}): Promise<void>;
|
|
304
|
+
routeWebSocket(matcher: RouteMatcher, _handler: (ws: SneakyWebSocketRoute) => void | Promise<void>): Promise<void>;
|
|
305
|
+
evaluate<R = unknown, A = unknown>(fn: string | ((arg: A) => R | Promise<R>), arg?: A): Promise<R>;
|
|
306
|
+
locator(selector: string): SneakyLocator;
|
|
307
|
+
getByRole(role: string, options?: {
|
|
308
|
+
name?: string;
|
|
309
|
+
exact?: boolean;
|
|
310
|
+
}): SneakyLocator;
|
|
311
|
+
getByText(text: string, options?: {
|
|
312
|
+
exact?: boolean;
|
|
313
|
+
}): SneakyLocator;
|
|
314
|
+
getByLabel(text: string): SneakyLocator;
|
|
315
|
+
$(selector: string): Promise<SneakyElementHandle | null>;
|
|
316
|
+
$$(selector: string): Promise<SneakyElementHandle[]>;
|
|
317
|
+
waitForSelector(selector: string, options?: WaitForOptions): Promise<SneakyElementHandle | null>;
|
|
318
|
+
waitForFunction<R = unknown, A = unknown>(fn: string | ((arg: A) => R | Promise<R>), arg?: A, options?: {
|
|
319
|
+
timeout?: number;
|
|
320
|
+
polling?: number;
|
|
321
|
+
}): Promise<R>;
|
|
322
|
+
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
|
|
323
|
+
pdf(options?: PDFOptions): Promise<Buffer>;
|
|
324
|
+
private markClosed;
|
|
325
|
+
close(): Promise<void>;
|
|
326
|
+
}
|
|
327
|
+
export declare class SneakyContext extends EventEmitter {
|
|
328
|
+
private readonly browser;
|
|
329
|
+
private readonly cdp;
|
|
330
|
+
readonly browserContextId: string | undefined;
|
|
331
|
+
private readonly options;
|
|
332
|
+
defaultTimeoutMs: number;
|
|
333
|
+
readonly contextRoutes: RouteEntry[];
|
|
334
|
+
readonly proxyAuth?: {
|
|
335
|
+
username: string;
|
|
336
|
+
password: string;
|
|
337
|
+
};
|
|
338
|
+
private readonly initScripts;
|
|
339
|
+
private readonly pageList;
|
|
340
|
+
private closed;
|
|
341
|
+
constructor(browser: SneakyBrowser, cdp: CDPConnection, browserContextId: string | undefined, options: ContextOptions, proxyAuth?: {
|
|
342
|
+
username: string;
|
|
343
|
+
password: string;
|
|
344
|
+
});
|
|
345
|
+
pages(): SneakyPage[];
|
|
346
|
+
removePage(p: SneakyPage): void;
|
|
347
|
+
setDefaultTimeout(timeout: number): void;
|
|
348
|
+
setDefaultNavigationTimeout(timeout: number): void;
|
|
349
|
+
addInitScript(fn: string | ((...args: never[]) => unknown), arg?: unknown): Promise<void>;
|
|
350
|
+
route(matcher: RouteMatcher, handler: (route: SneakyRoute, request: SneakyRequest) => void | Promise<void>): Promise<void>;
|
|
351
|
+
routeWebSocket(matcher: RouteMatcher, _handler: (ws: SneakyWebSocketRoute) => void | Promise<void>): Promise<void>;
|
|
352
|
+
unroute(matcher: RouteMatcher, handler?: (route: SneakyRoute, request: SneakyRequest) => void | Promise<void>): Promise<void>;
|
|
353
|
+
newPage(): Promise<SneakyPage>;
|
|
354
|
+
attachPageTarget(targetId: string): Promise<SneakyPage>;
|
|
355
|
+
attachExistingPageTarget(targetId: string, sessionId: string): Promise<SneakyPage>;
|
|
356
|
+
/** Creates a direct CDP session attached to a Page or cross-origin OOPIF Frame target. */
|
|
357
|
+
newCDPSession(pageOrFrame: SneakyPage | SneakyFrame): Promise<SneakyCDPSession>;
|
|
358
|
+
cookies(urls?: string | string[]): Promise<Cookie[]>;
|
|
359
|
+
addCookies(cookies: Cookie[]): Promise<void>;
|
|
360
|
+
clearCookies(): Promise<void>;
|
|
361
|
+
close(): Promise<void>;
|
|
362
|
+
}
|
|
363
|
+
export declare class SneakyBrowser extends EventEmitter {
|
|
364
|
+
readonly cdp: CDPConnection;
|
|
365
|
+
private readonly proc?;
|
|
366
|
+
private readonly contextList;
|
|
367
|
+
private closed;
|
|
368
|
+
private versionStr;
|
|
369
|
+
constructor(cdp: CDPConnection, proc?: LaunchedBrowserProcess | undefined);
|
|
370
|
+
init(): Promise<void>;
|
|
371
|
+
version(): string;
|
|
372
|
+
isConnected(): boolean;
|
|
373
|
+
contexts(): SneakyContext[];
|
|
374
|
+
removeContext(ctx: SneakyContext): void;
|
|
375
|
+
newContext(options?: ContextOptions): Promise<SneakyContext>;
|
|
376
|
+
/** Attaches to the default browser context (for launchPersistentContext or connectOverCDP). */
|
|
377
|
+
defaultContext(options?: ContextOptions): Promise<SneakyContext>;
|
|
378
|
+
newPage(options?: ContextOptions): Promise<SneakyPage>;
|
|
379
|
+
close(): Promise<void>;
|
|
380
|
+
}
|
|
381
|
+
export declare function launch(options?: LaunchOptions): Promise<SneakyBrowser>;
|
|
382
|
+
export declare function launchPersistentContext(userDataDir: string, options?: LaunchOptions): Promise<SneakyContext>;
|
|
383
|
+
export declare function connectOverCDP(endpointUrl: string): Promise<SneakyBrowser>;
|
|
384
|
+
/** Drop-in Playwright `chromium` object powered by sneaky-agent's zero-Runtime.enable stealth CDP driver. */
|
|
385
|
+
export declare const chromium: {
|
|
386
|
+
launch: typeof launch;
|
|
387
|
+
launchPersistentContext: typeof launchPersistentContext;
|
|
388
|
+
connectOverCDP: typeof connectOverCDP;
|
|
389
|
+
use(_plugin: unknown): /*elided*/ any;
|
|
390
|
+
};
|
|
391
|
+
export {};
|