browserscale-ts 1.7.1 → 1.9.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 +137 -81
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/browserscale.browser.js +533 -216
- package/dist/client.d.ts +266 -60
- package/dist/client.js +348 -81
- 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 +466 -91
- package/dist/gen/wrc_pb.js +145 -135
- package/dist/index.d.ts +15 -9
- package/dist/index.js +17 -13
- package/dist/internal/convert.d.ts +4 -2
- package/dist/internal/convert.js +28 -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 +52 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CloudBrowser } from "./client.ts";
|
|
2
2
|
import { BrowserConfig } from "./config.ts";
|
|
3
|
-
import type { BrowserInfo } from "./types.ts";
|
|
3
|
+
import type { BrowserInfo, SessionUsage } from "./types.ts";
|
|
4
4
|
export { CloudBrowser } from "./client.ts";
|
|
5
5
|
export { BrowserConfig } from "./config.ts";
|
|
6
6
|
export { Locator, css, js, node, at, AllFrames } from "./locator.ts";
|
|
7
7
|
export { DefaultWaitTimeoutMs, DefaultVisible, DefaultSteadyMs, } from "./defaults.ts";
|
|
8
|
-
export { BrowserScaleError, ClickError, FillError, DragError, ScrollError, MoveError, SelectOptionError, WaitError, } from "./errors.ts";
|
|
9
|
-
export type { Rect, FrameInfo, PageInfo, Header, InterceptedRequest, InterceptedResponse, NetworkExchange, NetworkResourceType, NetworkServedFrom, NetworkBodies, NetworkCaptureOptions, WaitResult, WaitConditionStatus, OccluderInfo, ElementRef, NavigateResult, EvaluateResult, ElementResult, DragResult, SelectOptionResult, ScreenshotResult, ReadCanvasResult, DOMResult, InspectResult, RentResponse, BrowserInfo, IceServer, StreamAnswer, ReactionInfo, } from "./types.ts";
|
|
8
|
+
export { BrowserScaleError, CommandError, ClickError, FillError, DragError, ScrollError, MoveError, SelectOptionError, WaitError, } from "./errors.ts";
|
|
9
|
+
export type { Rect, FrameInfo, PageInfo, Header, InterceptedRequest, InterceptedResponse, NetworkExchange, NetworkResourceType, NetworkServedFrom, NetworkBodies, NetworkCaptureOptions, WaitResult, WaitConditionStatus, OccluderInfo, ElementRef, NavigateResult, EvaluateResult, ElementResult, DragResult, SelectOptionResult, ScreenshotResult, ReadCanvasResult, DOMResult, InspectResult, RentResponse, BrowserInfo, SessionUsage, IceServer, StreamAnswer, ReactionInfo, } from "./types.ts";
|
|
10
10
|
export type { Button, ClickAction, ClickOpts, FillOpts, ReactionOpts, SelectOpts, WaitOpts, WaitUntil, NavigateOpts, LoadHTMLOpts, GetDOMOpts, GetObservationOpts, ScreenshotOpts, ReadCanvasOpts, } from "./options.ts";
|
|
11
11
|
export { type RequestPattern, type HeaderModification, type HeaderModificationAction, } from "./network.ts";
|
|
12
12
|
export { ScriptRun, ScriptFollow, type ScriptEvent, type ScriptEventHandler, type ScriptFinished, type ScriptLogEntry, type ScriptResult, type ScriptRunInfo, } from "./scripts.ts";
|
|
@@ -40,8 +40,9 @@ export declare function setApiEndpoint(endpoint: string): void;
|
|
|
40
40
|
*
|
|
41
41
|
* @returns CloudBrowser ready to drive the rented session
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* Rejects when the rent API refuses the request or the connection cannot be
|
|
44
|
+
* established. These are session-lifecycle failures rather than browser outcomes,
|
|
45
|
+
* so they carry no code.
|
|
45
46
|
*
|
|
46
47
|
* @example
|
|
47
48
|
* const cfg = new BrowserConfig("sk_…", 600, "", 0, "", "");
|
|
@@ -87,12 +88,16 @@ export declare function connectSession(grpcUrl: string, apiKey: string, sessionI
|
|
|
87
88
|
* @param apiKey - API key the session was rented with
|
|
88
89
|
* @param sessionId - id of the session to release
|
|
89
90
|
*
|
|
90
|
-
* @
|
|
91
|
+
* @returns SessionUsage what the session consumed over its whole life;
|
|
92
|
+
* undefined when the server could not report it
|
|
93
|
+
*
|
|
94
|
+
* Rejects when the stop API refuses the request. Stopping a session that is
|
|
95
|
+
* already gone is a no-op rather than a failure.
|
|
91
96
|
*
|
|
92
97
|
* @example
|
|
93
|
-
* await stopBrowser(apiKey, sessionId);
|
|
98
|
+
* const usage = await stopBrowser(apiKey, sessionId);
|
|
94
99
|
*/
|
|
95
|
-
export declare function stopBrowser(apiKey: string, sessionId: string): Promise<
|
|
100
|
+
export declare function stopBrowser(apiKey: string, sessionId: string): Promise<SessionUsage | undefined>;
|
|
96
101
|
/**
|
|
97
102
|
* Reports the sessions an API key currently holds.
|
|
98
103
|
*
|
|
@@ -109,7 +114,8 @@ export declare function stopBrowser(apiKey: string, sessionId: string): Promise<
|
|
|
109
114
|
*
|
|
110
115
|
* @returns the running sessions, oldest first; empty when the key holds none
|
|
111
116
|
*
|
|
112
|
-
*
|
|
117
|
+
* Rejects when the list API refuses the request. An account with no running
|
|
118
|
+
* sessions is an empty list, not a failure.
|
|
113
119
|
*
|
|
114
120
|
* @example
|
|
115
121
|
* const browsers = await listBrowsers(apiKey);
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
2
2
|
import { CloudBrowser } from "./client.js";
|
|
3
|
+
import { sessionUsageFromJson } from "./internal/convert.js";
|
|
3
4
|
// Public API ──────────────────────────────────────────────────────────
|
|
4
5
|
export { CloudBrowser } from "./client.js";
|
|
5
6
|
export { BrowserConfig } from "./config.js";
|
|
@@ -8,7 +9,7 @@ export { Locator, css, js, node, at, AllFrames } from "./locator.js";
|
|
|
8
9
|
// Defaults the SDK applies before sending a request
|
|
9
10
|
export { DefaultWaitTimeoutMs, DefaultVisible, DefaultSteadyMs, } from "./defaults.js";
|
|
10
11
|
// Errors — base class plus the typed semantic-failure subclasses
|
|
11
|
-
export { BrowserScaleError, ClickError, FillError, DragError, ScrollError, MoveError, SelectOptionError, WaitError, } from "./errors.js";
|
|
12
|
+
export { BrowserScaleError, CommandError, ClickError, FillError, DragError, ScrollError, MoveError, SelectOptionError, WaitError, } from "./errors.js";
|
|
12
13
|
// Scripts (automation running inside the browser process)
|
|
13
14
|
export { ScriptRun, ScriptFollow, } from "./scripts.js";
|
|
14
15
|
// Network capture (traffic log)
|
|
@@ -43,8 +44,9 @@ export function setApiEndpoint(endpoint) {
|
|
|
43
44
|
*
|
|
44
45
|
* @returns CloudBrowser ready to drive the rented session
|
|
45
46
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
47
|
+
* Rejects when the rent API refuses the request or the connection cannot be
|
|
48
|
+
* established. These are session-lifecycle failures rather than browser outcomes,
|
|
49
|
+
* so they carry no code.
|
|
48
50
|
*
|
|
49
51
|
* @example
|
|
50
52
|
* const cfg = new BrowserConfig("sk_…", 600, "", 0, "", "");
|
|
@@ -60,9 +62,7 @@ export async function rentBrowser(config) {
|
|
|
60
62
|
const transport = createGrpcTransport({
|
|
61
63
|
baseUrl: grpcBaseUrl(rentResp.grpcUrl),
|
|
62
64
|
});
|
|
63
|
-
return new CloudBrowser(transport, rentResp.sessionId, config.apiKey, rentResp.fingerprint,
|
|
64
|
-
await callStopApi(config.apiKey, rentResp.sessionId);
|
|
65
|
-
});
|
|
65
|
+
return new CloudBrowser(transport, rentResp.sessionId, config.apiKey, rentResp.fingerprint, () => callStopApi(config.apiKey, rentResp.sessionId));
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Attaches to an already-rented session over a fresh gRPC connection.
|
|
@@ -89,9 +89,7 @@ export async function rentBrowser(config) {
|
|
|
89
89
|
*/
|
|
90
90
|
export function connectSession(grpcUrl, apiKey, sessionId) {
|
|
91
91
|
const transport = createGrpcTransport({ baseUrl: grpcBaseUrl(grpcUrl) });
|
|
92
|
-
return new CloudBrowser(transport, sessionId, apiKey, "",
|
|
93
|
-
await callStopApi(apiKey, sessionId);
|
|
94
|
-
});
|
|
92
|
+
return new CloudBrowser(transport, sessionId, apiKey, "", () => callStopApi(apiKey, sessionId));
|
|
95
93
|
}
|
|
96
94
|
/**
|
|
97
95
|
* Releases a session without needing a {@link CloudBrowser} handle.
|
|
@@ -103,13 +101,17 @@ export function connectSession(grpcUrl, apiKey, sessionId) {
|
|
|
103
101
|
* @param apiKey - API key the session was rented with
|
|
104
102
|
* @param sessionId - id of the session to release
|
|
105
103
|
*
|
|
106
|
-
* @
|
|
104
|
+
* @returns SessionUsage what the session consumed over its whole life;
|
|
105
|
+
* undefined when the server could not report it
|
|
106
|
+
*
|
|
107
|
+
* Rejects when the stop API refuses the request. Stopping a session that is
|
|
108
|
+
* already gone is a no-op rather than a failure.
|
|
107
109
|
*
|
|
108
110
|
* @example
|
|
109
|
-
* await stopBrowser(apiKey, sessionId);
|
|
111
|
+
* const usage = await stopBrowser(apiKey, sessionId);
|
|
110
112
|
*/
|
|
111
113
|
export async function stopBrowser(apiKey, sessionId) {
|
|
112
|
-
await callStopApi(apiKey, sessionId);
|
|
114
|
+
return await callStopApi(apiKey, sessionId);
|
|
113
115
|
}
|
|
114
116
|
/**
|
|
115
117
|
* Reports the sessions an API key currently holds.
|
|
@@ -127,7 +129,8 @@ export async function stopBrowser(apiKey, sessionId) {
|
|
|
127
129
|
*
|
|
128
130
|
* @returns the running sessions, oldest first; empty when the key holds none
|
|
129
131
|
*
|
|
130
|
-
*
|
|
132
|
+
* Rejects when the list API refuses the request. An account with no running
|
|
133
|
+
* sessions is an empty list, not a failure.
|
|
131
134
|
*
|
|
132
135
|
* @example
|
|
133
136
|
* const browsers = await listBrowsers(apiKey);
|
|
@@ -221,4 +224,5 @@ async function callStopApi(apiKey, sessionId) {
|
|
|
221
224
|
if (!resp.ok || !data.success) {
|
|
222
225
|
throw new Error(`stop failed: ${data.error ?? resp.statusText}`);
|
|
223
226
|
}
|
|
227
|
+
return sessionUsageFromJson(data.usage);
|
|
224
228
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Rect as ProtoRect, type ClickResult as ProtoClickResult, type FillResult as ProtoFillResult, type MoveResult as ProtoMoveResult, type ScrollResult as ProtoScrollResult, type DragResult as ProtoDragResult, type SelectOptionResult as ProtoSelectOptionResult, type WaitResult as ProtoWaitResult, type FrameInfo as ProtoFrameInfo, type PageInfo as ProtoPageInfo, type Header as ProtoHeader, type InterceptedRequest as ProtoInterceptedRequest, type InterceptedResponse as ProtoInterceptedResponse, type NetworkExchange as ProtoNetworkExchange, type HeaderModification as ProtoHeaderModification, type CookieParam as ProtoCookieParam, type StorageOriginEntry as ProtoStorageOriginEntry, type AuthSession as ProtoAuthSession } from "../gen/wrc_pb.ts";
|
|
2
|
-
import type { DragResult, ElementResult, FrameInfo, Header, InterceptedRequest, InterceptedResponse, NetworkExchange, PageInfo, Rect, SelectOptionResult, WaitResult } from "../types.ts";
|
|
1
|
+
import { type Rect as ProtoRect, type ClickResult as ProtoClickResult, type FillResult as ProtoFillResult, type MoveResult as ProtoMoveResult, type ScrollResult as ProtoScrollResult, type DragResult as ProtoDragResult, type SelectOptionResult as ProtoSelectOptionResult, type WaitResult as ProtoWaitResult, type FrameInfo as ProtoFrameInfo, type PageInfo as ProtoPageInfo, type SessionUsage as ProtoSessionUsage, type Header as ProtoHeader, type InterceptedRequest as ProtoInterceptedRequest, type InterceptedResponse as ProtoInterceptedResponse, type NetworkExchange as ProtoNetworkExchange, type HeaderModification as ProtoHeaderModification, type CookieParam as ProtoCookieParam, type StorageOriginEntry as ProtoStorageOriginEntry, type AuthSession as ProtoAuthSession } from "../gen/wrc_pb.ts";
|
|
2
|
+
import type { DragResult, ElementResult, FrameInfo, Header, InterceptedRequest, InterceptedResponse, NetworkExchange, PageInfo, Rect, SelectOptionResult, SessionUsage, WaitResult } from "../types.ts";
|
|
3
3
|
import type { CookieParam } from "../cookies.ts";
|
|
4
4
|
import type { StorageOriginEntry } from "../storage.ts";
|
|
5
5
|
import type { AuthSession } from "../auth-session.ts";
|
|
@@ -36,6 +36,8 @@ export declare function unwrapSelect(r: ProtoSelectOptionResult): SelectOptionRe
|
|
|
36
36
|
export declare function unwrapWait(r: ProtoWaitResult): WaitResult;
|
|
37
37
|
export declare function frameInfoFromProto(f: ProtoFrameInfo): FrameInfo;
|
|
38
38
|
export declare function pageInfoFromProto(p: ProtoPageInfo): PageInfo;
|
|
39
|
+
export declare function sessionUsageFromProto(u: ProtoSessionUsage): SessionUsage;
|
|
40
|
+
export declare function sessionUsageFromJson(v: unknown): SessionUsage | undefined;
|
|
39
41
|
export declare function headerFromProto(h: ProtoHeader): Header;
|
|
40
42
|
export declare function headersToProto(headers: Header[] | undefined): ProtoHeader[];
|
|
41
43
|
export declare function interceptedRequestFromProto(r: ProtoInterceptedRequest | undefined): InterceptedRequest | null;
|
package/dist/internal/convert.js
CHANGED
|
@@ -183,6 +183,7 @@ function waitConditionStatusFromProto(c) {
|
|
|
183
183
|
/** Maps a WaitResult; throws {@link WaitError} when no condition matched before the deadline. */
|
|
184
184
|
export function unwrapWait(r) {
|
|
185
185
|
const res = {
|
|
186
|
+
success: r.success,
|
|
186
187
|
index: r.index,
|
|
187
188
|
frameId: r.frameId,
|
|
188
189
|
backendNodeId: r.backendNodeId,
|
|
@@ -227,6 +228,33 @@ export function pageInfoFromProto(p) {
|
|
|
227
228
|
: {},
|
|
228
229
|
};
|
|
229
230
|
}
|
|
231
|
+
export function sessionUsageFromProto(u) {
|
|
232
|
+
return {
|
|
233
|
+
wallTime: u.wallTime,
|
|
234
|
+
cpuTime: u.cpuTime,
|
|
235
|
+
minMemory: u.minMemory,
|
|
236
|
+
averageMemory: u.averageMemory,
|
|
237
|
+
peakMemory: u.peakMemory,
|
|
238
|
+
renderersUsed: u.renderersUsed,
|
|
239
|
+
framesCreated: u.framesCreated,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
// The stop endpoint answers in JSON, with the same field names as SessionUsage.
|
|
243
|
+
export function sessionUsageFromJson(v) {
|
|
244
|
+
if (!v || typeof v !== "object")
|
|
245
|
+
return undefined;
|
|
246
|
+
const u = v;
|
|
247
|
+
const num = (x) => (typeof x === "number" ? x : 0);
|
|
248
|
+
return {
|
|
249
|
+
wallTime: num(u.wallTime),
|
|
250
|
+
cpuTime: num(u.cpuTime),
|
|
251
|
+
minMemory: num(u.minMemory),
|
|
252
|
+
averageMemory: num(u.averageMemory),
|
|
253
|
+
peakMemory: num(u.peakMemory),
|
|
254
|
+
renderersUsed: num(u.renderersUsed),
|
|
255
|
+
framesCreated: num(u.framesCreated),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
230
258
|
// ──────────────────────────────────────────────────────────────────────
|
|
231
259
|
// Headers
|
|
232
260
|
// ──────────────────────────────────────────────────────────────────────
|
package/dist/locator.d.ts
CHANGED
|
@@ -40,9 +40,9 @@ export declare class Locator {
|
|
|
40
40
|
* Enforces or disables the visibility check for this Locator's wait
|
|
41
41
|
* condition.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
* no effect when used as an action target — actions
|
|
45
|
-
* visibility before dispatching.
|
|
43
|
+
* Visibility is required by default, so pass `false` to wait for DOM
|
|
44
|
+
* presence alone. Has no effect when used as an action target — actions
|
|
45
|
+
* never check visibility before dispatching.
|
|
46
46
|
*
|
|
47
47
|
* @param v - true to require visibility, false to skip the check
|
|
48
48
|
*
|
|
@@ -56,9 +56,9 @@ export declare class Locator {
|
|
|
56
56
|
* Requires the element to keep a stable position and size for at least
|
|
57
57
|
* `ms` milliseconds before the wait matches.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
* for js() expressions that return a non-Element
|
|
61
|
-
* as an action target.
|
|
59
|
+
* Settling defaults to 500ms, so pass 0 to match the instant the element
|
|
60
|
+
* is found. Has no effect for js() expressions that return a non-Element
|
|
61
|
+
* value, nor when used as an action target.
|
|
62
62
|
*
|
|
63
63
|
* @param ms - steady-state duration in milliseconds; 0 disables
|
|
64
64
|
*
|
|
@@ -112,9 +112,10 @@ export declare class Locator {
|
|
|
112
112
|
* css waits for / targets an element matching the given CSS selector.
|
|
113
113
|
*
|
|
114
114
|
* When used in {@link CloudBrowser.wait}/{@link CloudBrowser.waitAny}, the
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* `.
|
|
115
|
+
* condition requires the element to be visible and to hold still for 500ms
|
|
116
|
+
* before it matches — the API's defaults for a condition that does not set
|
|
117
|
+
* them. Override per call with `.visible(false)` / `.steady(ms)` (use
|
|
118
|
+
* `.steady(0)` to disable the steady check).
|
|
118
119
|
*
|
|
119
120
|
* When used as an action target (click, fill, …) the visible/steady
|
|
120
121
|
* fields are ignored — there are no corresponding fields on the action
|
|
@@ -134,8 +135,8 @@ export declare function css(selector: string): Locator;
|
|
|
134
135
|
/**
|
|
135
136
|
* js waits for / targets the result of a JavaScript expression.
|
|
136
137
|
*
|
|
137
|
-
* Same wait defaults as {@link css} (
|
|
138
|
-
*
|
|
138
|
+
* Same wait defaults as {@link css} (visible, 500ms steady); these only
|
|
139
|
+
* apply when the expression returns a
|
|
139
140
|
* DOM Element. For non-Element truthy values (boolean, string, number,
|
|
140
141
|
* plain object) both fields are no-ops and the condition matches as soon
|
|
141
142
|
* as the value is truthy. Use `.visible(false)` / `.steady(0)` to opt out.
|
package/dist/locator.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DefaultSteadyMs, DefaultVisible } from "./defaults.js";
|
|
2
1
|
import { BrowserScaleError } from "./errors.js";
|
|
3
2
|
/**
|
|
4
3
|
* AllFrames is the sentinel for "match in every frame on the page".
|
|
@@ -53,9 +52,9 @@ export class Locator {
|
|
|
53
52
|
* Enforces or disables the visibility check for this Locator's wait
|
|
54
53
|
* condition.
|
|
55
54
|
*
|
|
56
|
-
*
|
|
57
|
-
* no effect when used as an action target — actions
|
|
58
|
-
* visibility before dispatching.
|
|
55
|
+
* Visibility is required by default, so pass `false` to wait for DOM
|
|
56
|
+
* presence alone. Has no effect when used as an action target — actions
|
|
57
|
+
* never check visibility before dispatching.
|
|
59
58
|
*
|
|
60
59
|
* @param v - true to require visibility, false to skip the check
|
|
61
60
|
*
|
|
@@ -71,9 +70,9 @@ export class Locator {
|
|
|
71
70
|
* Requires the element to keep a stable position and size for at least
|
|
72
71
|
* `ms` milliseconds before the wait matches.
|
|
73
72
|
*
|
|
74
|
-
*
|
|
75
|
-
* for js() expressions that return a non-Element
|
|
76
|
-
* as an action target.
|
|
73
|
+
* Settling defaults to 500ms, so pass 0 to match the instant the element
|
|
74
|
+
* is found. Has no effect for js() expressions that return a non-Element
|
|
75
|
+
* value, nor when used as an action target.
|
|
77
76
|
*
|
|
78
77
|
* @param ms - steady-state duration in milliseconds; 0 disables
|
|
79
78
|
*
|
|
@@ -132,19 +131,11 @@ export class Locator {
|
|
|
132
131
|
// ── Constructors (top-level functions re-export these) ──────────────
|
|
133
132
|
/** @internal */
|
|
134
133
|
static _css(selector) {
|
|
135
|
-
return new Locator({
|
|
136
|
-
selector,
|
|
137
|
-
visibleFlag: DefaultVisible,
|
|
138
|
-
steadyMs: DefaultSteadyMs,
|
|
139
|
-
});
|
|
134
|
+
return new Locator({ selector });
|
|
140
135
|
}
|
|
141
136
|
/** @internal */
|
|
142
137
|
static _js(expression) {
|
|
143
|
-
return new Locator({
|
|
144
|
-
jsExpression: expression,
|
|
145
|
-
visibleFlag: DefaultVisible,
|
|
146
|
-
steadyMs: DefaultSteadyMs,
|
|
147
|
-
});
|
|
138
|
+
return new Locator({ jsExpression: expression });
|
|
148
139
|
}
|
|
149
140
|
/** @internal */
|
|
150
141
|
static _node(backendNodeId) {
|
|
@@ -162,9 +153,10 @@ export class Locator {
|
|
|
162
153
|
* css waits for / targets an element matching the given CSS selector.
|
|
163
154
|
*
|
|
164
155
|
* When used in {@link CloudBrowser.wait}/{@link CloudBrowser.waitAny}, the
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* `.
|
|
156
|
+
* condition requires the element to be visible and to hold still for 500ms
|
|
157
|
+
* before it matches — the API's defaults for a condition that does not set
|
|
158
|
+
* them. Override per call with `.visible(false)` / `.steady(ms)` (use
|
|
159
|
+
* `.steady(0)` to disable the steady check).
|
|
168
160
|
*
|
|
169
161
|
* When used as an action target (click, fill, …) the visible/steady
|
|
170
162
|
* fields are ignored — there are no corresponding fields on the action
|
|
@@ -186,8 +178,8 @@ export function css(selector) {
|
|
|
186
178
|
/**
|
|
187
179
|
* js waits for / targets the result of a JavaScript expression.
|
|
188
180
|
*
|
|
189
|
-
* Same wait defaults as {@link css} (
|
|
190
|
-
*
|
|
181
|
+
* Same wait defaults as {@link css} (visible, 500ms steady); these only
|
|
182
|
+
* apply when the expression returns a
|
|
191
183
|
* DOM Element. For non-Element truthy values (boolean, string, number,
|
|
192
184
|
* plain object) both fields are no-ops and the condition matches as soon
|
|
193
185
|
* as the value is truthy. Use `.visible(false)` / `.steady(0)` to opt out.
|
|
@@ -77,8 +77,9 @@ export declare class NetworkCapture {
|
|
|
77
77
|
* {@link CloudBrowser.stopNetworkCapture} instead: stop awaits the reader,
|
|
78
78
|
* which cannot finish while the handler it called is still running.
|
|
79
79
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
80
|
+
* Rejects only on a transport failure, and the local reader is shut down
|
|
81
|
+
* regardless. Disarming a capture that is not running is a no-op rather than a
|
|
82
|
+
* failure, so there are no error codes to branch on.
|
|
82
83
|
*/
|
|
83
84
|
stop(): Promise<void>;
|
|
84
85
|
}
|
package/dist/network-capture.js
CHANGED
|
@@ -88,8 +88,9 @@ export class NetworkCapture {
|
|
|
88
88
|
* {@link CloudBrowser.stopNetworkCapture} instead: stop awaits the reader,
|
|
89
89
|
* which cannot finish while the handler it called is still running.
|
|
90
90
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
91
|
+
* Rejects only on a transport failure, and the local reader is shut down
|
|
92
|
+
* regardless. Disarming a capture that is not running is a no-op rather than a
|
|
93
|
+
* failure, so there are no error codes to branch on.
|
|
93
94
|
*/
|
|
94
95
|
async stop() {
|
|
95
96
|
if (this.stopped)
|
package/dist/options.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ export interface SelectOpts {
|
|
|
92
92
|
}
|
|
93
93
|
/** Optional customization for {@link CloudBrowser.wait} / {@link CloudBrowser.waitForAny}. */
|
|
94
94
|
export interface WaitOpts {
|
|
95
|
-
/**
|
|
95
|
+
/** Omitted leaves it to the API, which defaults to 30 000 ms. */
|
|
96
96
|
timeoutMs?: number;
|
|
97
97
|
}
|
|
98
98
|
/** Lifecycle event {@link CloudBrowser.navigate} waits for before returning. */
|
package/dist/scripts.d.ts
CHANGED
|
@@ -144,7 +144,8 @@ export declare class ScriptRun {
|
|
|
144
144
|
*
|
|
145
145
|
* @returns how the script ended
|
|
146
146
|
*
|
|
147
|
-
*
|
|
147
|
+
* Rejects only on a transport failure - the connection dying, or the run being
|
|
148
|
+
* abandoned. A script that threw is a normal outcome and arrives in the result.
|
|
148
149
|
*/
|
|
149
150
|
wait(): Promise<ScriptFinished>;
|
|
150
151
|
/**
|
|
@@ -155,8 +156,8 @@ export declare class ScriptRun {
|
|
|
155
156
|
* at its next operation in the page. Either way the handler sees a `finished`
|
|
156
157
|
* with `stopped` set, unless the local reader is torn down first.
|
|
157
158
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
159
|
+
* Rejects only on a transport failure, and the local reader is detached
|
|
160
|
+
* regardless. Cancelling a run that has already finished is a no-op.
|
|
160
161
|
*/
|
|
161
162
|
stop(): Promise<void>;
|
|
162
163
|
/**
|
package/dist/scripts.js
CHANGED
|
@@ -122,7 +122,8 @@ export class ScriptRun {
|
|
|
122
122
|
*
|
|
123
123
|
* @returns how the script ended
|
|
124
124
|
*
|
|
125
|
-
*
|
|
125
|
+
* Rejects only on a transport failure - the connection dying, or the run being
|
|
126
|
+
* abandoned. A script that threw is a normal outcome and arrives in the result.
|
|
126
127
|
*/
|
|
127
128
|
async wait() {
|
|
128
129
|
await this.endedPromise;
|
|
@@ -140,8 +141,8 @@ export class ScriptRun {
|
|
|
140
141
|
* at its next operation in the page. Either way the handler sees a `finished`
|
|
141
142
|
* with `stopped` set, unless the local reader is torn down first.
|
|
142
143
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
144
|
+
* Rejects only on a transport failure, and the local reader is detached
|
|
145
|
+
* regardless. Cancelling a run that has already finished is a no-op.
|
|
145
146
|
*/
|
|
146
147
|
async stop() {
|
|
147
148
|
if (this.detached)
|
package/dist/types.d.ts
CHANGED
|
@@ -26,6 +26,46 @@ export interface PageInfo {
|
|
|
26
26
|
viewport: Rect;
|
|
27
27
|
frameTree: FrameInfo;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* SessionUsage is what a session's browser has consumed since the session
|
|
31
|
+
* started: the CPU time and memory of every process that rendered its pages —
|
|
32
|
+
* main frames, cross-site iframes and the workers they host — including
|
|
33
|
+
* processes that have since exited. Work done on the session's behalf in
|
|
34
|
+
* processes it shares with other sessions is not included.
|
|
35
|
+
*
|
|
36
|
+
* {@link CloudBrowser.getUsage} reports it while the session runs, and
|
|
37
|
+
* {@link CloudBrowser.stopBrowser} resolves with the final figures, so there is
|
|
38
|
+
* no need to read it right before stopping.
|
|
39
|
+
*/
|
|
40
|
+
export interface SessionUsage {
|
|
41
|
+
/** Real time since the session's browser was created, in seconds. */
|
|
42
|
+
wallTime: number;
|
|
43
|
+
/**
|
|
44
|
+
* User plus kernel CPU time in seconds. Only time a thread actually ran on a
|
|
45
|
+
* core counts; waiting and idling do not.
|
|
46
|
+
*/
|
|
47
|
+
cpuTime: number;
|
|
48
|
+
/**
|
|
49
|
+
* The least memory the session held once its browser was ready, in bytes.
|
|
50
|
+
* Sampled about once a second.
|
|
51
|
+
*/
|
|
52
|
+
minMemory: number;
|
|
53
|
+
/**
|
|
54
|
+
* The memory held, averaged over wallTime, in bytes; averageMemory * wallTime
|
|
55
|
+
* is the memory-time used. Sampled about once a second, so short spikes count
|
|
56
|
+
* toward the peak but barely toward the average.
|
|
57
|
+
*/
|
|
58
|
+
averageMemory: number;
|
|
59
|
+
/** The most memory held at any one moment, in bytes. */
|
|
60
|
+
peakMemory: number;
|
|
61
|
+
/**
|
|
62
|
+
* Renderer processes that hosted at least one of the session's frames: one
|
|
63
|
+
* per site its pages and cross-site iframes needed.
|
|
64
|
+
*/
|
|
65
|
+
renderersUsed: number;
|
|
66
|
+
/** Child frames created in the session's pages, whether or not they got a process of their own. */
|
|
67
|
+
framesCreated: number;
|
|
68
|
+
}
|
|
29
69
|
/** Header is a single HTTP header (name/value pair) on an intercepted request or response. */
|
|
30
70
|
export interface Header {
|
|
31
71
|
name: string;
|
|
@@ -167,6 +207,11 @@ export interface NetworkCaptureOptions {
|
|
|
167
207
|
* argument order) and where the matched element lives.
|
|
168
208
|
*/
|
|
169
209
|
export interface WaitResult {
|
|
210
|
+
/**
|
|
211
|
+
* False iff nothing matched before the deadline. Redundant with `index` being
|
|
212
|
+
* -1, and carried so every command answers the same question the same way.
|
|
213
|
+
*/
|
|
214
|
+
success: boolean;
|
|
170
215
|
index: number;
|
|
171
216
|
frameId: string;
|
|
172
217
|
backendNodeId: number;
|
|
@@ -283,6 +328,13 @@ export interface NavigateResult {
|
|
|
283
328
|
* purely a TS hint, not a runtime guarantee.
|
|
284
329
|
*/
|
|
285
330
|
export interface EvaluateResult<T = unknown> {
|
|
331
|
+
/**
|
|
332
|
+
* False only when the expression never produced a value, which rejects the
|
|
333
|
+
* call — so a resolved result always has this true. An expression that answers
|
|
334
|
+
* falsy is a successful evaluation, so this does not mean "the answer was
|
|
335
|
+
* false".
|
|
336
|
+
*/
|
|
337
|
+
success: boolean;
|
|
286
338
|
value: T;
|
|
287
339
|
backendNodeId: number;
|
|
288
340
|
isVisible: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browserscale-ts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Official SDK for browserscale — undetected stealth browsers in the cloud. Rent real Chromium sessions with unique fingerprints, built-in proxies, captcha solving, human-like input and live video — scale web scraping and automation without running a single browser yourself.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|