@d0nj/dsh-browser 0.0.0-stage → 0.1.1

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/dist/tab.d.ts ADDED
@@ -0,0 +1,183 @@
1
+ /**
2
+ * One browser tab, driven over CDP.
3
+ *
4
+ * Every mutating operation follows the same shape: resolve the target, check it
5
+ * is actually visible, perform the action with real input events, wait for the
6
+ * document to settle, and invalidate refs when the document was replaced.
7
+ *
8
+ * @module @d0nj/dsh-browser/tab
9
+ */
10
+ import type { CdpClient } from './cdp.js';
11
+ import { ConsoleBuffer } from './console.js';
12
+ import type { SnapshotResult } from './snapshot.js';
13
+ /** How a tab behaves. */
14
+ export interface TabSettings {
15
+ readonly viewport: {
16
+ readonly width: number;
17
+ readonly height: number;
18
+ };
19
+ readonly dialogs: 'accept' | 'dismiss';
20
+ readonly navigateTimeoutMs: number;
21
+ }
22
+ /** What to operate on: a snapshot ref, or a CSS selector as the escape hatch. */
23
+ export interface ElementTarget {
24
+ readonly ref?: string | undefined;
25
+ readonly selector?: string | undefined;
26
+ }
27
+ /** Upload a browser-style click or keyboard key name. */
28
+ export type MouseButton = 'left' | 'right' | 'middle';
29
+ /** A captured PNG screenshot. */
30
+ export interface TabScreenshot {
31
+ readonly data: Buffer;
32
+ readonly width: number;
33
+ readonly height: number;
34
+ }
35
+ /** Page identity. */
36
+ export interface PageInfo {
37
+ readonly url: string;
38
+ readonly title: string;
39
+ }
40
+ /**
41
+ * Normalize model-supplied link text into an absolute URL.
42
+ * @param input - absolute URL, bare host, or `localhost:port`.
43
+ * @returns the URL to navigate to.
44
+ */
45
+ export declare function normalizeUrl(input: string): string;
46
+ /**
47
+ * Interpret a model-supplied selector, accepting the ref spellings agents copy
48
+ * out of a snapshot (`e12`, `@e12`, `aria-ref=e12`).
49
+ * @param selector - raw selector text.
50
+ * @returns the ref it names, when it names one.
51
+ */
52
+ export declare function refFromSelector(selector: string): string | undefined;
53
+ /** One attached tab. */
54
+ export declare class Tab {
55
+ #private;
56
+ readonly name: string;
57
+ readonly targetId: string;
58
+ readonly sessionId: string;
59
+ private constructor();
60
+ /**
61
+ * Attach to one page target and enable the domains this tab uses.
62
+ * @param cdp - browser-level connection.
63
+ * @param targetId - page target to attach to.
64
+ * @param name - tab name the model addresses.
65
+ * @param settings - viewport, dialogs, and timeouts.
66
+ * @returns the ready tab.
67
+ */
68
+ static attach(cdp: CdpClient, targetId: string, name: string, settings: TabSettings): Promise<Tab>;
69
+ /** Whether the tab can still be used. */
70
+ get closed(): boolean;
71
+ /** The tab's captured console and page errors. */
72
+ get consoleBuffer(): ConsoleBuffer;
73
+ /** Detach and stop listening. */
74
+ dispose(): Promise<void>;
75
+ /**
76
+ * Evaluate one expression in the page.
77
+ * @param expression - JavaScript expression.
78
+ * @param timeoutMs - execution budget.
79
+ * @returns the deserialized value.
80
+ */
81
+ evaluate<T = unknown>(expression: string, timeoutMs?: number): Promise<T>;
82
+ /**
83
+ * Current URL and title.
84
+ * @returns page identity, or empty strings when the page is unreachable.
85
+ */
86
+ info(): Promise<PageInfo>;
87
+ /**
88
+ * Navigate the tab.
89
+ * @param input - URL, bare host, or localhost address.
90
+ * @param timeoutMs - load budget.
91
+ * @returns the committed URL.
92
+ */
93
+ navigate(input: string, timeoutMs?: number): Promise<string>;
94
+ /** Go back one history entry. */
95
+ back(timeoutMs?: number): Promise<void>;
96
+ /** Go forward one history entry. */
97
+ forward(timeoutMs?: number): Promise<void>;
98
+ /** Reload the current document. */
99
+ reload(timeoutMs?: number): Promise<void>;
100
+ /**
101
+ * Click an element with real mouse events at its centre.
102
+ * @param target - snapshot ref or selector.
103
+ * @param options - button and click count.
104
+ */
105
+ click(target: ElementTarget, options?: {
106
+ button?: MouseButton;
107
+ clickCount?: number;
108
+ }): Promise<void>;
109
+ /**
110
+ * Move the pointer over an element without clicking.
111
+ * @param target - snapshot ref or selector.
112
+ */
113
+ hover(target: ElementTarget): Promise<void>;
114
+ /**
115
+ * Focus a field and type into it.
116
+ * @param target - snapshot ref or selector.
117
+ * @param text - text to insert.
118
+ * @param options - `clear` replaces the current value (default true); `submit` presses Enter.
119
+ */
120
+ type(target: ElementTarget, text: string, options?: {
121
+ clear?: boolean;
122
+ submit?: boolean;
123
+ }): Promise<void>;
124
+ /**
125
+ * Press one key or chord in the focused element, or after focusing a target.
126
+ * @param key - chord such as `Enter` or `Control+A`.
127
+ * @param target - element to focus first.
128
+ */
129
+ press(key: string, target?: ElementTarget): Promise<void>;
130
+ /**
131
+ * Focus an element.
132
+ * @param target - snapshot ref or selector.
133
+ */
134
+ focus(target: ElementTarget): Promise<void>;
135
+ /**
136
+ * Choose options in a `<select>`.
137
+ * @param target - snapshot ref or selector naming the select element.
138
+ * @param values - option values or labels.
139
+ * @returns the labels that ended up selected.
140
+ */
141
+ select(target: ElementTarget, values: readonly string[]): Promise<string[]>;
142
+ /**
143
+ * Scroll the page with a mouse wheel.
144
+ * @param options - direction, wheel notches, and optionally an element to aim at.
145
+ */
146
+ scroll(options?: {
147
+ amount?: number;
148
+ up?: boolean;
149
+ target?: ElementTarget;
150
+ }): Promise<void>;
151
+ /**
152
+ * Wait for text or a selector to appear.
153
+ * @param options - condition and budget.
154
+ * @returns what was observed, or throws when the budget expires.
155
+ */
156
+ waitFor(options: {
157
+ text?: string;
158
+ selector?: string;
159
+ timeoutMs?: number;
160
+ }): Promise<void>;
161
+ /**
162
+ * Read the page as a numbered accessibility outline.
163
+ * @param options - scope selector and budgets.
164
+ * @returns the outline and its ref table, which replaces the previous one.
165
+ */
166
+ snapshot(options?: {
167
+ selector?: string;
168
+ maxChars?: number;
169
+ maxNodes?: number;
170
+ }): Promise<SnapshotResult>;
171
+ /**
172
+ * Capture a PNG.
173
+ * @param options - viewport, full page, or one element.
174
+ * @returns the image bytes and their pixel size.
175
+ */
176
+ screenshot(options?: {
177
+ fullPage?: boolean;
178
+ target?: ElementTarget;
179
+ }): Promise<TabScreenshot>;
180
+ /** The document generation, which advances whenever the page navigates. */
181
+ get documentGeneration(): number;
182
+ }
183
+ //# sourceMappingURL=tab.d.ts.map