@itmetsam/samurai-framework 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/.claude/settings.local.json +7 -0
- package/.env.example +3 -0
- package/.github/actions/setup/action.yml +16 -0
- package/.github/workflows/ci.yml +71 -0
- package/.trunk/configs/.markdownlint.yaml +2 -0
- package/.trunk/configs/.yamllint.yaml +7 -0
- package/.trunk/configs/svgo.config.mjs +14 -0
- package/.trunk/trunk.yaml +34 -0
- package/docs/superpowers/bidi-roadmap.md +60 -0
- package/docs/superpowers/plans/2026-09-29-auto-wait.md +1827 -0
- package/docs/superpowers/plans/2026-09-29-expect.md +1350 -0
- package/docs/superpowers/plans/2026-10-01-ci.md +350 -0
- package/docs/superpowers/plans/2026-10-01-test-api-alignment.md +1821 -0
- package/docs/superpowers/recorder-roadmap.md +52 -0
- package/docs/superpowers/specs/2026-09-29-auto-wait-design.md +185 -0
- package/docs/superpowers/specs/2026-09-29-bidi-foundation-design.md +130 -0
- package/docs/superpowers/specs/2026-09-29-contexts-and-storage-design.md +88 -0
- package/docs/superpowers/specs/2026-09-29-downloads-and-file-dialogs-design.md +94 -0
- package/docs/superpowers/specs/2026-09-29-emulation-design.md +88 -0
- package/docs/superpowers/specs/2026-09-29-expect-design.md +130 -0
- package/docs/superpowers/specs/2026-09-29-locate-nodes-design.md +90 -0
- package/docs/superpowers/specs/2026-09-29-logs-and-errors-design.md +87 -0
- package/docs/superpowers/specs/2026-09-29-navigation-waits-design.md +83 -0
- package/docs/superpowers/specs/2026-09-29-network-data-design.md +78 -0
- package/docs/superpowers/specs/2026-09-29-network-interception-design.md +91 -0
- package/docs/superpowers/specs/2026-09-29-network-tracking-design.md +86 -0
- package/docs/superpowers/specs/2026-09-29-page-api-design.md +90 -0
- package/docs/superpowers/specs/2026-09-29-preload-scripts-design.md +82 -0
- package/docs/superpowers/specs/2026-09-29-script-call-function-design.md +107 -0
- package/docs/superpowers/specs/2026-09-29-set-files-design.md +62 -0
- package/docs/superpowers/specs/2026-09-29-user-prompts-design.md +75 -0
- package/docs/superpowers/specs/2026-10-01-ci-design.md +106 -0
- package/docs/superpowers/specs/2026-10-01-test-api-alignment-design.md +241 -0
- package/package.json +27 -0
- package/public/logo-dark.svg +236 -0
- package/public/logo-light.svg +262 -0
- package/samurai.config.ts +7 -0
- package/src/api.ts +4 -0
- package/src/assert/assertion-error.test.ts +55 -0
- package/src/assert/assertion-error.ts +62 -0
- package/src/assert/expect-locator.test.ts +217 -0
- package/src/assert/expect.test.ts +73 -0
- package/src/assert/expect.ts +299 -0
- package/src/browser/browser-context.browser-test.ts +201 -0
- package/src/browser/browser-context.test.ts +407 -0
- package/src/browser/browser-context.ts +208 -0
- package/src/browser/browser-finder.ts +110 -0
- package/src/browser/browser.test.ts +88 -0
- package/src/browser/browser.ts +515 -0
- package/src/browser/context-tree.test.ts +86 -0
- package/src/browser/context-tree.ts +70 -0
- package/src/browser/dialog.browser-test.ts +144 -0
- package/src/browser/dialog.test.ts +322 -0
- package/src/browser/dialog.ts +83 -0
- package/src/browser/download.test.ts +161 -0
- package/src/browser/download.ts +172 -0
- package/src/browser/downloads-dir.test.ts +75 -0
- package/src/browser/downloads-dir.ts +39 -0
- package/src/browser/emulation.browser-test.ts +186 -0
- package/src/browser/emulation.test.ts +200 -0
- package/src/browser/emulation.ts +204 -0
- package/src/browser/file-chooser.test.ts +142 -0
- package/src/browser/file-chooser.ts +99 -0
- package/src/browser/file-paths.ts +18 -0
- package/src/browser/goto.browser-test.ts +44 -0
- package/src/browser/navigation-error.ts +26 -0
- package/src/browser/navigation.browser-test.ts +172 -0
- package/src/browser/page-api.browser-test.ts +228 -0
- package/src/browser/page-logs.browser-test.ts +119 -0
- package/src/browser/page-logs.test.ts +212 -0
- package/src/browser/page-logs.ts +208 -0
- package/src/browser/page-wait.ts +19 -0
- package/src/browser/page.test.ts +1567 -0
- package/src/browser/page.ts +1176 -0
- package/src/browser/pdf.ts +62 -0
- package/src/browser/screenshot.ts +65 -0
- package/src/browser/transfers.browser-test.ts +180 -0
- package/src/config/config.ts +33 -0
- package/src/config/default.ts +5 -0
- package/src/config/fixtures.test.ts +137 -0
- package/src/config/mask.test.ts +143 -0
- package/src/config/mask.ts +87 -0
- package/src/config/run-settings.test.ts +163 -0
- package/src/config/run-settings.ts +114 -0
- package/src/config/secrets.ts +70 -0
- package/src/config/variables.ts +31 -0
- package/src/index.ts +10 -0
- package/src/locator/action-timeout-error.test.ts +83 -0
- package/src/locator/action-timeout-error.ts +72 -0
- package/src/locator/element-state.test.ts +181 -0
- package/src/locator/element-state.ts +159 -0
- package/src/locator/locate-nodes.browser-test.ts +169 -0
- package/src/locator/locator-actions.test.ts +355 -0
- package/src/locator/locator-chain.test.ts +292 -0
- package/src/locator/locator.browser-test.ts +137 -0
- package/src/locator/locator.test.ts +179 -0
- package/src/locator/locator.ts +656 -0
- package/src/locator/selector-errors.ts +18 -0
- package/src/locator/selector.test.ts +124 -0
- package/src/locator/selector.ts +107 -0
- package/src/locator/set-files.browser-test.ts +141 -0
- package/src/locator/set-files.test.ts +191 -0
- package/src/locator/text-locator.test.ts +118 -0
- package/src/locator/text-locator.ts +38 -0
- package/src/logger/index.test.ts +28 -0
- package/src/logger/index.ts +40 -0
- package/src/network/data-collector.test.ts +111 -0
- package/src/network/data-collector.ts +92 -0
- package/src/network/network-data.browser-test.ts +192 -0
- package/src/network/network-tracker.browser-test.ts +151 -0
- package/src/network/network-tracker.test.ts +307 -0
- package/src/network/network-tracker.ts +286 -0
- package/src/network/network-wait.ts +28 -0
- package/src/network/response.test.ts +93 -0
- package/src/network/response.ts +58 -0
- package/src/network/router.browser-test.ts +260 -0
- package/src/network/router.test.ts +528 -0
- package/src/network/router.ts +420 -0
- package/src/network/url-match.test.ts +69 -0
- package/src/network/url-match.ts +41 -0
- package/src/runner/page-logs-report.test.ts +144 -0
- package/src/runner/page-logs-report.ts +82 -0
- package/src/runner/prepare-run.test.ts +33 -0
- package/src/runner/prepare-run.ts +36 -0
- package/src/runner/registry.test.ts +59 -0
- package/src/runner/registry.ts +46 -0
- package/src/runner/reporter.test.ts +73 -0
- package/src/runner/reporter.ts +109 -0
- package/src/runner/test-error.test.ts +39 -0
- package/src/runner/test-error.ts +20 -0
- package/src/runner/test-runner.ts +184 -0
- package/src/script/call-function.browser-test.ts +112 -0
- package/src/script/call-function.test.ts +174 -0
- package/src/script/call-function.ts +113 -0
- package/src/script/element-handle.ts +11 -0
- package/src/script/helpers.test.ts +116 -0
- package/src/script/helpers.ts +68 -0
- package/src/script/preload.browser-test.ts +144 -0
- package/src/script/preload.test.ts +180 -0
- package/src/script/preload.ts +102 -0
- package/src/script/serialize.test.ts +182 -0
- package/src/script/serialize.ts +203 -0
- package/src/testing/browser-fixture.ts +18 -0
- package/src/testing/fake-websocket.ts +72 -0
- package/src/testing/stub-connector.ts +154 -0
- package/src/tests/index.spec.ts +30 -0
- package/src/transport/bidi-connection.test.ts +155 -0
- package/src/transport/bidi-connection.ts +256 -0
- package/src/transport/bidi-error.ts +23 -0
- package/src/transport/foundation.browser-test.ts +73 -0
- package/src/transport/subscriptions.test.ts +140 -0
- package/src/transport/subscriptions.ts +110 -0
- package/src/types/bidi-commands.test-d.ts +55 -0
- package/src/types/bidi-modules/browser.d.ts +103 -0
- package/src/types/bidi-modules/browsing-context.d.ts +430 -0
- package/src/types/bidi-modules/emulation.d.ts +280 -0
- package/src/types/bidi-modules/input.d.ts +201 -0
- package/src/types/bidi-modules/log.d.ts +49 -0
- package/src/types/bidi-modules/network.d.ts +358 -0
- package/src/types/bidi-modules/permissions.d.ts +19 -0
- package/src/types/bidi-modules/script.d.ts +543 -0
- package/src/types/bidi-modules/session.d.ts +135 -0
- package/src/types/bidi-modules/storage.d.ts +92 -0
- package/src/types/bidi-modules/web-extensions.d.ts +9 -0
- package/src/types/bidi-protocols/command.d.ts +7 -0
- package/src/types/bidi-protocols/error.d.ts +38 -0
- package/src/types/bidi-protocols/event.d.ts +17 -0
- package/src/types/bidi.d.ts +65 -0
- package/src/types/browser.d.ts +1 -0
- package/src/types/config.d.ts +157 -0
- package/src/types/env.d.ts +5 -0
- package/src/types/test.d.ts +95 -0
- package/src/wait/wait-until.test.ts +117 -0
- package/src/wait/wait-until.ts +86 -0
- package/tsconfig.json +44 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import type { EmptyResult } from "../bidi.js";
|
|
2
|
+
import type { UserContext } from "./browser.js";
|
|
3
|
+
import type { BrowsingContext } from "./browsing-context.js";
|
|
4
|
+
|
|
5
|
+
/** Commands available in the WebDriver BiDi script module, which manages JavaScript execution and realms. */
|
|
6
|
+
export interface ScriptCommands {
|
|
7
|
+
/** Evaluates a JavaScript expression in the given target realm and returns the serialized result. */
|
|
8
|
+
"script.evaluate": {
|
|
9
|
+
params: {
|
|
10
|
+
expression: string;
|
|
11
|
+
target: Target;
|
|
12
|
+
awaitPromise: boolean;
|
|
13
|
+
resultOwnership?: ResultOwnership | undefined;
|
|
14
|
+
serializationOptions?: SerializationOptions | undefined;
|
|
15
|
+
userActivation?: boolean | undefined;
|
|
16
|
+
};
|
|
17
|
+
result: EvaluateResult;
|
|
18
|
+
};
|
|
19
|
+
/** Calls a function declaration in the target realm with serialized arguments. */
|
|
20
|
+
"script.callFunction": {
|
|
21
|
+
params: {
|
|
22
|
+
functionDeclaration: string;
|
|
23
|
+
awaitPromise: boolean;
|
|
24
|
+
target: Target;
|
|
25
|
+
arguments?: ArgumentValue[] | undefined;
|
|
26
|
+
resultOwnership?: ResultOwnership | undefined;
|
|
27
|
+
serializationOptions?: SerializationOptions | undefined;
|
|
28
|
+
this?: ArgumentValue | undefined;
|
|
29
|
+
userActivation?: boolean | undefined;
|
|
30
|
+
};
|
|
31
|
+
result: CallFunctionResult;
|
|
32
|
+
};
|
|
33
|
+
/** Releases remote object handles in the target realm. */
|
|
34
|
+
"script.disown": {
|
|
35
|
+
params: { handles: Handle[]; target: Target };
|
|
36
|
+
result: DisownResult;
|
|
37
|
+
};
|
|
38
|
+
/** Registers a function to run before any page script in every matching new document. */
|
|
39
|
+
"script.addPreloadScript": {
|
|
40
|
+
params: {
|
|
41
|
+
functionDeclaration: string;
|
|
42
|
+
arguments?: ChannelValue[] | undefined;
|
|
43
|
+
contexts?: BrowsingContext[] | undefined;
|
|
44
|
+
userContexts?: UserContext[] | undefined;
|
|
45
|
+
sandbox?: string | undefined;
|
|
46
|
+
};
|
|
47
|
+
result: AddPreloadScriptResult;
|
|
48
|
+
};
|
|
49
|
+
/** Removes a preload script. */
|
|
50
|
+
"script.removePreloadScript": {
|
|
51
|
+
params: { script: PreloadScript };
|
|
52
|
+
result: RemovePreloadScriptResult;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A serialized value sent to the browser as a function argument or `this`. */
|
|
57
|
+
export type LocalValue = { type: string; value?: unknown; [key: string]: unknown };
|
|
58
|
+
/** A reference to a node or object that already lives in the browser. */
|
|
59
|
+
export type RemoteReference = { sharedId: string; handle?: string | undefined } | { handle: string };
|
|
60
|
+
/** A channel the browser can use to send messages back through `script.message`. */
|
|
61
|
+
export interface ChannelValue {
|
|
62
|
+
type: "channel";
|
|
63
|
+
value: { channel: Channel; serializationOptions?: SerializationOptions; ownership?: ResultOwnership };
|
|
64
|
+
}
|
|
65
|
+
export type ArgumentValue = LocalValue | RemoteReference | ChannelValue;
|
|
66
|
+
|
|
67
|
+
/** Events emitted by the script module, keyed by method name. */
|
|
68
|
+
export interface ScriptEvents {
|
|
69
|
+
"script.message": { params: MessageParameters };
|
|
70
|
+
"script.realmCreated": { params: RealmInfo };
|
|
71
|
+
"script.realmDestroyed": { params: RealmDestroyedParameters };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Result of a `script.evaluate` call — either a successful value or a thrown exception. */
|
|
75
|
+
export type EvaluateResult = EvaluateResultSuccess | EvaluateResultException;
|
|
76
|
+
|
|
77
|
+
/** Successful result of a `script.evaluate` call. */
|
|
78
|
+
export type EvaluateResultSuccess = {
|
|
79
|
+
type: "success";
|
|
80
|
+
result: RemoteValue;
|
|
81
|
+
realm: Realm;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** Result of a `script.evaluate` call where the expression threw an exception. */
|
|
85
|
+
export type EvaluateResultException = {
|
|
86
|
+
type: "exception";
|
|
87
|
+
exceptionDetails: ExceptionDetails;
|
|
88
|
+
realm: Realm;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** Details about a JavaScript exception, including its location and stack trace. */
|
|
92
|
+
export type ExceptionDetails = {
|
|
93
|
+
columnNumber: number;
|
|
94
|
+
exception: RemoteValue;
|
|
95
|
+
lineNumber: number;
|
|
96
|
+
stackTrace: StackTrace;
|
|
97
|
+
text: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** A JavaScript stack trace consisting of one or more call frames. */
|
|
101
|
+
export type StackTrace = {
|
|
102
|
+
callFrames: StackFrame[];
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** A single frame in a JavaScript stack trace. */
|
|
106
|
+
export type StackFrame = {
|
|
107
|
+
columnNumber: number;
|
|
108
|
+
functionName: string;
|
|
109
|
+
lineNumber: number;
|
|
110
|
+
url: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Each realm has an associated realm id, which is a string
|
|
114
|
+
* uniquely identifying that realm. This is implicitly set when
|
|
115
|
+
* the realm is created. */
|
|
116
|
+
export type Realm = string;
|
|
117
|
+
/** Targets a specific browsing context (and optional sandbox) for script execution. */
|
|
118
|
+
export type ContextTarget = {
|
|
119
|
+
context: BrowsingContext;
|
|
120
|
+
sandbox?: string | undefined;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Targets a specific realm by ID for script execution. */
|
|
124
|
+
export type RealmTarget = {
|
|
125
|
+
realm: Realm;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Represents a value that is either a Realm or a BrowsingContext.
|
|
129
|
+
* This is useful in cases where a navigable identifier can stand in
|
|
130
|
+
* for the realm associated with the navigable’s active document. */
|
|
131
|
+
export type Target = ContextTarget | RealmTarget;
|
|
132
|
+
|
|
133
|
+
/** Specifies how the serialized value ownership will be treated. */
|
|
134
|
+
export type ResultOwnership = "root" | "none";
|
|
135
|
+
|
|
136
|
+
/** Allows specifying how ECMAScript objects will be serialized. */
|
|
137
|
+
export type SerializationOptions = {
|
|
138
|
+
maxDomDepth?: number | null | undefined;
|
|
139
|
+
maxObjectDepth?: number | null | undefined;
|
|
140
|
+
includeShadowTree?: "none" | "open" | "all";
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type SharedId = string;
|
|
144
|
+
|
|
145
|
+
/** A serialized primitive ECMAScript value (undefined, null, string, number, boolean, or bigint). */
|
|
146
|
+
export type PrimitiveProtocolValue =
|
|
147
|
+
| UndefinedValue
|
|
148
|
+
| NullValue
|
|
149
|
+
| StringValue
|
|
150
|
+
| NumberValue
|
|
151
|
+
| BooleanValue
|
|
152
|
+
| BigIntValue;
|
|
153
|
+
|
|
154
|
+
/** Serialized `undefined`. */
|
|
155
|
+
export interface UndefinedValue {
|
|
156
|
+
type: "undefined";
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Serialized `null`. */
|
|
160
|
+
export interface NullValue {
|
|
161
|
+
type: "null";
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Serialized string value. */
|
|
165
|
+
export interface StringValue {
|
|
166
|
+
type: "string";
|
|
167
|
+
value: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Serialized number value. */
|
|
171
|
+
export interface NumberValue {
|
|
172
|
+
type: "number";
|
|
173
|
+
value: number;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Serialized boolean value. */
|
|
177
|
+
export interface BooleanValue {
|
|
178
|
+
type: "boolean";
|
|
179
|
+
value: boolean;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Serialized BigInt value. */
|
|
183
|
+
export interface BigIntValue {
|
|
184
|
+
type: "bigint";
|
|
185
|
+
value: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A serialized ECMAScript value returned from the remote end. Union of all possible remote value types. */
|
|
189
|
+
export type RemoteValue =
|
|
190
|
+
| PrimitiveProtocolValue
|
|
191
|
+
| SymbolRemoteValue
|
|
192
|
+
| ArrayRemoteValue
|
|
193
|
+
| ObjectRemoteValue
|
|
194
|
+
| FunctionRemoteValue
|
|
195
|
+
| RegExpRemoteValue
|
|
196
|
+
| DateRemoteValue
|
|
197
|
+
| MapRemoteValue
|
|
198
|
+
| SetRemoteValue
|
|
199
|
+
| WeakMapRemoteValue
|
|
200
|
+
| WeakSetRemoteValue
|
|
201
|
+
| GeneratorRemoteValue
|
|
202
|
+
| ErrorRemoteValue
|
|
203
|
+
| ProxyRemoteValue
|
|
204
|
+
| PromiseRemoteValue
|
|
205
|
+
| TypedArrayRemoteValue
|
|
206
|
+
| ArrayBufferRemoteValue
|
|
207
|
+
| NodeListRemoteValue
|
|
208
|
+
| HTMLCollectionRemoteValue
|
|
209
|
+
| NodeRemoteValue
|
|
210
|
+
| WindowProxyRemoteValue;
|
|
211
|
+
|
|
212
|
+
/** An ordered list of remote values, used for array-like types. */
|
|
213
|
+
export type ListRemoteValue = RemoteValue[];
|
|
214
|
+
|
|
215
|
+
/** A list of key-value pairs representing a Map or Object remote value. */
|
|
216
|
+
export type MappingRemoteValue = [RemoteValue | string, RemoteValue][];
|
|
217
|
+
|
|
218
|
+
/** A handle to a remote object; only valid within its associated realm. */
|
|
219
|
+
export type Handle = string;
|
|
220
|
+
|
|
221
|
+
/** An internal identifier for a remote object used for tracking object identity across serializations. */
|
|
222
|
+
export type InternalId = string;
|
|
223
|
+
|
|
224
|
+
/** Serialized ECMAScript Symbol. */
|
|
225
|
+
export interface SymbolRemoteValue {
|
|
226
|
+
type: "symbol";
|
|
227
|
+
handle?: Handle;
|
|
228
|
+
internalId?: InternalId;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Serialized ECMAScript Array. */
|
|
232
|
+
export interface ArrayRemoteValue {
|
|
233
|
+
type: "array";
|
|
234
|
+
handle?: Handle;
|
|
235
|
+
internalId?: InternalId;
|
|
236
|
+
value?: ListRemoteValue;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Serialized ECMAScript plain object. */
|
|
240
|
+
export interface ObjectRemoteValue {
|
|
241
|
+
type: "object";
|
|
242
|
+
handle?: Handle;
|
|
243
|
+
internalId?: InternalId;
|
|
244
|
+
value?: MappingRemoteValue;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Serialized ECMAScript function. */
|
|
248
|
+
export interface FunctionRemoteValue {
|
|
249
|
+
type: "function";
|
|
250
|
+
handle?: Handle;
|
|
251
|
+
internalId?: InternalId;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** The pattern and flags of a regular expression. */
|
|
255
|
+
export interface RegExpValue {
|
|
256
|
+
pattern: string;
|
|
257
|
+
flags?: string | undefined;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Local (non-remote) representation of a RegExp value. */
|
|
261
|
+
export interface RegExpLocalValue {
|
|
262
|
+
type: "regexp";
|
|
263
|
+
value: RegExpValue;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Serialized ECMAScript RegExp. */
|
|
267
|
+
export interface RegExpRemoteValue extends RegExpLocalValue {
|
|
268
|
+
handle?: Handle;
|
|
269
|
+
internalId?: InternalId;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Local (non-remote) representation of a Date value. */
|
|
273
|
+
export interface DateLocalValue {
|
|
274
|
+
type: "date";
|
|
275
|
+
value: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Serialized ECMAScript Date. */
|
|
279
|
+
export interface DateRemoteValue extends DateLocalValue {
|
|
280
|
+
handle?: Handle;
|
|
281
|
+
internalId?: InternalId;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Serialized ECMAScript Map. */
|
|
285
|
+
export interface MapRemoteValue {
|
|
286
|
+
type: "map";
|
|
287
|
+
handle?: Handle;
|
|
288
|
+
internalId?: InternalId;
|
|
289
|
+
value?: MappingRemoteValue;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Serialized ECMAScript Set. */
|
|
293
|
+
export interface SetRemoteValue {
|
|
294
|
+
type: "set";
|
|
295
|
+
handle?: Handle;
|
|
296
|
+
internalId?: InternalId;
|
|
297
|
+
value?: ListRemoteValue;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Serialized ECMAScript WeakMap. */
|
|
301
|
+
export interface WeakMapRemoteValue {
|
|
302
|
+
type: "weakmap";
|
|
303
|
+
handle?: Handle;
|
|
304
|
+
internalId?: InternalId;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Serialized ECMAScript WeakSet. */
|
|
308
|
+
export interface WeakSetRemoteValue {
|
|
309
|
+
type: "weakset";
|
|
310
|
+
handle?: Handle;
|
|
311
|
+
internalId?: InternalId;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Serialized ECMAScript Generator. */
|
|
315
|
+
export interface GeneratorRemoteValue {
|
|
316
|
+
type: "generator";
|
|
317
|
+
handle?: Handle;
|
|
318
|
+
internalId?: InternalId;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Serialized ECMAScript Error object. */
|
|
322
|
+
export interface ErrorRemoteValue {
|
|
323
|
+
type: "error";
|
|
324
|
+
handle?: Handle;
|
|
325
|
+
internalId?: InternalId;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Serialized ECMAScript Proxy. */
|
|
329
|
+
export interface ProxyRemoteValue {
|
|
330
|
+
type: "proxy";
|
|
331
|
+
handle?: Handle;
|
|
332
|
+
internalId?: InternalId;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Serialized ECMAScript Promise. */
|
|
336
|
+
export interface PromiseRemoteValue {
|
|
337
|
+
type: "promise";
|
|
338
|
+
handle?: Handle;
|
|
339
|
+
internalId?: InternalId;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Serialized ECMAScript TypedArray (e.g. Uint8Array, Float32Array). */
|
|
343
|
+
export interface TypedArrayRemoteValue {
|
|
344
|
+
type: "typedarray";
|
|
345
|
+
handle?: Handle;
|
|
346
|
+
internalId?: InternalId;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Serialized ECMAScript ArrayBuffer. */
|
|
350
|
+
export interface ArrayBufferRemoteValue {
|
|
351
|
+
type: "arraybuffer";
|
|
352
|
+
handle?: Handle;
|
|
353
|
+
internalId?: InternalId;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Serialized DOM NodeList. */
|
|
357
|
+
export interface NodeListRemoteValue {
|
|
358
|
+
type: "nodelist";
|
|
359
|
+
handle?: Handle;
|
|
360
|
+
internalId?: InternalId;
|
|
361
|
+
value?: ListRemoteValue;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Serialized DOM HTMLCollection. */
|
|
365
|
+
export interface HTMLCollectionRemoteValue {
|
|
366
|
+
type: "htmlcollection";
|
|
367
|
+
handle?: Handle;
|
|
368
|
+
internalId?: InternalId;
|
|
369
|
+
value?: ListRemoteValue;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Serialized DOM Node, usable via `sharedId` across realms. */
|
|
373
|
+
export interface NodeRemoteValue {
|
|
374
|
+
type: "node";
|
|
375
|
+
sharedId?: SharedId;
|
|
376
|
+
handle?: Handle;
|
|
377
|
+
internalId?: InternalId;
|
|
378
|
+
value?: NodeProperties;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Properties of a serialized DOM Node. */
|
|
382
|
+
export interface NodeProperties {
|
|
383
|
+
nodeType: number;
|
|
384
|
+
childNodeCount: number;
|
|
385
|
+
attributes?: Record<string, string>;
|
|
386
|
+
children?: NodeRemoteValue[];
|
|
387
|
+
localName?: string;
|
|
388
|
+
/** Shadow root mode, present when the node is a shadow root. */
|
|
389
|
+
mode?: "open" | "closed";
|
|
390
|
+
namespaceURI?: string;
|
|
391
|
+
nodeValue?: string;
|
|
392
|
+
shadowRoot?: NodeRemoteValue | null;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Serialized WindowProxy object. */
|
|
396
|
+
export interface WindowProxyRemoteValue {
|
|
397
|
+
type: "window";
|
|
398
|
+
value: WindowProxyProperties;
|
|
399
|
+
handle?: Handle;
|
|
400
|
+
internalId?: InternalId;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Properties of a serialized WindowProxy. */
|
|
404
|
+
export interface WindowProxyProperties {
|
|
405
|
+
context: BrowsingContext;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Union of all events emitted by the script module. */
|
|
409
|
+
export type ScriptEvent = Message | RealmCreated | RealmDestroyed;
|
|
410
|
+
|
|
411
|
+
/** Emitted when a script sends a message via a BiDi channel. */
|
|
412
|
+
export interface Message {
|
|
413
|
+
method: "script.message";
|
|
414
|
+
params: MessageParameters;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** Emitted when a new realm is created. */
|
|
418
|
+
export interface RealmCreated {
|
|
419
|
+
method: "script.realmCreated";
|
|
420
|
+
params: RealmInfo;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** Emitted when a realm is destroyed. */
|
|
424
|
+
export interface RealmDestroyed {
|
|
425
|
+
method: "script.realmDestroyed";
|
|
426
|
+
params: RealmDestroyedParameters;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Identifies a BiDi channel used for `window.bidi.send` / `script.message` communication. */
|
|
430
|
+
export type Channel = string;
|
|
431
|
+
|
|
432
|
+
/** Identifies the realm and browsing context that produced a script event. */
|
|
433
|
+
export interface Source {
|
|
434
|
+
realm: Realm;
|
|
435
|
+
context?: BrowsingContext;
|
|
436
|
+
userContext: UserContext;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** Parameters for the `script.message` event. */
|
|
440
|
+
export interface MessageParameters {
|
|
441
|
+
channel: Channel;
|
|
442
|
+
data: RemoteValue;
|
|
443
|
+
source: Source;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** Common properties shared by all realm info types. */
|
|
447
|
+
export interface BaseRealmInfo {
|
|
448
|
+
realm: Realm;
|
|
449
|
+
origin: string;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** Realm info for a window (top-level or iframe) context. */
|
|
453
|
+
export interface WindowRealmInfo extends BaseRealmInfo {
|
|
454
|
+
type: "window";
|
|
455
|
+
context: BrowsingContext;
|
|
456
|
+
userContext?: UserContext;
|
|
457
|
+
/** Non-default sandbox name, if the realm is a named sandbox. */
|
|
458
|
+
sandbox?: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** Realm info for a dedicated worker. */
|
|
462
|
+
export interface DedicatedWorkerRealmInfo extends BaseRealmInfo {
|
|
463
|
+
type: "dedicated-worker";
|
|
464
|
+
/** The realms that own this dedicated worker. */
|
|
465
|
+
owners: Realm[];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** Realm info for a shared worker. */
|
|
469
|
+
export interface SharedWorkerRealmInfo extends BaseRealmInfo {
|
|
470
|
+
type: "shared-worker";
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** Realm info for a service worker. */
|
|
474
|
+
export interface ServiceWorkerRealmInfo extends BaseRealmInfo {
|
|
475
|
+
type: "service-worker";
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Realm info for a generic worker. */
|
|
479
|
+
export interface WorkerRealmInfo extends BaseRealmInfo {
|
|
480
|
+
type: "worker";
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** Realm info for a CSS paint worklet. */
|
|
484
|
+
export interface PaintWorkletRealmInfo extends BaseRealmInfo {
|
|
485
|
+
type: "paint-worklet";
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** Realm info for an audio worklet. */
|
|
489
|
+
export interface AudioWorkletRealmInfo extends BaseRealmInfo {
|
|
490
|
+
type: "audio-worklet";
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Realm info for a generic worklet. */
|
|
494
|
+
export interface WorkletRealmInfo extends BaseRealmInfo {
|
|
495
|
+
type: "worklet";
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** Union of all realm info variants, discriminated by `type`. */
|
|
499
|
+
export type RealmInfo =
|
|
500
|
+
| WindowRealmInfo
|
|
501
|
+
| DedicatedWorkerRealmInfo
|
|
502
|
+
| SharedWorkerRealmInfo
|
|
503
|
+
| ServiceWorkerRealmInfo
|
|
504
|
+
| WorkerRealmInfo
|
|
505
|
+
| PaintWorkletRealmInfo
|
|
506
|
+
| AudioWorkletRealmInfo
|
|
507
|
+
| WorkletRealmInfo;
|
|
508
|
+
|
|
509
|
+
/** Parameters for the `script.realmDestroyed` event. */
|
|
510
|
+
export interface RealmDestroyedParameters {
|
|
511
|
+
realm: Realm;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** Union of all possible result types returned by script module commands. */
|
|
515
|
+
export type ScriptResult =
|
|
516
|
+
| AddPreloadScriptResult
|
|
517
|
+
| CallFunctionResult
|
|
518
|
+
| DisownResult
|
|
519
|
+
| EvaluateResult
|
|
520
|
+
| GetRealmsResult
|
|
521
|
+
| RemovePreloadScriptResult;
|
|
522
|
+
|
|
523
|
+
/** Unique identifier for a preload script registered via `script.addPreloadScript`. */
|
|
524
|
+
export type PreloadScript = string;
|
|
525
|
+
|
|
526
|
+
/** Result of `script.addPreloadScript`, containing the ID of the newly registered script. */
|
|
527
|
+
export interface AddPreloadScriptResult {
|
|
528
|
+
script: PreloadScript;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** Result of `script.callFunction` — same shape as `script.evaluate`. */
|
|
532
|
+
export type CallFunctionResult = EvaluateResult;
|
|
533
|
+
|
|
534
|
+
/** Result of `script.disown`. */
|
|
535
|
+
export type DisownResult = EmptyResult;
|
|
536
|
+
|
|
537
|
+
/** Result of `script.getRealms`, containing all matching realms. */
|
|
538
|
+
export interface GetRealmsResult {
|
|
539
|
+
realms: RealmInfo[];
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** Result of `script.removePreloadScript`. */
|
|
543
|
+
export type RemovePreloadScriptResult = EmptyResult;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { EmptyResult, Extensible } from "../bidi.js";
|
|
2
|
+
import type { UserContext } from "./browser.js";
|
|
3
|
+
import type { BrowsingContext } from "./browsing-context.js";
|
|
4
|
+
|
|
5
|
+
/** Commands available in the WebDriver BiDi session module, which manages session lifecycle and event subscriptions. */
|
|
6
|
+
export interface SessionModule {
|
|
7
|
+
/** Creates a new BiDi session with the given capabilities. */
|
|
8
|
+
"session.new": {
|
|
9
|
+
params: { capabilities: object };
|
|
10
|
+
result: { sessionId: string; capabilities: object };
|
|
11
|
+
};
|
|
12
|
+
/** Subscribes to one or more events, optionally scoped to specific browsing contexts or user contexts. */
|
|
13
|
+
"session.subscribe": {
|
|
14
|
+
params: {
|
|
15
|
+
events: string[];
|
|
16
|
+
contexts?: BrowsingContext[];
|
|
17
|
+
userContexts?: UserContext[];
|
|
18
|
+
};
|
|
19
|
+
result: { subscription: Subscription };
|
|
20
|
+
};
|
|
21
|
+
/** Removes event subscriptions, by subscription id or by event name. */
|
|
22
|
+
"session.unsubscribe": {
|
|
23
|
+
params: { subscriptions: Subscription[] } | { events: string[] };
|
|
24
|
+
result: UnsubscribeResult;
|
|
25
|
+
};
|
|
26
|
+
"session.status": {
|
|
27
|
+
params: {};
|
|
28
|
+
result: {
|
|
29
|
+
ready: boolean;
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A unique identifier for an active event subscription, returned by `session.subscribe`. */
|
|
36
|
+
export type Subscription = string;
|
|
37
|
+
|
|
38
|
+
/** Defines how user prompts (alerts, confirms, prompts) should be automatically handled. */
|
|
39
|
+
export type UserPromptHandlerType = "accept" | "dismiss" | "ignore";
|
|
40
|
+
|
|
41
|
+
/** Union of all possible result types returned by session module commands. */
|
|
42
|
+
export type SessionResult =
|
|
43
|
+
| EndResult
|
|
44
|
+
| NewResult
|
|
45
|
+
| StatusResult
|
|
46
|
+
| SubscribeResult
|
|
47
|
+
| UnsubscribeResult;
|
|
48
|
+
|
|
49
|
+
/** Result of `session.end`. */
|
|
50
|
+
export type EndResult = EmptyResult;
|
|
51
|
+
|
|
52
|
+
/** Automatically detects proxy settings from the environment. */
|
|
53
|
+
interface AutodetectProxyConfiguration extends Extensible {
|
|
54
|
+
proxyType: "autodetect";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Connects directly without a proxy. */
|
|
58
|
+
interface DirectProxyConfiguration extends Extensible {
|
|
59
|
+
proxyType: "direct";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** SOCKS proxy address and protocol version. */
|
|
63
|
+
interface SocksProxyConfiguration {
|
|
64
|
+
socksProxy: string;
|
|
65
|
+
/** SOCKS protocol version; 0..255 */
|
|
66
|
+
socksVersion: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Manually specified proxy settings, with optional per-protocol overrides and exclusion list. */
|
|
70
|
+
interface ManualProxyConfiguration extends Extensible {
|
|
71
|
+
proxyType: "manual";
|
|
72
|
+
httpProxy?: string;
|
|
73
|
+
sslProxy?: string;
|
|
74
|
+
socks?: SocksProxyConfiguration;
|
|
75
|
+
/** Hosts that should bypass the proxy. */
|
|
76
|
+
noProxy?: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Uses a Proxy Auto-Configuration (PAC) file at the given URL. */
|
|
80
|
+
interface PacProxyConfiguration extends Extensible {
|
|
81
|
+
proxyType: "pac";
|
|
82
|
+
proxyAutoconfigUrl: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Uses the operating system's proxy settings. */
|
|
86
|
+
interface SystemProxyConfiguration extends Extensible {
|
|
87
|
+
proxyType: "system";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Union of all proxy configuration variants, discriminated by `proxyType`. */
|
|
91
|
+
export type ProxyConfiguration =
|
|
92
|
+
| AutodetectProxyConfiguration
|
|
93
|
+
| DirectProxyConfiguration
|
|
94
|
+
| ManualProxyConfiguration
|
|
95
|
+
| PacProxyConfiguration
|
|
96
|
+
| SystemProxyConfiguration;
|
|
97
|
+
|
|
98
|
+
/** Per-prompt-type configuration for automatically handling browser dialogs. */
|
|
99
|
+
export interface UserPromptHandler {
|
|
100
|
+
alert?: UserPromptHandlerType;
|
|
101
|
+
beforeUnload?: UserPromptHandlerType;
|
|
102
|
+
confirm?: UserPromptHandlerType;
|
|
103
|
+
/** Fallback handler used when no type-specific handler is set. */
|
|
104
|
+
default?: UserPromptHandlerType;
|
|
105
|
+
file?: UserPromptHandlerType;
|
|
106
|
+
prompt?: UserPromptHandlerType;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Result of `session.new`, containing the assigned session ID and the negotiated capabilities. */
|
|
110
|
+
export interface NewResult {
|
|
111
|
+
sessionId: string;
|
|
112
|
+
capabilities: {
|
|
113
|
+
acceptInsecureCerts: boolean;
|
|
114
|
+
browserName: string;
|
|
115
|
+
browserVersion: string;
|
|
116
|
+
platformName: string;
|
|
117
|
+
setWindowRect: boolean;
|
|
118
|
+
userAgent: string;
|
|
119
|
+
proxy?: ProxyConfiguration;
|
|
120
|
+
unhandledPromptBehavior?: UserPromptHandler;
|
|
121
|
+
/** The WebSocket URL for BiDi communication, if supported. */
|
|
122
|
+
webSocketUrl?: string;
|
|
123
|
+
} & Extensible;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Result of `session.status`. */
|
|
127
|
+
export type StatusResult = EmptyResult;
|
|
128
|
+
|
|
129
|
+
/** Result of `session.subscribe`, containing the new subscription identifier. */
|
|
130
|
+
export interface SubscribeResult {
|
|
131
|
+
subscription: Subscription;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Result of `session.unsubscribe`. */
|
|
135
|
+
export type UnsubscribeResult = EmptyResult;
|