@querying/sneaky 0.1.0 → 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.
@@ -0,0 +1,246 @@
1
+ import { type ActOptions, type ActResult, type ExtractKind, type PdfOptions, type ScreenshotOptions, type SnapshotResult, type Sneaky, type SneakySession, type Target, type WaitUntil } from "../index.js";
2
+ import { type ResolvedHost } from "./host.js";
3
+ export { connectSneakyClient, loadSneakyConfig, resolveHostConfig, sneakyHomeDir } from "./host.js";
4
+ export type { ConnectClientOptions, ResolvedHost, SavedConfig, SavedHostConfig } from "./host.js";
5
+ export { transformReplCode } from "./transform.js";
6
+ export interface DisplayedImage {
7
+ path: string;
8
+ mimeType: string;
9
+ base64: string;
10
+ bytes: number;
11
+ label?: string;
12
+ }
13
+ export interface ReplSnapshotOptions {
14
+ interactive?: boolean;
15
+ full?: boolean;
16
+ compact?: boolean;
17
+ showHidden?: boolean;
18
+ ref?: string;
19
+ selector?: string;
20
+ maxNodes?: number;
21
+ maxChars?: number;
22
+ diff?: boolean;
23
+ source?: "dom" | "ax";
24
+ }
25
+ export interface ReplSnapshotResult {
26
+ tree: string;
27
+ diff: string | null;
28
+ rawDiff?: SnapshotResult["diff"];
29
+ snapshotId: string;
30
+ refCount: number;
31
+ refs: SnapshotResult["refs"];
32
+ page: SnapshotResult["page"];
33
+ truncated: boolean;
34
+ }
35
+ export interface AnnotatedScreenshotResult {
36
+ buffer: Buffer;
37
+ base64: string;
38
+ mimeType: string;
39
+ format: string;
40
+ annotationCount: number;
41
+ annotations: Array<{
42
+ ref: string;
43
+ x: number;
44
+ y: number;
45
+ width: number;
46
+ height: number;
47
+ }>;
48
+ }
49
+ export interface ReplRunResult {
50
+ ok: boolean;
51
+ stdout: string;
52
+ stderr: string;
53
+ result?: unknown;
54
+ resultFormatted?: string;
55
+ displayed: DisplayedImage[];
56
+ error?: string;
57
+ durationMs: number;
58
+ }
59
+ interface ReplHostCallbacks {
60
+ ensureTabActive(targetId: string): Promise<void>;
61
+ onTabClosed(targetId: string): void;
62
+ snapshotPage(page: ReplPage, opts?: ReplSnapshotOptions): Promise<ReplSnapshotResult>;
63
+ }
64
+ export declare class ReplLocator {
65
+ private readonly page;
66
+ private readonly target;
67
+ constructor(page: ReplPage, target: Target);
68
+ first(): ReplLocator;
69
+ last(): ReplLocator;
70
+ nth(index: number): ReplLocator;
71
+ click(options?: ActOptions & {
72
+ button?: "left" | "right" | "middle";
73
+ clickCount?: number;
74
+ }): Promise<ActResult>;
75
+ dblclick(options?: ActOptions): Promise<ActResult>;
76
+ hover(options?: ActOptions): Promise<ActResult>;
77
+ fill(text: string, options?: ActOptions & {
78
+ clear?: boolean;
79
+ }): Promise<ActResult>;
80
+ type(text: string, options?: ActOptions): Promise<ActResult>;
81
+ press(key: string, options?: ActOptions): Promise<ActResult>;
82
+ selectOption(valueOrOpt: string | {
83
+ value?: string;
84
+ label?: string;
85
+ }, options?: ActOptions): Promise<ActResult>;
86
+ waitFor(options?: {
87
+ timeout?: number;
88
+ }): Promise<ActResult>;
89
+ textContent(): Promise<string | null>;
90
+ innerText(): Promise<string | null>;
91
+ innerHTML(): Promise<string | null>;
92
+ outerHTML(): Promise<string | null>;
93
+ inputValue(): Promise<string | null>;
94
+ getAttribute(name: string): Promise<string | null>;
95
+ isVisible(): Promise<boolean>;
96
+ isEnabled(): Promise<boolean>;
97
+ isChecked(): Promise<boolean>;
98
+ count(): Promise<number>;
99
+ boundingBox(): Promise<{
100
+ x: number;
101
+ y: number;
102
+ width: number;
103
+ height: number;
104
+ } | null>;
105
+ allTextContents(): Promise<string[]>;
106
+ allInnerTexts(): Promise<string[]>;
107
+ screenshot(options?: Omit<ScreenshotOptions, "target"> & {
108
+ path?: string;
109
+ }): Promise<Buffer>;
110
+ }
111
+ export declare class ReplPage {
112
+ readonly session: SneakySession;
113
+ readonly targetId: string;
114
+ private readonly host;
115
+ private currentUrl;
116
+ private currentTitle;
117
+ readonly keyboard: {
118
+ press: (key: string) => Promise<ActResult>;
119
+ type: (text: string, options?: ActOptions) => Promise<ActResult>;
120
+ };
121
+ readonly mouse: {
122
+ click: (x: number, y: number, options?: {
123
+ button?: "left" | "right" | "middle";
124
+ clickCount?: number;
125
+ speed?: "fast" | "natural" | "stealth";
126
+ }) => Promise<ActResult>;
127
+ move: (x: number, y: number, options?: ActOptions) => Promise<ActResult>;
128
+ wheel: (dx: number, dy: number) => Promise<ActResult>;
129
+ };
130
+ constructor(session: SneakySession, targetId: string, host: ReplHostCallbacks, initialMeta?: {
131
+ url?: string;
132
+ title?: string;
133
+ });
134
+ /** Internal: activates this tab on the daemon if it is not already the front tab. */
135
+ ensureActive(): Promise<void>;
136
+ /** Internal: updates cached URL/title from daemon responses. */
137
+ _updateMeta(url?: string, title?: string): void;
138
+ url(): string;
139
+ title(): Promise<string>;
140
+ goto(url: string, options?: {
141
+ waitUntil?: WaitUntil;
142
+ timeout?: number;
143
+ }): Promise<{
144
+ url: string;
145
+ title: string;
146
+ ready_state: string;
147
+ duration_ms: number;
148
+ }>;
149
+ reload(options?: {
150
+ waitUntil?: WaitUntil;
151
+ timeout?: number;
152
+ }): Promise<ActResult>;
153
+ goBack(): Promise<ActResult>;
154
+ goForward(): Promise<ActResult>;
155
+ content(): Promise<string>;
156
+ /** Evaluates a function or JS expression in the page's main world WITHOUT calling Runtime.enable. */
157
+ evaluate<T = unknown>(fnOrExpr: string | ((...args: never[]) => T | Promise<T>), arg?: unknown): Promise<T>;
158
+ setViewportSize(size: {
159
+ width: number;
160
+ height: number;
161
+ deviceScaleFactor?: number;
162
+ mobile?: boolean;
163
+ }): Promise<import("../index.js").ViewportResult>;
164
+ screenshot(options?: ScreenshotOptions & {
165
+ path?: string;
166
+ }): Promise<Buffer>;
167
+ pdf(options?: PdfOptions & {
168
+ path?: string;
169
+ }): Promise<Buffer>;
170
+ extract(options?: {
171
+ kind?: ExtractKind;
172
+ selector?: string;
173
+ maxChars?: number;
174
+ }): Promise<Record<string, unknown>>;
175
+ snapshot(options?: ReplSnapshotOptions): Promise<ReplSnapshotResult>;
176
+ waitForTimeout(ms: number): Promise<void>;
177
+ waitForSelector(selectorOrRef: string, options?: {
178
+ timeout?: number;
179
+ }): Promise<ActResult>;
180
+ waitForURL(urlSubstring: string, options?: {
181
+ timeout?: number;
182
+ }): Promise<ActResult>;
183
+ bringToFront(): Promise<void>;
184
+ close(): Promise<void>;
185
+ locator(selectorOrRef: string): ReplLocator;
186
+ getByRole(role: string, options?: {
187
+ name?: string;
188
+ exact?: boolean;
189
+ }): ReplLocator;
190
+ getByText(text: string, options?: {
191
+ exact?: boolean;
192
+ }): ReplLocator;
193
+ getByLabel(label: string, options?: {
194
+ exact?: boolean;
195
+ }): ReplLocator;
196
+ getByPlaceholder(placeholder: string, options?: {
197
+ exact?: boolean;
198
+ }): ReplLocator;
199
+ toString(): string;
200
+ }
201
+ export interface ConnectReplOptions {
202
+ profile?: string;
203
+ incognito?: boolean;
204
+ host?: string;
205
+ baseUrl?: string;
206
+ authToken?: string;
207
+ apiKey?: string;
208
+ remote?: boolean;
209
+ headful?: boolean;
210
+ headless?: boolean;
211
+ autoStartLocal?: boolean;
212
+ artifactDir?: string;
213
+ homeDir?: string;
214
+ }
215
+ export declare class SneakyReplSession {
216
+ readonly client: Sneaky;
217
+ readonly session: SneakySession;
218
+ readonly profileId: string;
219
+ readonly host: ResolvedHost;
220
+ readonly ephemeral: boolean;
221
+ private context;
222
+ private activeTargetId;
223
+ private attachedTabs;
224
+ private lastSnapshotByTab;
225
+ private turnStdout;
226
+ private turnStderr;
227
+ private turnDisplayed;
228
+ private displaySeq;
229
+ readonly artifactDir: string;
230
+ constructor(client: Sneaky, session: SneakySession, profileId: string, host: ResolvedHost, ephemeral: boolean, artifactDir?: string);
231
+ static connect(options?: ConnectReplOptions): Promise<SneakyReplSession>;
232
+ private readonly hostCallbacks;
233
+ private syncTabsGlobal;
234
+ private attachOrReuse;
235
+ private takeSnapshot;
236
+ private replFetch;
237
+ private recordDisplay;
238
+ /** Reinitializes the JS vm.Context cleanly (starts neutral with page = null and empty tabs). */
239
+ resetContext(): void;
240
+ /** Executes JS code in the persistent vm.Context, returning stdout/stderr, return value, and displayed images. */
241
+ run(code: string, options?: {
242
+ timeoutMs?: number;
243
+ }): Promise<ReplRunResult>;
244
+ /** Closes WS RPC; if this session is ephemeral (--incognito or cloud), also closes the browser session. */
245
+ close(): Promise<void>;
246
+ }