browserscale-ts 1.7.0 → 1.8.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/README.md +136 -78
- package/dist/browser.js +1 -1
- package/dist/browserscale.browser.js +427 -162
- package/dist/client.d.ts +241 -62
- package/dist/client.js +312 -83
- package/dist/defaults.d.ts +11 -9
- package/dist/defaults.js +15 -12
- package/dist/dom-mirror.d.ts +27 -0
- package/dist/dom-mirror.js +27 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.js +37 -0
- package/dist/gen/wrc_pb.d.ts +348 -91
- package/dist/gen/wrc_pb.js +53 -58
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -5
- package/dist/internal/convert.js +1 -0
- package/dist/locator.d.ts +12 -11
- package/dist/locator.js +14 -22
- package/dist/network-capture.d.ts +3 -2
- package/dist/network-capture.js +3 -2
- package/dist/options.d.ts +1 -1
- package/dist/scripts.d.ts +4 -3
- package/dist/scripts.js +4 -3
- package/dist/types.d.ts +12 -0
- package/package.json +1 -1
package/dist/defaults.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Timeout (ms) the API applies to wait() / waitAny() when no opts.timeoutMs
|
|
3
3
|
* is passed.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated The API owns this value; the SDK no longer sends it.
|
|
4
6
|
*/
|
|
5
7
|
export declare const DefaultWaitTimeoutMs = 30000;
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Visibility requirement the API applies to a wait condition that does not set
|
|
10
|
+
* one. Use .visible(false) on a Locator to wait for DOM presence alone.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated The API owns this value; the SDK no longer sends it.
|
|
11
13
|
*/
|
|
12
14
|
export declare const DefaultVisible = true;
|
|
13
15
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Steady-time (ms) the API applies to a wait condition that does not set one.
|
|
17
|
+
* Use .steady(0) on a Locator to match the instant the element is found.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated The API owns this value; the SDK no longer sends it.
|
|
18
20
|
*/
|
|
19
21
|
export declare const DefaultSteadyMs = 500;
|
package/dist/defaults.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// The SDK no longer applies its own defaults: every optional field is left
|
|
2
|
+
// unset on the wire and the browserscale API supplies the default, so there is
|
|
3
|
+
// one place that defines them. The constants below record the current
|
|
4
|
+
// server-side values for reference and are kept only for compatibility.
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Timeout (ms) the API applies to wait() / waitAny() when no opts.timeoutMs
|
|
6
7
|
* is passed.
|
|
8
|
+
*
|
|
9
|
+
* @deprecated The API owns this value; the SDK no longer sends it.
|
|
7
10
|
*/
|
|
8
11
|
export const DefaultWaitTimeoutMs = 30000;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* Visibility requirement the API applies to a wait condition that does not set
|
|
14
|
+
* one. Use .visible(false) on a Locator to wait for DOM presence alone.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated The API owns this value; the SDK no longer sends it.
|
|
14
17
|
*/
|
|
15
18
|
export const DefaultVisible = true;
|
|
16
19
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* Steady-time (ms) the API applies to a wait condition that does not set one.
|
|
21
|
+
* Use .steady(0) on a Locator to match the instant the element is found.
|
|
22
|
+
*
|
|
23
|
+
* @deprecated The API owns this value; the SDK no longer sends it.
|
|
21
24
|
*/
|
|
22
25
|
export const DefaultSteadyMs = 500;
|
package/dist/dom-mirror.d.ts
CHANGED
|
@@ -195,6 +195,14 @@ export declare class DomMirror {
|
|
|
195
195
|
* boundary was crossed; it is a child list like any other.
|
|
196
196
|
*
|
|
197
197
|
* @param depth levels below the node, default 1
|
|
198
|
+
*
|
|
199
|
+
* @throws not_mirrored - the page has no mirror, or the node's frame is not
|
|
200
|
+
* part of the one it has; after a resync, fetch the current tree before
|
|
201
|
+
* addressing nodes again
|
|
202
|
+
* @throws mirror_failed - the subtree could not be serialized, usually a
|
|
203
|
+
* document that went away mid-read
|
|
204
|
+
*
|
|
205
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
198
206
|
*/
|
|
199
207
|
expand(node: DomNode, depth?: number): Promise<void>;
|
|
200
208
|
/**
|
|
@@ -204,6 +212,13 @@ export declare class DomMirror {
|
|
|
204
212
|
*
|
|
205
213
|
* Skipping this is not an error, it is a slow leak: the browser's revealed
|
|
206
214
|
* set only grows, and eventually it is no longer filtering anything.
|
|
215
|
+
*
|
|
216
|
+
* @throws not_mirrored - the page has no mirror, or the node's frame is not
|
|
217
|
+
* part of the one it has; this is what collapsing a node from a tree that has
|
|
218
|
+
* since been resynced looks like, so fetch the current tree and address the
|
|
219
|
+
* node again
|
|
220
|
+
*
|
|
221
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
207
222
|
*/
|
|
208
223
|
collapse(node: DomNode): Promise<void>;
|
|
209
224
|
/**
|
|
@@ -220,12 +235,24 @@ export declare class DomMirror {
|
|
|
220
235
|
*
|
|
221
236
|
* @returns the ancestor chain, the main document first, or an empty array if
|
|
222
237
|
* the node is not on the page
|
|
238
|
+
*
|
|
239
|
+
* @throws not_mirrored - the page has no mirror, or the given frame is not part
|
|
240
|
+
* of the one it has
|
|
241
|
+
* @throws mirror_failed - the path could not be serialized, usually a document
|
|
242
|
+
* that went away mid-read
|
|
243
|
+
*
|
|
244
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
223
245
|
*/
|
|
224
246
|
reveal(backendNodeId: number, frameId?: string): Promise<DomNode[]>;
|
|
225
247
|
/**
|
|
226
248
|
* Throws away the local copy of the whole page and fetches a fresh one.
|
|
227
249
|
* Happens automatically whenever the browser says the copy is void, so you
|
|
228
250
|
* rarely need to call it.
|
|
251
|
+
*
|
|
252
|
+
* @throws mirror_failed - the page could not be serialized, usually a document
|
|
253
|
+
* that went away while the tree was being rebuilt. The mirror then ends
|
|
254
|
+
*
|
|
255
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
229
256
|
*/
|
|
230
257
|
resync(reason?: DomResyncReason): Promise<void>;
|
|
231
258
|
/** Resolves once the mirror ends — stop(), a dead session, a transport failure. */
|
package/dist/dom-mirror.js
CHANGED
|
@@ -130,6 +130,14 @@ export class DomMirror {
|
|
|
130
130
|
* boundary was crossed; it is a child list like any other.
|
|
131
131
|
*
|
|
132
132
|
* @param depth levels below the node, default 1
|
|
133
|
+
*
|
|
134
|
+
* @throws not_mirrored - the page has no mirror, or the node's frame is not
|
|
135
|
+
* part of the one it has; after a resync, fetch the current tree before
|
|
136
|
+
* addressing nodes again
|
|
137
|
+
* @throws mirror_failed - the subtree could not be serialized, usually a
|
|
138
|
+
* document that went away mid-read
|
|
139
|
+
*
|
|
140
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
133
141
|
*/
|
|
134
142
|
async expand(node, depth) {
|
|
135
143
|
if (this.stopped)
|
|
@@ -157,6 +165,13 @@ export class DomMirror {
|
|
|
157
165
|
*
|
|
158
166
|
* Skipping this is not an error, it is a slow leak: the browser's revealed
|
|
159
167
|
* set only grows, and eventually it is no longer filtering anything.
|
|
168
|
+
*
|
|
169
|
+
* @throws not_mirrored - the page has no mirror, or the node's frame is not
|
|
170
|
+
* part of the one it has; this is what collapsing a node from a tree that has
|
|
171
|
+
* since been resynced looks like, so fetch the current tree and address the
|
|
172
|
+
* node again
|
|
173
|
+
*
|
|
174
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
160
175
|
*/
|
|
161
176
|
async collapse(node) {
|
|
162
177
|
if (this.stopped)
|
|
@@ -185,6 +200,13 @@ export class DomMirror {
|
|
|
185
200
|
*
|
|
186
201
|
* @returns the ancestor chain, the main document first, or an empty array if
|
|
187
202
|
* the node is not on the page
|
|
203
|
+
*
|
|
204
|
+
* @throws not_mirrored - the page has no mirror, or the given frame is not part
|
|
205
|
+
* of the one it has
|
|
206
|
+
* @throws mirror_failed - the path could not be serialized, usually a document
|
|
207
|
+
* that went away mid-read
|
|
208
|
+
*
|
|
209
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
188
210
|
*/
|
|
189
211
|
async reveal(backendNodeId, frameId) {
|
|
190
212
|
if (this.stopped)
|
|
@@ -236,6 +258,11 @@ export class DomMirror {
|
|
|
236
258
|
* Throws away the local copy of the whole page and fetches a fresh one.
|
|
237
259
|
* Happens automatically whenever the browser says the copy is void, so you
|
|
238
260
|
* rarely need to call it.
|
|
261
|
+
*
|
|
262
|
+
* @throws mirror_failed - the page could not be serialized, usually a document
|
|
263
|
+
* that went away while the tree was being rebuilt. The mirror then ends
|
|
264
|
+
*
|
|
265
|
+
* @see {@link CommandError} for reading the code off the rejection
|
|
239
266
|
*/
|
|
240
267
|
async resync(reason = "manual") {
|
|
241
268
|
if (this.stopped)
|
package/dist/errors.d.ts
CHANGED
|
@@ -24,6 +24,49 @@ export declare class BrowserScaleError extends Error {
|
|
|
24
24
|
readonly cause?: unknown | undefined;
|
|
25
25
|
constructor(message: string, cause?: unknown | undefined);
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* CommandError is thrown when the browser carried out a command correctly but
|
|
29
|
+
* the page would not go along with it. It is the error for the commands that
|
|
30
|
+
* have nothing to report beyond what went wrong; the richer failures have their
|
|
31
|
+
* own class ({@link ClickError}, {@link FillError}, {@link DragError}) carrying
|
|
32
|
+
* the same `code` plus their own detail.
|
|
33
|
+
*
|
|
34
|
+
* It never reports an outage. A dead session, a closed page or a malformed call
|
|
35
|
+
* arrive as a plain {@link BrowserScaleError} instead, so narrowing to this
|
|
36
|
+
* class tells you the fault is in the page or in what you asked of it — which is
|
|
37
|
+
* the difference between retrying and fixing your code.
|
|
38
|
+
*
|
|
39
|
+
* try {
|
|
40
|
+
* await browser.evaluate("window.__ready === true");
|
|
41
|
+
* } catch (e) {
|
|
42
|
+
* if (e instanceof CommandError && e.code === "threw") {
|
|
43
|
+
* // the expression itself is broken; e.message has the exception text
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Raises the optional error of a uniform result, and does nothing when the
|
|
49
|
+
* command succeeded — so a call site stays one line instead of an if.
|
|
50
|
+
*/
|
|
51
|
+
export declare function throwCommandError(command: string, error?: {
|
|
52
|
+
code: string;
|
|
53
|
+
message: string;
|
|
54
|
+
}): void;
|
|
55
|
+
export declare class CommandError extends BrowserScaleError {
|
|
56
|
+
/** The call that failed, e.g. `"evaluate"`. */
|
|
57
|
+
readonly command: string;
|
|
58
|
+
/**
|
|
59
|
+
* Machine-stable and lowercase, and scoped to `command`: the same string can
|
|
60
|
+
* mean different things for different commands, so narrow on it together with
|
|
61
|
+
* the call you made.
|
|
62
|
+
*/
|
|
63
|
+
readonly code: string;
|
|
64
|
+
constructor(init: {
|
|
65
|
+
command: string;
|
|
66
|
+
code: string;
|
|
67
|
+
message: string;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
27
70
|
/**
|
|
28
71
|
* ClickError is thrown by {@link CloudBrowser.click} when the click did not
|
|
29
72
|
* land — the target was found but another element covered the intended point.
|
package/dist/errors.js
CHANGED
|
@@ -26,6 +26,43 @@ export class BrowserScaleError extends Error {
|
|
|
26
26
|
this.name = "BrowserScaleError";
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* CommandError is thrown when the browser carried out a command correctly but
|
|
31
|
+
* the page would not go along with it. It is the error for the commands that
|
|
32
|
+
* have nothing to report beyond what went wrong; the richer failures have their
|
|
33
|
+
* own class ({@link ClickError}, {@link FillError}, {@link DragError}) carrying
|
|
34
|
+
* the same `code` plus their own detail.
|
|
35
|
+
*
|
|
36
|
+
* It never reports an outage. A dead session, a closed page or a malformed call
|
|
37
|
+
* arrive as a plain {@link BrowserScaleError} instead, so narrowing to this
|
|
38
|
+
* class tells you the fault is in the page or in what you asked of it — which is
|
|
39
|
+
* the difference between retrying and fixing your code.
|
|
40
|
+
*
|
|
41
|
+
* try {
|
|
42
|
+
* await browser.evaluate("window.__ready === true");
|
|
43
|
+
* } catch (e) {
|
|
44
|
+
* if (e instanceof CommandError && e.code === "threw") {
|
|
45
|
+
* // the expression itself is broken; e.message has the exception text
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Raises the optional error of a uniform result, and does nothing when the
|
|
51
|
+
* command succeeded — so a call site stays one line instead of an if.
|
|
52
|
+
*/
|
|
53
|
+
export function throwCommandError(command, error) {
|
|
54
|
+
if (error) {
|
|
55
|
+
throw new CommandError({ command, code: error.code, message: error.message });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export class CommandError extends BrowserScaleError {
|
|
59
|
+
constructor(init) {
|
|
60
|
+
super(formatMessage(init.command, init.code, init.message));
|
|
61
|
+
this.name = "CommandError";
|
|
62
|
+
this.command = init.command;
|
|
63
|
+
this.code = init.code;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
29
66
|
/**
|
|
30
67
|
* ClickError is thrown by {@link CloudBrowser.click} when the click did not
|
|
31
68
|
* land — the target was found but another element covered the intended point.
|