wrc-ts 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/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/browser.d.ts +39 -0
- package/dist/browser.js +43 -0
- package/dist/client.d.ts +840 -0
- package/dist/client.js +1264 -0
- package/dist/config.d.ts +65 -0
- package/dist/config.js +78 -0
- package/dist/cookies.d.ts +21 -0
- package/dist/cookies.js +1 -0
- package/dist/defaults.d.ts +19 -0
- package/dist/defaults.js +22 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +21 -0
- package/dist/gen/google/protobuf/empty_pb.d.ts +15 -0
- package/dist/gen/google/protobuf/empty_pb.js +13 -0
- package/dist/gen/wrc_pb.d.ts +2189 -0
- package/dist/gen/wrc_pb.js +328 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +134 -0
- package/dist/internal/convert.d.ts +44 -0
- package/dist/internal/convert.js +250 -0
- package/dist/locator.d.ts +191 -0
- package/dist/locator.js +255 -0
- package/dist/network.d.ts +37 -0
- package/dist/network.js +2 -0
- package/dist/options.d.ts +96 -0
- package/dist/options.js +7 -0
- package/dist/storage.d.ts +14 -0
- package/dist/storage.js +1 -0
- package/dist/types.d.ts +161 -0
- package/dist/types.js +3 -0
- package/dist/wrc.browser.js +5627 -0
- package/dist/ws-transport.d.ts +15 -0
- package/dist/ws-transport.js +99 -0
- package/package.json +80 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestPattern matches a URL pattern in waitForAnyRequest/Response.
|
|
3
|
+
* Set abort to true to drop the request with an empty 200 response
|
|
4
|
+
* instead of letting it through to the network.
|
|
5
|
+
*/
|
|
6
|
+
export interface RequestPattern {
|
|
7
|
+
url: string;
|
|
8
|
+
/** Default false. */
|
|
9
|
+
abort?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Action verb for a {@link HeaderModification}. */
|
|
12
|
+
export type HeaderModificationAction = "add" | "edit" | "remove";
|
|
13
|
+
/**
|
|
14
|
+
* HeaderModification is one entry passed to {@link CloudBrowser.modifyRequest}.
|
|
15
|
+
* Write it as a plain object literal.
|
|
16
|
+
*/
|
|
17
|
+
export interface HeaderModification {
|
|
18
|
+
/**
|
|
19
|
+
* `"add"` inserts a new header, `"edit"` replaces an existing header's
|
|
20
|
+
* value, `"remove"` drops the header.
|
|
21
|
+
*/
|
|
22
|
+
action: HeaderModificationAction;
|
|
23
|
+
/** Header name the action applies to. */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Header value for add/edit; ignored for remove. */
|
|
26
|
+
value?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Positions an `"add"` immediately before the named existing header;
|
|
29
|
+
* otherwise the header is appended at the end. Ignored for edit/remove.
|
|
30
|
+
*/
|
|
31
|
+
before?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Positions an `"add"` immediately after the named existing header.
|
|
34
|
+
* Mirror of `before`; ignored for edit/remove.
|
|
35
|
+
*/
|
|
36
|
+
after?: string;
|
|
37
|
+
}
|
package/dist/network.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** Mouse button used by {@link CloudBrowser.click}. */
|
|
2
|
+
export type Button = "left" | "right" | "middle";
|
|
3
|
+
/** Mouse phase performed by {@link CloudBrowser.click}. */
|
|
4
|
+
export type ClickAction = "click" | "press" | "release";
|
|
5
|
+
/**
|
|
6
|
+
* Optional customization for {@link CloudBrowser.click}. All fields are
|
|
7
|
+
* optional; missing or zero values mean "use the server default".
|
|
8
|
+
*/
|
|
9
|
+
export interface ClickOpts {
|
|
10
|
+
/**
|
|
11
|
+
* Override the locator's frame. Omit to use the locator's own
|
|
12
|
+
* {@link Locator.inFrame} (or the main frame). Pass a specific
|
|
13
|
+
* `frameId` or {@link AllFrames} to search elsewhere.
|
|
14
|
+
*/
|
|
15
|
+
inFrame?: string;
|
|
16
|
+
/** Mouse button. Default `"left"`. */
|
|
17
|
+
button?: Button;
|
|
18
|
+
/** `1` = single click (default), `2` = double-click. */
|
|
19
|
+
clickCount?: number;
|
|
20
|
+
/**
|
|
21
|
+
* `"click"` (default) performs a full mouseDown+mouseUp.
|
|
22
|
+
* `"press"` only dispatches mouseDown, `"release"` only mouseUp at
|
|
23
|
+
* the current cursor position.
|
|
24
|
+
*/
|
|
25
|
+
action?: ClickAction;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Optional customization for {@link CloudBrowser.fill}. All fields are
|
|
29
|
+
* optional; missing values mean "use the server default".
|
|
30
|
+
*/
|
|
31
|
+
export interface FillOpts {
|
|
32
|
+
/**
|
|
33
|
+
* Override the locator's frame. Omit to use the locator's own
|
|
34
|
+
* {@link Locator.inFrame} (or the main frame). Pass a specific
|
|
35
|
+
* `frameId` or {@link AllFrames} to search elsewhere.
|
|
36
|
+
*/
|
|
37
|
+
inFrame?: string;
|
|
38
|
+
/**
|
|
39
|
+
* `true` wipes the field's existing content with Ctrl+A, Delete
|
|
40
|
+
* before typing. Default (`false`) appends to whatever is already
|
|
41
|
+
* in the field.
|
|
42
|
+
*/
|
|
43
|
+
clearFirst?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Optional customization for {@link CloudBrowser.selectByIndex},
|
|
47
|
+
* {@link CloudBrowser.selectByValue} and {@link CloudBrowser.selectByText}.
|
|
48
|
+
*/
|
|
49
|
+
export interface SelectOpts {
|
|
50
|
+
/**
|
|
51
|
+
* Override the locator's frame. Omit to use the locator's own
|
|
52
|
+
* {@link Locator.inFrame} (or the main frame). Pass a specific
|
|
53
|
+
* `frameId` or {@link AllFrames} to search elsewhere.
|
|
54
|
+
*/
|
|
55
|
+
inFrame?: string;
|
|
56
|
+
/**
|
|
57
|
+
* `false` suppresses change/input events. Default (`true`) fires the
|
|
58
|
+
* standard events after the selection.
|
|
59
|
+
*/
|
|
60
|
+
fireEvents?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Optional customization for {@link CloudBrowser.wait} / {@link CloudBrowser.waitForAny}. */
|
|
63
|
+
export interface WaitOpts {
|
|
64
|
+
/** Default `DefaultWaitTimeoutMs` (30 000 ms). */
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
}
|
|
67
|
+
/** Lifecycle event {@link CloudBrowser.navigate} waits for before returning. */
|
|
68
|
+
export type WaitUntil = "load" | "domcontentloaded" | "networkidle";
|
|
69
|
+
/** Optional customization for {@link CloudBrowser.navigate}. */
|
|
70
|
+
export interface NavigateOpts {
|
|
71
|
+
/** Default 30 000 ms. */
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
/** Default "load". */
|
|
74
|
+
waitUntil?: WaitUntil;
|
|
75
|
+
}
|
|
76
|
+
/** Optional customization for {@link CloudBrowser.loadHTML}. */
|
|
77
|
+
export interface LoadHTMLOpts {
|
|
78
|
+
/** Extra headers to attach to the synthetic response. */
|
|
79
|
+
headers?: {
|
|
80
|
+
name: string;
|
|
81
|
+
value: string;
|
|
82
|
+
}[];
|
|
83
|
+
/** Default 200. */
|
|
84
|
+
statusCode?: number;
|
|
85
|
+
}
|
|
86
|
+
/** Depth used by getDOM(). 0 = whole tree (default), >0 = limited depth. */
|
|
87
|
+
export interface GetDOMOpts {
|
|
88
|
+
depth?: number;
|
|
89
|
+
}
|
|
90
|
+
/** Optional customization for {@link CloudBrowser.getObservation}. */
|
|
91
|
+
export interface GetObservationOpts {
|
|
92
|
+
/** Default 200. */
|
|
93
|
+
maxElementsPerFrame?: number;
|
|
94
|
+
/** Default 200. */
|
|
95
|
+
maxTextLength?: number;
|
|
96
|
+
}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Option bags for the element-action methods. All fields are optional —
|
|
2
|
+
// pass nothing (or `{}`) to take all defaults. Empty/zero values mean
|
|
3
|
+
// "use server default".
|
|
4
|
+
//
|
|
5
|
+
// `inFrame` on each opts struct wins over the locator's own .inFrame(...)
|
|
6
|
+
// chain — useful when reusing a locator across frames.
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** StorageItem is a single localStorage key/value pair. */
|
|
2
|
+
export interface StorageItem {
|
|
3
|
+
key: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* StorageOriginEntry groups the localStorage entries of one origin
|
|
8
|
+
* (e.g. "https://example.com"). getStorage() returns these and
|
|
9
|
+
* setStorage() accepts the same shape, so a dump can be fed back verbatim.
|
|
10
|
+
*/
|
|
11
|
+
export interface StorageOriginEntry {
|
|
12
|
+
origin: string;
|
|
13
|
+
items: StorageItem[];
|
|
14
|
+
}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/** Rect mirrors WRC.pdl Rect: position and size in CSS pixels. */
|
|
2
|
+
export interface Rect {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
/** FrameInfo describes a single frame within a page's frame tree. */
|
|
9
|
+
export interface FrameInfo {
|
|
10
|
+
frameId: string;
|
|
11
|
+
url: string;
|
|
12
|
+
isOOPIF: boolean;
|
|
13
|
+
hasJSContext: boolean;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
isVisible: boolean;
|
|
16
|
+
absoluteRect: Rect;
|
|
17
|
+
relativeRect: Rect;
|
|
18
|
+
children: FrameInfo[];
|
|
19
|
+
}
|
|
20
|
+
/** PageInfo describes an open page (tab or popup) inside a browser context. */
|
|
21
|
+
export interface PageInfo {
|
|
22
|
+
pageId: string;
|
|
23
|
+
browserContextId: string;
|
|
24
|
+
url: string;
|
|
25
|
+
title: string;
|
|
26
|
+
viewport: Rect;
|
|
27
|
+
frameTree: FrameInfo;
|
|
28
|
+
}
|
|
29
|
+
/** Header is a single HTTP header (name/value pair) on an intercepted request or response. */
|
|
30
|
+
export interface Header {
|
|
31
|
+
name: string;
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* InterceptedRequest describes an outgoing request captured by
|
|
36
|
+
* {@link CloudBrowser.waitForAnyRequest}.
|
|
37
|
+
*/
|
|
38
|
+
export interface InterceptedRequest {
|
|
39
|
+
method: string;
|
|
40
|
+
url: string;
|
|
41
|
+
headers: Header[];
|
|
42
|
+
body: string;
|
|
43
|
+
resourceType: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* InterceptedResponse describes a network response captured by
|
|
47
|
+
* {@link CloudBrowser.waitForAnyResponse}.
|
|
48
|
+
*/
|
|
49
|
+
export interface InterceptedResponse {
|
|
50
|
+
url: string;
|
|
51
|
+
statusCode: number;
|
|
52
|
+
headers: Header[];
|
|
53
|
+
body: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* WaitResult is the outcome of a {@link CloudBrowser.wait} /
|
|
57
|
+
* {@link CloudBrowser.waitForAny} call: which condition matched (index, in
|
|
58
|
+
* argument order) and where the matched element lives.
|
|
59
|
+
*/
|
|
60
|
+
export interface WaitResult {
|
|
61
|
+
index: number;
|
|
62
|
+
frameId: string;
|
|
63
|
+
backendNodeId: number;
|
|
64
|
+
isVisible: boolean;
|
|
65
|
+
bounds: Rect;
|
|
66
|
+
}
|
|
67
|
+
/** NavigateResult reports where a {@link CloudBrowser.navigate} call ended up after redirects. */
|
|
68
|
+
export interface NavigateResult {
|
|
69
|
+
frameId: string;
|
|
70
|
+
url: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* EvaluateResult carries the outcome of a JS evaluate call.
|
|
74
|
+
*
|
|
75
|
+
* If the expression returned a DOM element, backendNodeId/isVisible/bounds
|
|
76
|
+
* are populated and value is null. Otherwise value holds the parsed JSON
|
|
77
|
+
* value (string/number/boolean/array/object/null). On parse failure value
|
|
78
|
+
* falls back to the raw server string so the caller is never empty-handed.
|
|
79
|
+
*
|
|
80
|
+
* The optional generic T types the .value field for convenience — this is
|
|
81
|
+
* purely a TS hint, not a runtime guarantee.
|
|
82
|
+
*/
|
|
83
|
+
export interface EvaluateResult<T = unknown> {
|
|
84
|
+
value: T;
|
|
85
|
+
backendNodeId: number;
|
|
86
|
+
isVisible: boolean;
|
|
87
|
+
bounds: Rect;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* ElementResult is the outcome of an element interaction such as
|
|
91
|
+
* {@link CloudBrowser.click}, {@link CloudBrowser.fill} or
|
|
92
|
+
* {@link CloudBrowser.scrollTo}: the resolved element plus the
|
|
93
|
+
* root-relative coordinates the action was performed at.
|
|
94
|
+
*/
|
|
95
|
+
export interface ElementResult {
|
|
96
|
+
success: boolean;
|
|
97
|
+
frameId: string;
|
|
98
|
+
backendNodeId: number;
|
|
99
|
+
isVisible: boolean;
|
|
100
|
+
bounds: Rect;
|
|
101
|
+
rootX: number;
|
|
102
|
+
rootY: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* DragResult is the outcome of a {@link CloudBrowser.drag} gesture: the
|
|
106
|
+
* resolved source element and the start/end coordinates of the performed drag.
|
|
107
|
+
*/
|
|
108
|
+
export interface DragResult {
|
|
109
|
+
success: boolean;
|
|
110
|
+
frameId: string;
|
|
111
|
+
backendNodeId: number;
|
|
112
|
+
startX: number;
|
|
113
|
+
startY: number;
|
|
114
|
+
endX: number;
|
|
115
|
+
endY: number;
|
|
116
|
+
}
|
|
117
|
+
/** SelectOptionResult reports which option a selectByXxx call ended up selecting. */
|
|
118
|
+
export interface SelectOptionResult {
|
|
119
|
+
selectedIndex: number;
|
|
120
|
+
selectedValue: string;
|
|
121
|
+
selectedText: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* ObservationResult is the compact page snapshot returned by
|
|
125
|
+
* {@link CloudBrowser.getObservation} — the visible, interactive elements
|
|
126
|
+
* rendered as prompt-friendly text and as JSON.
|
|
127
|
+
*/
|
|
128
|
+
export interface ObservationResult {
|
|
129
|
+
text: string;
|
|
130
|
+
json: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* DOMResult is the full-tree DOM snapshot returned by
|
|
134
|
+
* {@link CloudBrowser.getDOM}, plus its sha256[:8] hash for cheap
|
|
135
|
+
* change detection.
|
|
136
|
+
*/
|
|
137
|
+
export interface DOMResult {
|
|
138
|
+
hash: string;
|
|
139
|
+
dom: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* InspectResult describes the topmost element hit at viewport-relative
|
|
143
|
+
* (x, y). backendNodeId === 0 means nothing was found at that position.
|
|
144
|
+
*/
|
|
145
|
+
export interface InspectResult {
|
|
146
|
+
backendNodeId: number;
|
|
147
|
+
frameId: string;
|
|
148
|
+
tagName: string;
|
|
149
|
+
textContent: string;
|
|
150
|
+
isVisible: boolean;
|
|
151
|
+
bounds: Rect;
|
|
152
|
+
}
|
|
153
|
+
/** RentResponse is the result of renting a browser via the REST API. */
|
|
154
|
+
export interface RentResponse {
|
|
155
|
+
sessionId: string;
|
|
156
|
+
grpcUrl: string;
|
|
157
|
+
countryCode: string;
|
|
158
|
+
timezone: string;
|
|
159
|
+
acceptLanguage: string;
|
|
160
|
+
fingerprint: string;
|
|
161
|
+
}
|
package/dist/types.js
ADDED