@nexum-hub/browser 0.0.0-stage → 0.0.2
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 +22 -2
- package/browser-extension/assets.js +654 -0
- package/browser-extension/build.mjs +111 -0
- package/browser-extension/clipboard.js +397 -0
- package/browser-extension/connection.js +880 -0
- package/browser-extension/dist/development/assets.js +654 -0
- package/browser-extension/dist/development/clipboard.js +397 -0
- package/browser-extension/dist/development/connection.js +880 -0
- package/browser-extension/dist/development/errors.js +106 -0
- package/browser-extension/dist/development/evaluate.js +160 -0
- package/browser-extension/dist/development/frames.js +256 -0
- package/browser-extension/dist/development/keyboard.js +167 -0
- package/browser-extension/dist/development/manifest.json +35 -0
- package/browser-extension/dist/development/native-node.js +85 -0
- package/browser-extension/dist/development/page-data.js +497 -0
- package/browser-extension/dist/development/page.js +772 -0
- package/browser-extension/dist/development/profile.js +2 -0
- package/browser-extension/dist/development/router.js +5961 -0
- package/browser-extension/dist/development/site-source.js +149 -0
- package/browser-extension/dist/development/transport.js +405 -0
- package/browser-extension/dist/development/visual.js +976 -0
- package/browser-extension/dist/development/worker.js +24 -0
- package/browser-extension/dist/production/assets.js +654 -0
- package/browser-extension/dist/production/clipboard.js +397 -0
- package/browser-extension/dist/production/connection.js +880 -0
- package/browser-extension/dist/production/errors.js +106 -0
- package/browser-extension/dist/production/evaluate.js +160 -0
- package/browser-extension/dist/production/frames.js +256 -0
- package/browser-extension/dist/production/keyboard.js +167 -0
- package/browser-extension/dist/production/manifest.json +35 -0
- package/browser-extension/dist/production/native-node.js +85 -0
- package/browser-extension/dist/production/page-data.js +497 -0
- package/browser-extension/dist/production/page.js +772 -0
- package/browser-extension/dist/production/profile.js +2 -0
- package/browser-extension/dist/production/router.js +5961 -0
- package/browser-extension/dist/production/site-source.js +149 -0
- package/browser-extension/dist/production/transport.js +405 -0
- package/browser-extension/dist/production/visual.js +976 -0
- package/browser-extension/dist/production/worker.js +24 -0
- package/browser-extension/errors.js +106 -0
- package/browser-extension/evaluate.js +160 -0
- package/browser-extension/frames.js +256 -0
- package/browser-extension/keyboard.js +167 -0
- package/browser-extension/native-node.js +85 -0
- package/browser-extension/page-data.js +497 -0
- package/browser-extension/page.js +772 -0
- package/browser-extension/release-info.json +21 -0
- package/browser-extension/route-manifest.json +807 -0
- package/browser-extension/router.js +5961 -0
- package/browser-extension/site-source.js +149 -0
- package/browser-extension/transport.js +405 -0
- package/browser-extension/visual.js +976 -0
- package/browser-extension/worker.js +24 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +894 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/routes.d.ts +6 -0
- package/dist/client/routes.js +777 -0
- package/dist/client/routes.js.map +1 -0
- package/dist/client/serialize.d.ts +16 -0
- package/dist/client/serialize.js +355 -0
- package/dist/client/serialize.js.map +1 -0
- package/dist/client/types.d.ts +1342 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/extension/artifacts.d.ts +60 -0
- package/dist/extension/artifacts.js +493 -0
- package/dist/extension/artifacts.js.map +1 -0
- package/dist/extension/assets.d.ts +10 -0
- package/dist/extension/assets.js +90 -0
- package/dist/extension/assets.js.map +1 -0
- package/dist/extension/batch.d.ts +6 -0
- package/dist/extension/batch.js +138 -0
- package/dist/extension/batch.js.map +1 -0
- package/dist/extension/files.d.ts +16 -0
- package/dist/extension/files.js +594 -0
- package/dist/extension/files.js.map +1 -0
- package/dist/extension/index.d.ts +3 -0
- package/dist/extension/index.js +623 -0
- package/dist/extension/index.js.map +1 -0
- package/dist/extension/protocol.d.ts +81 -0
- package/dist/extension/protocol.js +475 -0
- package/dist/extension/protocol.js.map +1 -0
- package/dist/extension/scope.d.ts +55 -0
- package/dist/extension/scope.js +563 -0
- package/dist/extension/scope.js.map +1 -0
- package/dist/extension/service.d.ts +113 -0
- package/dist/extension/service.js +905 -0
- package/dist/extension/service.js.map +1 -0
- package/docs/README.md +10 -0
- package/docs/api.md +1375 -0
- package/docs/connection.md +9 -0
- package/docs/lifecycle.md +17 -0
- package/docs/usage.md +75 -0
- package/implementation.json +2962 -0
- package/instructions/README.md +8 -0
- package/package.json +80 -4
- package/scripts/discover.js +12 -0
- package/scripts/screenshot.js +9 -0
- package/skills/browser-control/SKILL.md +12 -0
|
@@ -0,0 +1,894 @@
|
|
|
1
|
+
import { browserRoutes } from "./routes.js";
|
|
2
|
+
import { clientError, dataObject, defined, freeze, normalizeBrowserValue, options, plain, queryTarget, requireArgument, targetKey, textMatcher, validateLocatorDescription, validateTarget, } from "./serialize.js";
|
|
3
|
+
export { browserRoutes } from "./routes.js";
|
|
4
|
+
export { normalizeBrowserValue, validateLocatorDescription, } from "./serialize.js";
|
|
5
|
+
const routeMap = new Map(browserRoutes.map((route) => [route.path, route]));
|
|
6
|
+
class Router {
|
|
7
|
+
#methods = new Map();
|
|
8
|
+
#barriers = new Map();
|
|
9
|
+
constructor(methods) {
|
|
10
|
+
requireArgument(plain(methods), "Use the current managed browser method container.");
|
|
11
|
+
for (const route of browserRoutes) {
|
|
12
|
+
let node = methods;
|
|
13
|
+
for (const key of route.path.split(".")) {
|
|
14
|
+
if (node === undefined)
|
|
15
|
+
break;
|
|
16
|
+
requireArgument(plain(node), "A managed route container must be an ordinary data object.");
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(node, key);
|
|
18
|
+
if (!d) {
|
|
19
|
+
node = undefined;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
requireArgument("value" in d, "Managed routes cannot be accessors.");
|
|
23
|
+
node = d.value;
|
|
24
|
+
}
|
|
25
|
+
if (node !== undefined) {
|
|
26
|
+
requireArgument(typeof node === "function", "A managed browser route must be a function.");
|
|
27
|
+
this.#methods.set(route.path, node);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
option(_path, value, _field = "options") {
|
|
32
|
+
// Validation occurs inside the native Promise returned by call(), preserving
|
|
33
|
+
// the async I/O API even when local argument normalization fails.
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
barrier(target, ready) {
|
|
37
|
+
const key = targetKey(target), previous = this.#barriers.get(key);
|
|
38
|
+
const combined = previous
|
|
39
|
+
? Promise.all([previous, ready]).then(() => { })
|
|
40
|
+
: ready;
|
|
41
|
+
this.#barriers.set(key, combined);
|
|
42
|
+
void combined.catch(() => { });
|
|
43
|
+
}
|
|
44
|
+
async call(path, input, barrier = true) {
|
|
45
|
+
const fn = this.#methods.get(path);
|
|
46
|
+
if (!fn)
|
|
47
|
+
throw clientError("CAPABILITY_NOT_ALLOWED", "This managed browser route is not available in the supplied current method table.");
|
|
48
|
+
const fields = defined(input);
|
|
49
|
+
const schema = routeMap.get(path).inputSchema;
|
|
50
|
+
for (const [name, field] of Object.entries(schema.properties)) {
|
|
51
|
+
if (fields[name] !== undefined && field.properties)
|
|
52
|
+
fields[name] = dataObject(fields[name], Object.keys(field.properties));
|
|
53
|
+
}
|
|
54
|
+
const value = normalizeBrowserValue(fields);
|
|
55
|
+
if (path === "cdp.readEvents") {
|
|
56
|
+
const o = value.options;
|
|
57
|
+
if (o?.methods !== undefined)
|
|
58
|
+
requireArgument(Array.isArray(o.methods) && o.methods.length > 0, "CDP method filters must be nonempty.");
|
|
59
|
+
}
|
|
60
|
+
if (path === "tab.screenshot") {
|
|
61
|
+
const o = value.options;
|
|
62
|
+
requireArgument(!(o?.clip !== undefined && o.fullPage === true), "A screenshot cannot combine fullPage with an explicit clip.");
|
|
63
|
+
}
|
|
64
|
+
const target = (value.target ??
|
|
65
|
+
value.locator?.target);
|
|
66
|
+
if (barrier && target?.tabId)
|
|
67
|
+
await this.#barriers.get(targetKey(target));
|
|
68
|
+
return (await Reflect.apply(fn, undefined, [value]));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const locatorDescriptions = new WeakMap();
|
|
72
|
+
function locatorScope(description) {
|
|
73
|
+
return targetKey(description.target) + JSON.stringify(description.framePath);
|
|
74
|
+
}
|
|
75
|
+
function descriptionOf(value) {
|
|
76
|
+
const description = value && typeof value === "object"
|
|
77
|
+
? locatorDescriptions.get(value)
|
|
78
|
+
: undefined;
|
|
79
|
+
requireArgument(description, "A locator combination needs a locator created by this public client.");
|
|
80
|
+
return description;
|
|
81
|
+
}
|
|
82
|
+
function locatorObject(router, input) {
|
|
83
|
+
const description = validateLocatorDescription(input);
|
|
84
|
+
const nested = (query) => locatorObject(router, { ...description, query });
|
|
85
|
+
const descendant = (query) => nested({ kind: "descendant", root: description.query, query });
|
|
86
|
+
const otherQuery = (other) => {
|
|
87
|
+
const right = descriptionOf(other);
|
|
88
|
+
requireArgument(locatorScope(right) === locatorScope(description), "Locator combinations cannot cross browser, connection, tab or frame scopes.");
|
|
89
|
+
return right.query;
|
|
90
|
+
};
|
|
91
|
+
const filter = (value) => {
|
|
92
|
+
const data = dataObject(value, [
|
|
93
|
+
"has",
|
|
94
|
+
"hasNot",
|
|
95
|
+
"hasText",
|
|
96
|
+
"hasNotText",
|
|
97
|
+
"visible",
|
|
98
|
+
]);
|
|
99
|
+
return defined({
|
|
100
|
+
has: data.has === undefined ? undefined : otherQuery(data.has),
|
|
101
|
+
hasNot: data.hasNot === undefined ? undefined : otherQuery(data.hasNot),
|
|
102
|
+
hasText: data.hasText === undefined ? undefined : textMatcher(data.hasText),
|
|
103
|
+
hasNotText: data.hasNotText === undefined
|
|
104
|
+
? undefined
|
|
105
|
+
: textMatcher(data.hasNotText),
|
|
106
|
+
visible: data.visible,
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const invoke = (name, fields = {}) => router.call(`locator.${name}`, { locator: description, ...fields });
|
|
110
|
+
const opts = (name, value) => router.option(`locator.${name}`, value);
|
|
111
|
+
const result = {
|
|
112
|
+
...queryMethods(descendant),
|
|
113
|
+
locator: (selector, value) => {
|
|
114
|
+
const child = {
|
|
115
|
+
kind: "descendant",
|
|
116
|
+
root: description.query,
|
|
117
|
+
query: { kind: "selector", selector },
|
|
118
|
+
};
|
|
119
|
+
return value === undefined
|
|
120
|
+
? nested(child)
|
|
121
|
+
: nested({
|
|
122
|
+
kind: "filter",
|
|
123
|
+
query: child,
|
|
124
|
+
...filter(value),
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
and: (other) => nested({
|
|
128
|
+
kind: "and",
|
|
129
|
+
left: description.query,
|
|
130
|
+
right: otherQuery(other),
|
|
131
|
+
}),
|
|
132
|
+
or: (other) => nested({ kind: "or", left: description.query, right: otherQuery(other) }),
|
|
133
|
+
filter: (value) => nested({
|
|
134
|
+
kind: "filter",
|
|
135
|
+
query: description.query,
|
|
136
|
+
...filter(value),
|
|
137
|
+
}),
|
|
138
|
+
first: () => nested({ kind: "position", query: description.query, at: "first" }),
|
|
139
|
+
last: () => nested({ kind: "position", query: description.query, at: "last" }),
|
|
140
|
+
nth: (at) => nested({ kind: "position", query: description.query, at }),
|
|
141
|
+
all: async () => {
|
|
142
|
+
const rows = await invoke("all");
|
|
143
|
+
requireArgument(Array.isArray(rows), "The managed locator snapshot is invalid.");
|
|
144
|
+
return rows.map((row) => {
|
|
145
|
+
const fixed = validateLocatorDescription(row);
|
|
146
|
+
requireArgument(locatorScope(fixed) === locatorScope(description) &&
|
|
147
|
+
fixed.query.kind === "ref", "Locator.all must return fixed observed members of the same scope.");
|
|
148
|
+
return locatorObject(router, fixed);
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
count: () => invoke("count"),
|
|
152
|
+
allTextContents: (value) => invoke("allTextContents", {
|
|
153
|
+
options: opts("allTextContents", value),
|
|
154
|
+
}),
|
|
155
|
+
click: (value) => invoke("click", { options: opts("click", value) }),
|
|
156
|
+
dblclick: (value) => invoke("dblclick", { options: opts("dblclick", value) }),
|
|
157
|
+
check: (value) => invoke("check", { options: opts("check", value) }),
|
|
158
|
+
uncheck: (value) => invoke("uncheck", { options: opts("uncheck", value) }),
|
|
159
|
+
setChecked: (checked, value) => invoke("setChecked", {
|
|
160
|
+
checked,
|
|
161
|
+
options: opts("setChecked", value),
|
|
162
|
+
}),
|
|
163
|
+
fill: (value, o) => invoke("fill", { value, options: opts("fill", o) }),
|
|
164
|
+
press: (value, o) => invoke("press", { value, options: opts("press", o) }),
|
|
165
|
+
pressSequentially: (value, o) => invoke("pressSequentially", {
|
|
166
|
+
value,
|
|
167
|
+
options: opts("pressSequentially", o),
|
|
168
|
+
}),
|
|
169
|
+
type: (value, o) => invoke("type", { value, options: opts("type", o) }),
|
|
170
|
+
selectOption: (value, o) => invoke("selectOption", { value, options: opts("selectOption", o) }),
|
|
171
|
+
getAttribute: (name, o) => invoke("getAttribute", {
|
|
172
|
+
name,
|
|
173
|
+
options: opts("getAttribute", o),
|
|
174
|
+
}),
|
|
175
|
+
innerText: (o) => invoke("innerText", { options: opts("innerText", o) }),
|
|
176
|
+
textContent: (o) => invoke("textContent", { options: opts("textContent", o) }),
|
|
177
|
+
isEnabled: () => invoke("isEnabled"),
|
|
178
|
+
isVisible: () => invoke("isVisible"),
|
|
179
|
+
waitFor: (value) => invoke("waitFor", { options: opts("waitFor", value) }),
|
|
180
|
+
downloadMedia: (value) => invoke("downloadMedia", {
|
|
181
|
+
options: opts("downloadMedia", value),
|
|
182
|
+
}),
|
|
183
|
+
evaluate: (expression, arg, value) => invoke("evaluate", {
|
|
184
|
+
expression,
|
|
185
|
+
arg,
|
|
186
|
+
options: opts("evaluate", value),
|
|
187
|
+
}),
|
|
188
|
+
evaluateAll: (expression, arg, value) => invoke("evaluateAll", {
|
|
189
|
+
expression,
|
|
190
|
+
arg,
|
|
191
|
+
options: opts("evaluateAll", value),
|
|
192
|
+
}),
|
|
193
|
+
};
|
|
194
|
+
freeze(result);
|
|
195
|
+
locatorDescriptions.set(result, description);
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
function queryMethods(create) {
|
|
199
|
+
return {
|
|
200
|
+
locator: (selector) => create({ kind: "selector", selector }),
|
|
201
|
+
getByRole: (role, value) => {
|
|
202
|
+
const o = options(value, ["exact", "name"]);
|
|
203
|
+
return create(defined({
|
|
204
|
+
kind: "role",
|
|
205
|
+
role,
|
|
206
|
+
exact: o?.exact,
|
|
207
|
+
name: o?.name === undefined ? undefined : textMatcher(o.name),
|
|
208
|
+
}));
|
|
209
|
+
},
|
|
210
|
+
getByLabel: (value, o) => create({
|
|
211
|
+
kind: "label",
|
|
212
|
+
matcher: textMatcher(value, options(o, ["exact"])?.exact),
|
|
213
|
+
}),
|
|
214
|
+
getByPlaceholder: (value, o) => create({
|
|
215
|
+
kind: "placeholder",
|
|
216
|
+
matcher: textMatcher(value, options(o, ["exact"])?.exact),
|
|
217
|
+
}),
|
|
218
|
+
getByText: (value, o) => create({
|
|
219
|
+
kind: "text",
|
|
220
|
+
matcher: textMatcher(value, options(o, ["exact"])?.exact),
|
|
221
|
+
}),
|
|
222
|
+
getByTestId: (value) => create({ kind: "testId", value }),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function frameLocator(router, target, framePath) {
|
|
226
|
+
requireArgument(framePath.length <= 8 &&
|
|
227
|
+
framePath.every((selector) => typeof selector === "string" && selector.length > 0), "At most eight nested frame selectors are allowed.");
|
|
228
|
+
const path = freeze([...framePath]);
|
|
229
|
+
return freeze({
|
|
230
|
+
...queryMethods((query) => locatorObject(router, { target, framePath: path, query })),
|
|
231
|
+
frameLocator: (selector) => frameLocator(router, target, [...path, selector]),
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function makeFrame(router, input, expected) {
|
|
235
|
+
const target = queryTarget(input.target, true);
|
|
236
|
+
requireArgument(targetKey(target) === targetKey(expected), "The frame descriptor belongs to a different control target.");
|
|
237
|
+
requireArgument(Array.isArray(input.framePath) &&
|
|
238
|
+
input.framePath.length <= 8 &&
|
|
239
|
+
input.framePath.every((item) => typeof item === "string" && item.length > 0), "The frame descriptor is invalid.");
|
|
240
|
+
const path = freeze([...input.framePath]);
|
|
241
|
+
return freeze({
|
|
242
|
+
...frameLocator(router, target, path),
|
|
243
|
+
snapshot: (value) => router.call("frame.snapshot", {
|
|
244
|
+
target,
|
|
245
|
+
framePath: path,
|
|
246
|
+
options: router.option("frame.snapshot", value),
|
|
247
|
+
}),
|
|
248
|
+
click: (ref, value) => router.call("frame.click", {
|
|
249
|
+
target,
|
|
250
|
+
framePath: path,
|
|
251
|
+
ref,
|
|
252
|
+
options: router.option("frame.click", value),
|
|
253
|
+
}),
|
|
254
|
+
fill: (ref, text, value) => router.call("frame.fill", {
|
|
255
|
+
target,
|
|
256
|
+
framePath: path,
|
|
257
|
+
ref,
|
|
258
|
+
text,
|
|
259
|
+
options: router.option("frame.fill", value),
|
|
260
|
+
}),
|
|
261
|
+
waitFor: (condition) => router.call("frame.waitFor", {
|
|
262
|
+
target,
|
|
263
|
+
framePath: path,
|
|
264
|
+
condition,
|
|
265
|
+
}),
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function makeDownload(router, input) {
|
|
269
|
+
const target = queryTarget(input.target, true);
|
|
270
|
+
requireArgument(typeof input.downloadId === "string" && input.downloadId.length > 0, "The download descriptor is invalid.");
|
|
271
|
+
const downloadId = input.downloadId;
|
|
272
|
+
return freeze({
|
|
273
|
+
path: (value) => router.call("downloads.path", {
|
|
274
|
+
target,
|
|
275
|
+
downloadId,
|
|
276
|
+
options: router.option("downloads.path", value),
|
|
277
|
+
}),
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function makeChooser(router, input) {
|
|
281
|
+
const target = queryTarget(input.target, true);
|
|
282
|
+
requireArgument(typeof input.chooserId === "string" &&
|
|
283
|
+
Number.isSafeInteger(input.pageVersion) &&
|
|
284
|
+
typeof input.multiple === "boolean", "The chooser descriptor is invalid.");
|
|
285
|
+
const { chooserId, pageVersion, multiple } = input;
|
|
286
|
+
return freeze({
|
|
287
|
+
isMultiple: () => multiple,
|
|
288
|
+
setFiles: (files, value) => router.call("fileChoosers.setFiles", {
|
|
289
|
+
target,
|
|
290
|
+
chooserId,
|
|
291
|
+
pageVersion,
|
|
292
|
+
files,
|
|
293
|
+
options: router.option("fileChoosers.setFiles", value),
|
|
294
|
+
}),
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function makeDialog(router, input, target) {
|
|
298
|
+
const fixed = normalizeBrowserValue(dataObject(input, ["target", "dialogId", "pageVersion", "type", "message"]));
|
|
299
|
+
requireArgument(targetKey(validateTarget(fixed.target, true)) === targetKey(target) &&
|
|
300
|
+
typeof fixed.dialogId === "string" &&
|
|
301
|
+
Number.isSafeInteger(fixed.pageVersion) &&
|
|
302
|
+
typeof fixed.message === "string", "The dialog descriptor is invalid.");
|
|
303
|
+
requireArgument(["alert", "beforeunload", "confirm", "prompt"].includes(fixed.type), "The native dialog kind is invalid.");
|
|
304
|
+
const fields = {
|
|
305
|
+
target,
|
|
306
|
+
dialogId: fixed.dialogId,
|
|
307
|
+
pageVersion: fixed.pageVersion,
|
|
308
|
+
};
|
|
309
|
+
const result = {
|
|
310
|
+
type: fixed.type,
|
|
311
|
+
message: fixed.message,
|
|
312
|
+
dismiss: () => router.call("dialogs.dismiss", fields),
|
|
313
|
+
...(["confirm", "prompt"].includes(fixed.type)
|
|
314
|
+
? {
|
|
315
|
+
accept: async (text) => {
|
|
316
|
+
requireArgument(fixed.type === "prompt" || text === undefined, "Only prompt dialogs accept text.");
|
|
317
|
+
return router.call("dialogs.accept", { ...fields, text });
|
|
318
|
+
},
|
|
319
|
+
}
|
|
320
|
+
: {}),
|
|
321
|
+
};
|
|
322
|
+
return freeze(result);
|
|
323
|
+
}
|
|
324
|
+
function makeWebMcp(router, target) {
|
|
325
|
+
let discovered;
|
|
326
|
+
const checked = (tools) => {
|
|
327
|
+
requireArgument(Array.isArray(tools), "WebMCP discovery did not return tool data.");
|
|
328
|
+
const fixed = normalizeBrowserValue(tools), names = new Set();
|
|
329
|
+
for (const tool of fixed) {
|
|
330
|
+
requireArgument(typeof tool.name === "string" &&
|
|
331
|
+
typeof tool.documentRevision === "string" &&
|
|
332
|
+
typeof tool.registrationRevision === "string" &&
|
|
333
|
+
!names.has(tool.name), "WebMCP registrations require unique names and exact revisions.");
|
|
334
|
+
names.add(tool.name);
|
|
335
|
+
}
|
|
336
|
+
return freeze(fixed);
|
|
337
|
+
};
|
|
338
|
+
const invoke = (tools, name, args) => {
|
|
339
|
+
const tool = tools.find((tool) => tool.name === name);
|
|
340
|
+
requireArgument(tool, "The requested WebMCP tool was not present in this discovery.");
|
|
341
|
+
return router.call("webmcp.invokeTool", {
|
|
342
|
+
target,
|
|
343
|
+
name,
|
|
344
|
+
args,
|
|
345
|
+
tool,
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
const api = {
|
|
349
|
+
async listTools() {
|
|
350
|
+
discovered = checked(await router.call("webmcp.listTools", { target }));
|
|
351
|
+
return [...discovered];
|
|
352
|
+
},
|
|
353
|
+
async invokeTool(name, args) {
|
|
354
|
+
const tools = discovered ?? (await api.listTools());
|
|
355
|
+
return invoke(tools, name, args);
|
|
356
|
+
},
|
|
357
|
+
async fetchTools() {
|
|
358
|
+
const value = await router.call("webmcp.fetchTools", { target });
|
|
359
|
+
const tools = checked(value.tools);
|
|
360
|
+
requireArgument(typeof value.documentRevision === "string" &&
|
|
361
|
+
typeof value.registrationRevision === "string" &&
|
|
362
|
+
tools.every((tool) => tool.documentRevision === value.documentRevision &&
|
|
363
|
+
tool.registrationRevision === value.registrationRevision), "WebMCP discovery revisions are inconsistent.");
|
|
364
|
+
discovered = tools;
|
|
365
|
+
return freeze({
|
|
366
|
+
documentRevision: value.documentRevision,
|
|
367
|
+
registrationRevision: value.registrationRevision,
|
|
368
|
+
tools,
|
|
369
|
+
invokeTool: (name, args) => invoke(tools, name, args),
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
return freeze(api);
|
|
374
|
+
}
|
|
375
|
+
function management(router, target) {
|
|
376
|
+
const call = (path, fields = {}) => router.call(`management.${path}`, { target, ...fields });
|
|
377
|
+
const opts = (path, value) => router.option(`management.${path}`, value);
|
|
378
|
+
return freeze({
|
|
379
|
+
windows: {
|
|
380
|
+
list: () => call("windows.list"),
|
|
381
|
+
getAll: (o) => call("windows.getAll", {
|
|
382
|
+
options: opts("windows.getAll", o),
|
|
383
|
+
}),
|
|
384
|
+
create: (o) => call("windows.create", {
|
|
385
|
+
options: opts("windows.create", o),
|
|
386
|
+
}),
|
|
387
|
+
update: (id, o) => call("windows.update", {
|
|
388
|
+
id,
|
|
389
|
+
options: opts("windows.update", o),
|
|
390
|
+
}),
|
|
391
|
+
},
|
|
392
|
+
tabs: {
|
|
393
|
+
query: (o) => call("tabs.query", { options: opts("tabs.query", o) }),
|
|
394
|
+
get: (id) => call("tabs.get", { id }),
|
|
395
|
+
move: (id, o) => call("tabs.move", { id, options: opts("tabs.move", o) }),
|
|
396
|
+
update: (id, o) => call("tabs.update", {
|
|
397
|
+
id,
|
|
398
|
+
options: opts("tabs.update", o),
|
|
399
|
+
}),
|
|
400
|
+
group: (o) => call("tabs.group", {
|
|
401
|
+
options: opts("tabs.group", o),
|
|
402
|
+
}),
|
|
403
|
+
ungroup: (ids) => call("tabs.ungroup", { ids }),
|
|
404
|
+
close: (id) => call("tabs.close", { id }),
|
|
405
|
+
},
|
|
406
|
+
tabGroups: {
|
|
407
|
+
query: (o) => call("tabGroups.query", {
|
|
408
|
+
options: opts("tabGroups.query", o),
|
|
409
|
+
}),
|
|
410
|
+
get: (id) => call("tabGroups.get", { id }),
|
|
411
|
+
update: (id, o) => call("tabGroups.update", {
|
|
412
|
+
id,
|
|
413
|
+
options: opts("tabGroups.update", o),
|
|
414
|
+
}),
|
|
415
|
+
move: (id, o) => call("tabGroups.move", {
|
|
416
|
+
id,
|
|
417
|
+
options: opts("tabGroups.move", o),
|
|
418
|
+
}),
|
|
419
|
+
},
|
|
420
|
+
bookmarks: {
|
|
421
|
+
search: (query) => call("bookmarks.search", { query }),
|
|
422
|
+
getTree: () => call("bookmarks.getTree"),
|
|
423
|
+
create: (o) => call("bookmarks.create", {
|
|
424
|
+
options: opts("bookmarks.create", o),
|
|
425
|
+
}),
|
|
426
|
+
update: (id, o) => call("bookmarks.update", {
|
|
427
|
+
id,
|
|
428
|
+
options: opts("bookmarks.update", o),
|
|
429
|
+
}),
|
|
430
|
+
move: (id, o) => call("bookmarks.move", {
|
|
431
|
+
id,
|
|
432
|
+
options: opts("bookmarks.move", o),
|
|
433
|
+
}),
|
|
434
|
+
remove: (id) => call("bookmarks.remove", { id }),
|
|
435
|
+
},
|
|
436
|
+
getAuditTrail: (o) => call("getAuditTrail", { options: opts("getAuditTrail", o) }),
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
function makeBrowser(router, value) {
|
|
440
|
+
const info = normalizeBrowserValue(dataObject(value));
|
|
441
|
+
requireArgument(typeof info.id === "string" &&
|
|
442
|
+
typeof info.name === "string" &&
|
|
443
|
+
info.type === "extension" &&
|
|
444
|
+
info.status === "online", "The selected browser descriptor is invalid.");
|
|
445
|
+
const target = queryTarget({
|
|
446
|
+
browserId: info.id,
|
|
447
|
+
bootId: info.bootId,
|
|
448
|
+
browserSessionId: info.browserSessionId,
|
|
449
|
+
generation: info.generation,
|
|
450
|
+
});
|
|
451
|
+
const organization = management(router, target);
|
|
452
|
+
const visibility = freeze({
|
|
453
|
+
get: () => router.call("visibility.get", { target }),
|
|
454
|
+
set: (visible) => router.call("visibility.set", { target, visible }),
|
|
455
|
+
});
|
|
456
|
+
const viewport = freeze({
|
|
457
|
+
set: (options) => router.call("viewport.set", {
|
|
458
|
+
target,
|
|
459
|
+
options: router.option("viewport.set", options),
|
|
460
|
+
}),
|
|
461
|
+
reset: (tabId) => router.call("viewport.reset", { target, tabId }),
|
|
462
|
+
});
|
|
463
|
+
const downloads = freeze({
|
|
464
|
+
list: (options) => router.call("browsers.downloads", {
|
|
465
|
+
target,
|
|
466
|
+
options: router.option("browsers.downloads", options),
|
|
467
|
+
}),
|
|
468
|
+
});
|
|
469
|
+
const capabilities = {
|
|
470
|
+
list: () => router.call("capabilities.browserList", { target }),
|
|
471
|
+
async get(id) {
|
|
472
|
+
const descriptor = await router.call("capabilities.browserGet", { target, id });
|
|
473
|
+
requireArgument(descriptor.id === id, "The capability response does not match its requested identity.");
|
|
474
|
+
if (!descriptor.supported)
|
|
475
|
+
throw clientError("CAPABILITY_NOT_ALLOWED", "The requested browser capability is unavailable in this connection.");
|
|
476
|
+
switch (id) {
|
|
477
|
+
case "management":
|
|
478
|
+
return organization;
|
|
479
|
+
case "visibility":
|
|
480
|
+
return visibility;
|
|
481
|
+
case "viewport":
|
|
482
|
+
return viewport;
|
|
483
|
+
default:
|
|
484
|
+
return freeze(normalizeBrowserValue(descriptor));
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
const tabFrom = (descriptor) => makeTab(router, descriptor, target);
|
|
489
|
+
const tabs = {
|
|
490
|
+
...organization.tabs,
|
|
491
|
+
list: () => router.call("tabs.list", { target }),
|
|
492
|
+
get: async (id) => tabFrom(await router.call("tabs.get", { target, id })),
|
|
493
|
+
new: async (url, o) => tabFrom(await router.call("tabs.new", {
|
|
494
|
+
target,
|
|
495
|
+
url,
|
|
496
|
+
options: router.option("tabs.new", o),
|
|
497
|
+
})),
|
|
498
|
+
selected: async () => {
|
|
499
|
+
const result = await router.call("tabs.selected", { target });
|
|
500
|
+
return result === undefined ? undefined : tabFrom(result);
|
|
501
|
+
},
|
|
502
|
+
select: (id) => router.call("tabs.select", { target, id }),
|
|
503
|
+
content: (options) => router.call("tabs.content", {
|
|
504
|
+
target,
|
|
505
|
+
options: router.option("tabs.content", options),
|
|
506
|
+
}),
|
|
507
|
+
};
|
|
508
|
+
const user = {
|
|
509
|
+
openTabs: () => router.call("user.openTabs", { target }),
|
|
510
|
+
claimTab: async (tab) => tabFrom(await router.call("user.claimTab", { target, tab })),
|
|
511
|
+
getTabContext: (tab) => router.call("user.getTabContext", {
|
|
512
|
+
target,
|
|
513
|
+
tab,
|
|
514
|
+
}),
|
|
515
|
+
};
|
|
516
|
+
return freeze({
|
|
517
|
+
browserId: info.id,
|
|
518
|
+
name: info.name,
|
|
519
|
+
type: "extension",
|
|
520
|
+
profileName: info.profileName,
|
|
521
|
+
downloads,
|
|
522
|
+
tabs,
|
|
523
|
+
user,
|
|
524
|
+
capabilities,
|
|
525
|
+
management: organization,
|
|
526
|
+
windows: organization.windows,
|
|
527
|
+
tabGroups: organization.tabGroups,
|
|
528
|
+
bookmarks: organization.bookmarks,
|
|
529
|
+
visibility,
|
|
530
|
+
viewport,
|
|
531
|
+
documentation: () => router.call("browsers.documentation", { target }),
|
|
532
|
+
history: (options) => router.call("browsers.history", {
|
|
533
|
+
target,
|
|
534
|
+
options: router.option("browsers.history", options),
|
|
535
|
+
}),
|
|
536
|
+
nameSession: (name) => router.call("browsers.nameSession", { target, name }),
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
function makeTab(router, value, browserTarget) {
|
|
540
|
+
const descriptor = dataObject(value, [
|
|
541
|
+
"target",
|
|
542
|
+
"id",
|
|
543
|
+
"title",
|
|
544
|
+
"url",
|
|
545
|
+
"providerTabId",
|
|
546
|
+
"active",
|
|
547
|
+
"windowId",
|
|
548
|
+
"groupId",
|
|
549
|
+
]);
|
|
550
|
+
const target = queryTarget(descriptor.target, true);
|
|
551
|
+
requireArgument((descriptor.id === undefined || descriptor.id === target.tabId) &&
|
|
552
|
+
(!browserTarget ||
|
|
553
|
+
targetKey({ ...target, tabId: undefined, controlEpoch: undefined }) ===
|
|
554
|
+
targetKey(browserTarget)), "The tab descriptor belongs to a different target.");
|
|
555
|
+
const call = (name, fields = {}) => router.call(name, { target, ...fields });
|
|
556
|
+
const opts = (name, value) => router.option(name, value);
|
|
557
|
+
const queries = queryMethods((query) => locatorObject(router, { target, framePath: [], query }));
|
|
558
|
+
const cancelWaiter = async (id, primaryFailed) => {
|
|
559
|
+
try {
|
|
560
|
+
await router.call("waiters.cancel", { id }, false);
|
|
561
|
+
}
|
|
562
|
+
catch (cause) {
|
|
563
|
+
if (!primaryFailed)
|
|
564
|
+
throw cause;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
const arm = (event, value) => {
|
|
568
|
+
const arming = (async () => {
|
|
569
|
+
requireArgument(["navigation", "download", "filechooser"].includes(event), "This event waiter type is unsupported.");
|
|
570
|
+
const fields = options(value, event === "navigation"
|
|
571
|
+
? ["timeoutMs", "url", "waitUntil"]
|
|
572
|
+
: ["timeoutMs"]);
|
|
573
|
+
const info = await router.call("waiters.arm", { target, event, ...fields }, false);
|
|
574
|
+
requireArgument(typeof info.id === "string" &&
|
|
575
|
+
targetKey(validateTarget(info.target, true)) === targetKey(target), "The waiter descriptor does not match its target.");
|
|
576
|
+
return info;
|
|
577
|
+
})();
|
|
578
|
+
router.barrier(target, arming.then(() => { }));
|
|
579
|
+
void arming.catch(() => { });
|
|
580
|
+
return arming;
|
|
581
|
+
};
|
|
582
|
+
const eventWait = (event, value) => {
|
|
583
|
+
const arming = arm(event, value);
|
|
584
|
+
const pending = (async () => {
|
|
585
|
+
let id, failed = false;
|
|
586
|
+
try {
|
|
587
|
+
const info = await arming;
|
|
588
|
+
id = info.id;
|
|
589
|
+
const result = await router.call("waiters.get", { id }, false);
|
|
590
|
+
requireArgument(result.type === event &&
|
|
591
|
+
targetKey(validateTarget(result.target, true)) ===
|
|
592
|
+
targetKey(target), "The waiter event does not match its registration.");
|
|
593
|
+
return result.type === "download"
|
|
594
|
+
? makeDownload(router, {
|
|
595
|
+
target,
|
|
596
|
+
downloadId: result.downloadId,
|
|
597
|
+
suggestedFilename: result.suggestedFilename,
|
|
598
|
+
})
|
|
599
|
+
: makeChooser(router, {
|
|
600
|
+
target,
|
|
601
|
+
chooserId: result.chooserId,
|
|
602
|
+
pageVersion: result.pageVersion,
|
|
603
|
+
multiple: result.multiple,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
catch (cause) {
|
|
607
|
+
failed = true;
|
|
608
|
+
throw cause;
|
|
609
|
+
}
|
|
610
|
+
finally {
|
|
611
|
+
if (id)
|
|
612
|
+
await cancelWaiter(id, failed);
|
|
613
|
+
}
|
|
614
|
+
})();
|
|
615
|
+
void pending.catch(() => { });
|
|
616
|
+
return pending;
|
|
617
|
+
};
|
|
618
|
+
const playwright = {
|
|
619
|
+
...queries,
|
|
620
|
+
domSnapshot: () => call("playwright.domSnapshot"),
|
|
621
|
+
elementInfo: (options) => call("playwright.elementInfo", {
|
|
622
|
+
options: opts("playwright.elementInfo", options),
|
|
623
|
+
}),
|
|
624
|
+
elementScreenshot: (options) => call("playwright.elementScreenshot", {
|
|
625
|
+
options: opts("playwright.elementScreenshot", options),
|
|
626
|
+
}),
|
|
627
|
+
evaluate: (expression, arg, options) => call("playwright.evaluate", {
|
|
628
|
+
expression,
|
|
629
|
+
arg,
|
|
630
|
+
options: opts("playwright.evaluate", options),
|
|
631
|
+
}),
|
|
632
|
+
frameLocator: (selector) => frameLocator(router, target, [selector]),
|
|
633
|
+
async expectNavigation(action, value) {
|
|
634
|
+
requireArgument(typeof action === "function", "expectNavigation requires a local action callback.");
|
|
635
|
+
const arming = arm("navigation", options(value, ["timeoutMs", "url", "waitUntil"]));
|
|
636
|
+
let id, failed = false;
|
|
637
|
+
try {
|
|
638
|
+
const info = await arming;
|
|
639
|
+
id = info.id;
|
|
640
|
+
const result = await action();
|
|
641
|
+
const event = await router.call("waiters.get", { id }, false);
|
|
642
|
+
requireArgument(event.type === "navigation" &&
|
|
643
|
+
targetKey(validateTarget(event.target, true)) === targetKey(target), "The navigation event does not match its registration.");
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
catch (cause) {
|
|
647
|
+
failed = true;
|
|
648
|
+
throw cause;
|
|
649
|
+
}
|
|
650
|
+
finally {
|
|
651
|
+
if (id)
|
|
652
|
+
await cancelWaiter(id, failed);
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
waitForEvent: eventWait,
|
|
656
|
+
waitForDownload: (value) => eventWait("download", value),
|
|
657
|
+
waitForFileChooser: (value) => eventWait("filechooser", value),
|
|
658
|
+
waitForLoadState: (options) => call("playwright.waitForLoadState", {
|
|
659
|
+
options: opts("playwright.waitForLoadState", options),
|
|
660
|
+
}),
|
|
661
|
+
waitForTimeout: (timeoutMs) => call("playwright.waitForTimeout", { timeoutMs }),
|
|
662
|
+
waitForURL: (url, options) => call("playwright.waitForURL", {
|
|
663
|
+
url,
|
|
664
|
+
options: opts("playwright.waitForURL", options),
|
|
665
|
+
}),
|
|
666
|
+
};
|
|
667
|
+
const ax = {
|
|
668
|
+
click: (element, options) => call("ax.click", { element, options: opts("ax.click", options) }),
|
|
669
|
+
drag: (from, to) => call("ax.drag", { from, to }),
|
|
670
|
+
get: (mode, options) => call("ax.get", { mode, options: opts("ax.get", options) }),
|
|
671
|
+
write: (mode, options) => call("ax.write", {
|
|
672
|
+
mode,
|
|
673
|
+
options: opts("ax.write", options),
|
|
674
|
+
}),
|
|
675
|
+
snapshot: (options) => call("ax.snapshot", { options: opts("ax.snapshot", options) }),
|
|
676
|
+
paste: (elementIndex, text, options) => call("ax.paste", {
|
|
677
|
+
elementIndex,
|
|
678
|
+
text,
|
|
679
|
+
options: opts("ax.paste", options),
|
|
680
|
+
}),
|
|
681
|
+
performSecondaryAction: (elementIndex, action) => call("ax.performSecondaryAction", { elementIndex, action }),
|
|
682
|
+
pressKey: (elementIndex, key, options) => call("ax.pressKey", {
|
|
683
|
+
elementIndex,
|
|
684
|
+
key,
|
|
685
|
+
options: opts("ax.pressKey", options),
|
|
686
|
+
}),
|
|
687
|
+
scroll: (element, direction, pages) => call("ax.scroll", { element, direction, pages }),
|
|
688
|
+
selectText: (elementIndex, text, options) => call("ax.selectText", {
|
|
689
|
+
elementIndex,
|
|
690
|
+
text,
|
|
691
|
+
options: opts("ax.selectText", options),
|
|
692
|
+
}),
|
|
693
|
+
setValue: (elementIndex, value) => call("ax.setValue", { elementIndex, value }),
|
|
694
|
+
typeText: (elementIndex, text) => call("ax.typeText", { elementIndex, text }),
|
|
695
|
+
};
|
|
696
|
+
const cua = Object.fromEntries([
|
|
697
|
+
"click",
|
|
698
|
+
"doubleClick",
|
|
699
|
+
"downloadMedia",
|
|
700
|
+
"drag",
|
|
701
|
+
"keypress",
|
|
702
|
+
"move",
|
|
703
|
+
"scroll",
|
|
704
|
+
"type",
|
|
705
|
+
].map((name) => [
|
|
706
|
+
name,
|
|
707
|
+
(value) => call(`cua.${name}`, { options: opts(`cua.${name}`, value) }),
|
|
708
|
+
]));
|
|
709
|
+
const dom = {
|
|
710
|
+
...Object.fromEntries([
|
|
711
|
+
"click",
|
|
712
|
+
"doubleClick",
|
|
713
|
+
"downloadMedia",
|
|
714
|
+
"keypress",
|
|
715
|
+
"scroll",
|
|
716
|
+
"type",
|
|
717
|
+
].map((name) => [
|
|
718
|
+
name,
|
|
719
|
+
(value) => call(`dom.${name}`, { options: opts(`dom.${name}`, value) }),
|
|
720
|
+
])),
|
|
721
|
+
getVisibleTree: () => call("dom.getVisibleTree"),
|
|
722
|
+
fill: (nodeId, text) => call("dom.fill", { nodeId, text }),
|
|
723
|
+
};
|
|
724
|
+
const content = {
|
|
725
|
+
export: () => call("content.export"),
|
|
726
|
+
exportGsuite: (type) => call("content.exportGsuite", { type }),
|
|
727
|
+
exportYouTubeTranscript: () => call("content.exportYouTubeTranscript"),
|
|
728
|
+
};
|
|
729
|
+
const clipboard = {
|
|
730
|
+
read: () => call("clipboard.read"),
|
|
731
|
+
readText: () => call("clipboard.readText"),
|
|
732
|
+
write: (items) => call("clipboard.write", { items }),
|
|
733
|
+
writeText: (text) => call("clipboard.writeText", { text }),
|
|
734
|
+
};
|
|
735
|
+
const assets = {
|
|
736
|
+
list: () => call("pageAssets.list"),
|
|
737
|
+
download: (urls) => call("pageAssets.download", { urls }),
|
|
738
|
+
bundle: (options) => call("pageAssets.bundle", {
|
|
739
|
+
options: opts("pageAssets.bundle", options),
|
|
740
|
+
}),
|
|
741
|
+
};
|
|
742
|
+
const cdp = {
|
|
743
|
+
send: (method, params, options) => call("cdp.send", {
|
|
744
|
+
method,
|
|
745
|
+
params,
|
|
746
|
+
options: opts("cdp.send", options),
|
|
747
|
+
}),
|
|
748
|
+
events: (cursor) => call("cdp.events", {
|
|
749
|
+
cursor,
|
|
750
|
+
}),
|
|
751
|
+
cursor: () => call("cdp.cursor"),
|
|
752
|
+
readEvents: (options) => {
|
|
753
|
+
return call("cdp.readEvents", { options: opts("cdp.readEvents", options) });
|
|
754
|
+
},
|
|
755
|
+
};
|
|
756
|
+
const webmcp = makeWebMcp(router, target);
|
|
757
|
+
const capabilities = {
|
|
758
|
+
list: () => call("capabilities.tabList"),
|
|
759
|
+
async get(id) {
|
|
760
|
+
const info = await call("capabilities.tabGet", { id });
|
|
761
|
+
requireArgument(info.id === id, "The capability descriptor does not match the requested identity.");
|
|
762
|
+
if (!info.supported)
|
|
763
|
+
throw clientError("CAPABILITY_NOT_ALLOWED", "The requested tab capability is unavailable.");
|
|
764
|
+
switch (id) {
|
|
765
|
+
case "pageAssets":
|
|
766
|
+
return assets;
|
|
767
|
+
case "cdp":
|
|
768
|
+
return cdp;
|
|
769
|
+
case "webmcp":
|
|
770
|
+
return webmcp;
|
|
771
|
+
default:
|
|
772
|
+
return freeze(normalizeBrowserValue(info));
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
};
|
|
776
|
+
const result = {
|
|
777
|
+
id: target.tabId,
|
|
778
|
+
ax,
|
|
779
|
+
cua,
|
|
780
|
+
dom,
|
|
781
|
+
content,
|
|
782
|
+
clipboard,
|
|
783
|
+
playwright,
|
|
784
|
+
assets,
|
|
785
|
+
cdp,
|
|
786
|
+
webmcp,
|
|
787
|
+
capabilities,
|
|
788
|
+
goBack: (options) => call("tab.goBack", {
|
|
789
|
+
options: opts("tab.goBack", options),
|
|
790
|
+
}),
|
|
791
|
+
forward: (options) => call("tab.forward", {
|
|
792
|
+
options: opts("tab.forward", options),
|
|
793
|
+
}),
|
|
794
|
+
reload: (options) => call("tab.reload", {
|
|
795
|
+
options: opts("tab.reload", options),
|
|
796
|
+
}),
|
|
797
|
+
navigate: (url, options) => call("tab.navigate", {
|
|
798
|
+
url,
|
|
799
|
+
options: opts("tab.navigate", options),
|
|
800
|
+
}),
|
|
801
|
+
close: () => call("tab.close"),
|
|
802
|
+
title: () => call("tab.title"),
|
|
803
|
+
url: () => call("tab.url"),
|
|
804
|
+
screenshot: (options) => call("tab.screenshot", {
|
|
805
|
+
options: opts("tab.screenshot", options),
|
|
806
|
+
}),
|
|
807
|
+
markDeliverable: () => call("tab.markDeliverable"),
|
|
808
|
+
markHandoff: () => call("tab.markHandoff"),
|
|
809
|
+
requestUserTakeover: (reason) => call("tab.requestUserTakeover", { reason }),
|
|
810
|
+
getJsDialog: async () => {
|
|
811
|
+
const value = await call("tab.getJsDialog");
|
|
812
|
+
return value === undefined
|
|
813
|
+
? undefined
|
|
814
|
+
: makeDialog(router, value, target);
|
|
815
|
+
},
|
|
816
|
+
snapshot: (options) => call("tab.snapshot", {
|
|
817
|
+
options: opts("tab.snapshot", options),
|
|
818
|
+
}),
|
|
819
|
+
click: (ref, options) => call("tab.click", {
|
|
820
|
+
ref,
|
|
821
|
+
options: opts("tab.click", options),
|
|
822
|
+
}),
|
|
823
|
+
fill: (ref, text, options) => call("tab.fill", {
|
|
824
|
+
ref,
|
|
825
|
+
text,
|
|
826
|
+
options: opts("tab.fill", options),
|
|
827
|
+
}),
|
|
828
|
+
press: (key, options) => call("tab.press", {
|
|
829
|
+
key,
|
|
830
|
+
options: opts("tab.press", options),
|
|
831
|
+
}),
|
|
832
|
+
selectOption: (ref, values) => call("tab.selectOption", { ref, values }),
|
|
833
|
+
scroll: (options) => call("tab.scroll", {
|
|
834
|
+
options: opts("tab.scroll", options),
|
|
835
|
+
}),
|
|
836
|
+
hover: (ref, options) => call("tab.hover", {
|
|
837
|
+
ref,
|
|
838
|
+
options: opts("tab.hover", options),
|
|
839
|
+
}),
|
|
840
|
+
focus: (ref) => call("tab.focus", { ref }),
|
|
841
|
+
waitFor: (condition) => call("tab.waitFor", { condition }),
|
|
842
|
+
locator: queries.locator,
|
|
843
|
+
evaluate: (expression, args) => call("tab.evaluate", { expression, args }),
|
|
844
|
+
keyboardDown: (key) => call("tab.keyboardDown", { key }),
|
|
845
|
+
keyboardUp: (key) => call("tab.keyboardUp", { key }),
|
|
846
|
+
frame: async (selector) => makeFrame(router, await call("tab.frame", { selector }), target),
|
|
847
|
+
dialogAccept: (text) => call("tab.dialogAccept", { text }),
|
|
848
|
+
dialogDismiss: () => call("tab.dialogDismiss"),
|
|
849
|
+
contentExport: (options) => call("tab.contentExport", {
|
|
850
|
+
options: opts("tab.contentExport", options),
|
|
851
|
+
}),
|
|
852
|
+
exportGsuite: content.exportGsuite,
|
|
853
|
+
exportYouTubeTranscript: content.exportYouTubeTranscript,
|
|
854
|
+
clipboardReadText: clipboard.readText,
|
|
855
|
+
clipboardRead: clipboard.read,
|
|
856
|
+
clipboardWriteText: (text) => call("clipboard.writeText", { text }),
|
|
857
|
+
clipboardWrite: (items) => call("clipboard.write", { items }),
|
|
858
|
+
setFiles: (ref, files) => call("tab.setFiles", { ref, files }),
|
|
859
|
+
downloads: () => call("tab.downloads"),
|
|
860
|
+
saveDownload: (id, path) => call("tab.saveDownload", { id, path }),
|
|
861
|
+
setViewport: (size) => call("tab.setViewport", {
|
|
862
|
+
size: router.option("tab.setViewport", size, "size"),
|
|
863
|
+
}),
|
|
864
|
+
resetViewport: () => call("tab.resetViewport"),
|
|
865
|
+
devLogs: (options) => call("tab.devLogs", {
|
|
866
|
+
options: opts("tab.devLogs", options),
|
|
867
|
+
}),
|
|
868
|
+
dev: {
|
|
869
|
+
logs: (options) => call("dev.logs", {
|
|
870
|
+
options: opts("dev.logs", options),
|
|
871
|
+
}),
|
|
872
|
+
},
|
|
873
|
+
exportFile: (options) => call("tab.exportFile", {
|
|
874
|
+
options: opts("tab.exportFile", options),
|
|
875
|
+
}),
|
|
876
|
+
};
|
|
877
|
+
return freeze(result);
|
|
878
|
+
}
|
|
879
|
+
/** Construct immutable public facades only. No connection, listener, filesystem or browser I/O occurs here. */
|
|
880
|
+
export function createBrowserClient(methods) {
|
|
881
|
+
const router = new Router(methods);
|
|
882
|
+
return freeze({
|
|
883
|
+
browsers: {
|
|
884
|
+
list: () => router.call("browsers.list", {}),
|
|
885
|
+
get: async (id) => makeBrowser(router, await router.call("browsers.get", { id })),
|
|
886
|
+
getDefault: async () => makeBrowser(router, await router.call("browsers.getDefault", {})),
|
|
887
|
+
getForUrl: async (url) => makeBrowser(router, await router.call("browsers.getForUrl", { url })),
|
|
888
|
+
},
|
|
889
|
+
documentation: {
|
|
890
|
+
get: (name) => router.call("documentation.get", { name }),
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
//# sourceMappingURL=index.js.map
|