@thinkingos/vsl-mcp-server 1.2.16 → 1.3.1
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/dist/index.js +3336 -198
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,2508 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __esm = (fn, res) => function __init() {
|
|
15
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
+
};
|
|
17
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
|
|
42
|
+
// node_modules/ms/index.js
|
|
43
|
+
var require_ms = __commonJS({
|
|
44
|
+
"node_modules/ms/index.js"(exports, module) {
|
|
45
|
+
"use strict";
|
|
46
|
+
var s = 1e3;
|
|
47
|
+
var m = s * 60;
|
|
48
|
+
var h = m * 60;
|
|
49
|
+
var d = h * 24;
|
|
50
|
+
var w = d * 7;
|
|
51
|
+
var y = d * 365.25;
|
|
52
|
+
module.exports = function(val, options) {
|
|
53
|
+
options = options || {};
|
|
54
|
+
var type = typeof val;
|
|
55
|
+
if (type === "string" && val.length > 0) {
|
|
56
|
+
return parse(val);
|
|
57
|
+
} else if (type === "number" && isFinite(val)) {
|
|
58
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
59
|
+
}
|
|
60
|
+
throw new Error(
|
|
61
|
+
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
function parse(str) {
|
|
65
|
+
str = String(str);
|
|
66
|
+
if (str.length > 100) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
70
|
+
str
|
|
71
|
+
);
|
|
72
|
+
if (!match) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var n = parseFloat(match[1]);
|
|
76
|
+
var type = (match[2] || "ms").toLowerCase();
|
|
77
|
+
switch (type) {
|
|
78
|
+
case "years":
|
|
79
|
+
case "year":
|
|
80
|
+
case "yrs":
|
|
81
|
+
case "yr":
|
|
82
|
+
case "y":
|
|
83
|
+
return n * y;
|
|
84
|
+
case "weeks":
|
|
85
|
+
case "week":
|
|
86
|
+
case "w":
|
|
87
|
+
return n * w;
|
|
88
|
+
case "days":
|
|
89
|
+
case "day":
|
|
90
|
+
case "d":
|
|
91
|
+
return n * d;
|
|
92
|
+
case "hours":
|
|
93
|
+
case "hour":
|
|
94
|
+
case "hrs":
|
|
95
|
+
case "hr":
|
|
96
|
+
case "h":
|
|
97
|
+
return n * h;
|
|
98
|
+
case "minutes":
|
|
99
|
+
case "minute":
|
|
100
|
+
case "mins":
|
|
101
|
+
case "min":
|
|
102
|
+
case "m":
|
|
103
|
+
return n * m;
|
|
104
|
+
case "seconds":
|
|
105
|
+
case "second":
|
|
106
|
+
case "secs":
|
|
107
|
+
case "sec":
|
|
108
|
+
case "s":
|
|
109
|
+
return n * s;
|
|
110
|
+
case "milliseconds":
|
|
111
|
+
case "millisecond":
|
|
112
|
+
case "msecs":
|
|
113
|
+
case "msec":
|
|
114
|
+
case "ms":
|
|
115
|
+
return n;
|
|
116
|
+
default:
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function fmtShort(ms) {
|
|
121
|
+
var msAbs = Math.abs(ms);
|
|
122
|
+
if (msAbs >= d) {
|
|
123
|
+
return Math.round(ms / d) + "d";
|
|
124
|
+
}
|
|
125
|
+
if (msAbs >= h) {
|
|
126
|
+
return Math.round(ms / h) + "h";
|
|
127
|
+
}
|
|
128
|
+
if (msAbs >= m) {
|
|
129
|
+
return Math.round(ms / m) + "m";
|
|
130
|
+
}
|
|
131
|
+
if (msAbs >= s) {
|
|
132
|
+
return Math.round(ms / s) + "s";
|
|
133
|
+
}
|
|
134
|
+
return ms + "ms";
|
|
135
|
+
}
|
|
136
|
+
function fmtLong(ms) {
|
|
137
|
+
var msAbs = Math.abs(ms);
|
|
138
|
+
if (msAbs >= d) {
|
|
139
|
+
return plural(ms, msAbs, d, "day");
|
|
140
|
+
}
|
|
141
|
+
if (msAbs >= h) {
|
|
142
|
+
return plural(ms, msAbs, h, "hour");
|
|
143
|
+
}
|
|
144
|
+
if (msAbs >= m) {
|
|
145
|
+
return plural(ms, msAbs, m, "minute");
|
|
146
|
+
}
|
|
147
|
+
if (msAbs >= s) {
|
|
148
|
+
return plural(ms, msAbs, s, "second");
|
|
149
|
+
}
|
|
150
|
+
return ms + " ms";
|
|
151
|
+
}
|
|
152
|
+
function plural(ms, msAbs, n, name) {
|
|
153
|
+
var isPlural = msAbs >= n * 1.5;
|
|
154
|
+
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// node_modules/debug/src/common.js
|
|
160
|
+
var require_common = __commonJS({
|
|
161
|
+
"node_modules/debug/src/common.js"(exports, module) {
|
|
162
|
+
"use strict";
|
|
163
|
+
function setup(env) {
|
|
164
|
+
createDebug.debug = createDebug;
|
|
165
|
+
createDebug.default = createDebug;
|
|
166
|
+
createDebug.coerce = coerce;
|
|
167
|
+
createDebug.disable = disable;
|
|
168
|
+
createDebug.enable = enable;
|
|
169
|
+
createDebug.enabled = enabled;
|
|
170
|
+
createDebug.humanize = require_ms();
|
|
171
|
+
createDebug.destroy = destroy;
|
|
172
|
+
Object.keys(env).forEach((key) => {
|
|
173
|
+
createDebug[key] = env[key];
|
|
174
|
+
});
|
|
175
|
+
createDebug.names = [];
|
|
176
|
+
createDebug.skips = [];
|
|
177
|
+
createDebug.formatters = {};
|
|
178
|
+
function selectColor(namespace) {
|
|
179
|
+
let hash = 0;
|
|
180
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
181
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
182
|
+
hash |= 0;
|
|
183
|
+
}
|
|
184
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
185
|
+
}
|
|
186
|
+
createDebug.selectColor = selectColor;
|
|
187
|
+
function createDebug(namespace) {
|
|
188
|
+
let prevTime;
|
|
189
|
+
let enableOverride = null;
|
|
190
|
+
let namespacesCache;
|
|
191
|
+
let enabledCache;
|
|
192
|
+
function debug3(...args) {
|
|
193
|
+
if (!debug3.enabled) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const self = debug3;
|
|
197
|
+
const curr = Number(/* @__PURE__ */ new Date());
|
|
198
|
+
const ms = curr - (prevTime || curr);
|
|
199
|
+
self.diff = ms;
|
|
200
|
+
self.prev = prevTime;
|
|
201
|
+
self.curr = curr;
|
|
202
|
+
prevTime = curr;
|
|
203
|
+
args[0] = createDebug.coerce(args[0]);
|
|
204
|
+
if (typeof args[0] !== "string") {
|
|
205
|
+
args.unshift("%O");
|
|
206
|
+
}
|
|
207
|
+
let index = 0;
|
|
208
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
209
|
+
if (match === "%%") {
|
|
210
|
+
return "%";
|
|
211
|
+
}
|
|
212
|
+
index++;
|
|
213
|
+
const formatter = createDebug.formatters[format];
|
|
214
|
+
if (typeof formatter === "function") {
|
|
215
|
+
const val = args[index];
|
|
216
|
+
match = formatter.call(self, val);
|
|
217
|
+
args.splice(index, 1);
|
|
218
|
+
index--;
|
|
219
|
+
}
|
|
220
|
+
return match;
|
|
221
|
+
});
|
|
222
|
+
createDebug.formatArgs.call(self, args);
|
|
223
|
+
const logFn = self.log || createDebug.log;
|
|
224
|
+
logFn.apply(self, args);
|
|
225
|
+
}
|
|
226
|
+
debug3.namespace = namespace;
|
|
227
|
+
debug3.useColors = createDebug.useColors();
|
|
228
|
+
debug3.color = createDebug.selectColor(namespace);
|
|
229
|
+
debug3.extend = extend;
|
|
230
|
+
debug3.destroy = createDebug.destroy;
|
|
231
|
+
Object.defineProperty(debug3, "enabled", {
|
|
232
|
+
enumerable: true,
|
|
233
|
+
configurable: false,
|
|
234
|
+
get: () => {
|
|
235
|
+
if (enableOverride !== null) {
|
|
236
|
+
return enableOverride;
|
|
237
|
+
}
|
|
238
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
239
|
+
namespacesCache = createDebug.namespaces;
|
|
240
|
+
enabledCache = createDebug.enabled(namespace);
|
|
241
|
+
}
|
|
242
|
+
return enabledCache;
|
|
243
|
+
},
|
|
244
|
+
set: (v) => {
|
|
245
|
+
enableOverride = v;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (typeof createDebug.init === "function") {
|
|
249
|
+
createDebug.init(debug3);
|
|
250
|
+
}
|
|
251
|
+
return debug3;
|
|
252
|
+
}
|
|
253
|
+
function extend(namespace, delimiter) {
|
|
254
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
255
|
+
newDebug.log = this.log;
|
|
256
|
+
return newDebug;
|
|
257
|
+
}
|
|
258
|
+
function enable(namespaces) {
|
|
259
|
+
createDebug.save(namespaces);
|
|
260
|
+
createDebug.namespaces = namespaces;
|
|
261
|
+
createDebug.names = [];
|
|
262
|
+
createDebug.skips = [];
|
|
263
|
+
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
264
|
+
for (const ns of split) {
|
|
265
|
+
if (ns[0] === "-") {
|
|
266
|
+
createDebug.skips.push(ns.slice(1));
|
|
267
|
+
} else {
|
|
268
|
+
createDebug.names.push(ns);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function matchesTemplate(search, template) {
|
|
273
|
+
let searchIndex = 0;
|
|
274
|
+
let templateIndex = 0;
|
|
275
|
+
let starIndex = -1;
|
|
276
|
+
let matchIndex = 0;
|
|
277
|
+
while (searchIndex < search.length) {
|
|
278
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
|
|
279
|
+
if (template[templateIndex] === "*") {
|
|
280
|
+
starIndex = templateIndex;
|
|
281
|
+
matchIndex = searchIndex;
|
|
282
|
+
templateIndex++;
|
|
283
|
+
} else {
|
|
284
|
+
searchIndex++;
|
|
285
|
+
templateIndex++;
|
|
286
|
+
}
|
|
287
|
+
} else if (starIndex !== -1) {
|
|
288
|
+
templateIndex = starIndex + 1;
|
|
289
|
+
matchIndex++;
|
|
290
|
+
searchIndex = matchIndex;
|
|
291
|
+
} else {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
while (templateIndex < template.length && template[templateIndex] === "*") {
|
|
296
|
+
templateIndex++;
|
|
297
|
+
}
|
|
298
|
+
return templateIndex === template.length;
|
|
299
|
+
}
|
|
300
|
+
function disable() {
|
|
301
|
+
const namespaces = [
|
|
302
|
+
...createDebug.names,
|
|
303
|
+
...createDebug.skips.map((namespace) => "-" + namespace)
|
|
304
|
+
].join(",");
|
|
305
|
+
createDebug.enable("");
|
|
306
|
+
return namespaces;
|
|
307
|
+
}
|
|
308
|
+
function enabled(name) {
|
|
309
|
+
for (const skip of createDebug.skips) {
|
|
310
|
+
if (matchesTemplate(name, skip)) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const ns of createDebug.names) {
|
|
315
|
+
if (matchesTemplate(name, ns)) {
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
function coerce(val) {
|
|
322
|
+
if (val instanceof Error) {
|
|
323
|
+
return val.stack || val.message;
|
|
324
|
+
}
|
|
325
|
+
return val;
|
|
326
|
+
}
|
|
327
|
+
function destroy() {
|
|
328
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
329
|
+
}
|
|
330
|
+
createDebug.enable(createDebug.load());
|
|
331
|
+
return createDebug;
|
|
332
|
+
}
|
|
333
|
+
module.exports = setup;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// node_modules/debug/src/browser.js
|
|
338
|
+
var require_browser = __commonJS({
|
|
339
|
+
"node_modules/debug/src/browser.js"(exports, module) {
|
|
340
|
+
"use strict";
|
|
341
|
+
exports.formatArgs = formatArgs;
|
|
342
|
+
exports.save = save;
|
|
343
|
+
exports.load = load2;
|
|
344
|
+
exports.useColors = useColors;
|
|
345
|
+
exports.storage = localstorage();
|
|
346
|
+
exports.destroy = /* @__PURE__ */ (() => {
|
|
347
|
+
let warned = false;
|
|
348
|
+
return () => {
|
|
349
|
+
if (!warned) {
|
|
350
|
+
warned = true;
|
|
351
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
})();
|
|
355
|
+
exports.colors = [
|
|
356
|
+
"#0000CC",
|
|
357
|
+
"#0000FF",
|
|
358
|
+
"#0033CC",
|
|
359
|
+
"#0033FF",
|
|
360
|
+
"#0066CC",
|
|
361
|
+
"#0066FF",
|
|
362
|
+
"#0099CC",
|
|
363
|
+
"#0099FF",
|
|
364
|
+
"#00CC00",
|
|
365
|
+
"#00CC33",
|
|
366
|
+
"#00CC66",
|
|
367
|
+
"#00CC99",
|
|
368
|
+
"#00CCCC",
|
|
369
|
+
"#00CCFF",
|
|
370
|
+
"#3300CC",
|
|
371
|
+
"#3300FF",
|
|
372
|
+
"#3333CC",
|
|
373
|
+
"#3333FF",
|
|
374
|
+
"#3366CC",
|
|
375
|
+
"#3366FF",
|
|
376
|
+
"#3399CC",
|
|
377
|
+
"#3399FF",
|
|
378
|
+
"#33CC00",
|
|
379
|
+
"#33CC33",
|
|
380
|
+
"#33CC66",
|
|
381
|
+
"#33CC99",
|
|
382
|
+
"#33CCCC",
|
|
383
|
+
"#33CCFF",
|
|
384
|
+
"#6600CC",
|
|
385
|
+
"#6600FF",
|
|
386
|
+
"#6633CC",
|
|
387
|
+
"#6633FF",
|
|
388
|
+
"#66CC00",
|
|
389
|
+
"#66CC33",
|
|
390
|
+
"#9900CC",
|
|
391
|
+
"#9900FF",
|
|
392
|
+
"#9933CC",
|
|
393
|
+
"#9933FF",
|
|
394
|
+
"#99CC00",
|
|
395
|
+
"#99CC33",
|
|
396
|
+
"#CC0000",
|
|
397
|
+
"#CC0033",
|
|
398
|
+
"#CC0066",
|
|
399
|
+
"#CC0099",
|
|
400
|
+
"#CC00CC",
|
|
401
|
+
"#CC00FF",
|
|
402
|
+
"#CC3300",
|
|
403
|
+
"#CC3333",
|
|
404
|
+
"#CC3366",
|
|
405
|
+
"#CC3399",
|
|
406
|
+
"#CC33CC",
|
|
407
|
+
"#CC33FF",
|
|
408
|
+
"#CC6600",
|
|
409
|
+
"#CC6633",
|
|
410
|
+
"#CC9900",
|
|
411
|
+
"#CC9933",
|
|
412
|
+
"#CCCC00",
|
|
413
|
+
"#CCCC33",
|
|
414
|
+
"#FF0000",
|
|
415
|
+
"#FF0033",
|
|
416
|
+
"#FF0066",
|
|
417
|
+
"#FF0099",
|
|
418
|
+
"#FF00CC",
|
|
419
|
+
"#FF00FF",
|
|
420
|
+
"#FF3300",
|
|
421
|
+
"#FF3333",
|
|
422
|
+
"#FF3366",
|
|
423
|
+
"#FF3399",
|
|
424
|
+
"#FF33CC",
|
|
425
|
+
"#FF33FF",
|
|
426
|
+
"#FF6600",
|
|
427
|
+
"#FF6633",
|
|
428
|
+
"#FF9900",
|
|
429
|
+
"#FF9933",
|
|
430
|
+
"#FFCC00",
|
|
431
|
+
"#FFCC33"
|
|
432
|
+
];
|
|
433
|
+
function useColors() {
|
|
434
|
+
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
let m;
|
|
441
|
+
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
442
|
+
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
443
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
444
|
+
typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
445
|
+
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
446
|
+
}
|
|
447
|
+
function formatArgs(args) {
|
|
448
|
+
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
|
|
449
|
+
if (!this.useColors) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const c = "color: " + this.color;
|
|
453
|
+
args.splice(1, 0, c, "color: inherit");
|
|
454
|
+
let index = 0;
|
|
455
|
+
let lastC = 0;
|
|
456
|
+
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
457
|
+
if (match === "%%") {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
index++;
|
|
461
|
+
if (match === "%c") {
|
|
462
|
+
lastC = index;
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
args.splice(lastC, 0, c);
|
|
466
|
+
}
|
|
467
|
+
exports.log = console.debug || console.log || (() => {
|
|
468
|
+
});
|
|
469
|
+
function save(namespaces) {
|
|
470
|
+
try {
|
|
471
|
+
if (namespaces) {
|
|
472
|
+
exports.storage.setItem("debug", namespaces);
|
|
473
|
+
} else {
|
|
474
|
+
exports.storage.removeItem("debug");
|
|
475
|
+
}
|
|
476
|
+
} catch (error) {
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function load2() {
|
|
480
|
+
let r;
|
|
481
|
+
try {
|
|
482
|
+
r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
|
|
483
|
+
} catch (error) {
|
|
484
|
+
}
|
|
485
|
+
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
486
|
+
r = process.env.DEBUG;
|
|
487
|
+
}
|
|
488
|
+
return r;
|
|
489
|
+
}
|
|
490
|
+
function localstorage() {
|
|
491
|
+
try {
|
|
492
|
+
return localStorage;
|
|
493
|
+
} catch (error) {
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
module.exports = require_common()(exports);
|
|
497
|
+
var { formatters } = module.exports;
|
|
498
|
+
formatters.j = function(v) {
|
|
499
|
+
try {
|
|
500
|
+
return JSON.stringify(v);
|
|
501
|
+
} catch (error) {
|
|
502
|
+
return "[UnexpectedJSONParseError]: " + error.message;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// node_modules/has-flag/index.js
|
|
509
|
+
var require_has_flag = __commonJS({
|
|
510
|
+
"node_modules/has-flag/index.js"(exports, module) {
|
|
511
|
+
"use strict";
|
|
512
|
+
module.exports = (flag, argv = process.argv) => {
|
|
513
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
514
|
+
const position = argv.indexOf(prefix + flag);
|
|
515
|
+
const terminatorPosition = argv.indexOf("--");
|
|
516
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// node_modules/supports-color/index.js
|
|
522
|
+
var require_supports_color = __commonJS({
|
|
523
|
+
"node_modules/supports-color/index.js"(exports, module) {
|
|
524
|
+
"use strict";
|
|
525
|
+
var os2 = __require("os");
|
|
526
|
+
var tty = __require("tty");
|
|
527
|
+
var hasFlag = require_has_flag();
|
|
528
|
+
var { env } = process;
|
|
529
|
+
var forceColor;
|
|
530
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
531
|
+
forceColor = 0;
|
|
532
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
533
|
+
forceColor = 1;
|
|
534
|
+
}
|
|
535
|
+
if ("FORCE_COLOR" in env) {
|
|
536
|
+
if (env.FORCE_COLOR === "true") {
|
|
537
|
+
forceColor = 1;
|
|
538
|
+
} else if (env.FORCE_COLOR === "false") {
|
|
539
|
+
forceColor = 0;
|
|
540
|
+
} else {
|
|
541
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function translateLevel(level) {
|
|
545
|
+
if (level === 0) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
level,
|
|
550
|
+
hasBasic: true,
|
|
551
|
+
has256: level >= 2,
|
|
552
|
+
has16m: level >= 3
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
556
|
+
if (forceColor === 0) {
|
|
557
|
+
return 0;
|
|
558
|
+
}
|
|
559
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
560
|
+
return 3;
|
|
561
|
+
}
|
|
562
|
+
if (hasFlag("color=256")) {
|
|
563
|
+
return 2;
|
|
564
|
+
}
|
|
565
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
566
|
+
return 0;
|
|
567
|
+
}
|
|
568
|
+
const min = forceColor || 0;
|
|
569
|
+
if (env.TERM === "dumb") {
|
|
570
|
+
return min;
|
|
571
|
+
}
|
|
572
|
+
if (process.platform === "win32") {
|
|
573
|
+
const osRelease = os2.release().split(".");
|
|
574
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
575
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
576
|
+
}
|
|
577
|
+
return 1;
|
|
578
|
+
}
|
|
579
|
+
if ("CI" in env) {
|
|
580
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
581
|
+
return 1;
|
|
582
|
+
}
|
|
583
|
+
return min;
|
|
584
|
+
}
|
|
585
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
586
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
587
|
+
}
|
|
588
|
+
if (env.COLORTERM === "truecolor") {
|
|
589
|
+
return 3;
|
|
590
|
+
}
|
|
591
|
+
if ("TERM_PROGRAM" in env) {
|
|
592
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
593
|
+
switch (env.TERM_PROGRAM) {
|
|
594
|
+
case "iTerm.app":
|
|
595
|
+
return version >= 3 ? 3 : 2;
|
|
596
|
+
case "Apple_Terminal":
|
|
597
|
+
return 2;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
601
|
+
return 2;
|
|
602
|
+
}
|
|
603
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
604
|
+
return 1;
|
|
605
|
+
}
|
|
606
|
+
if ("COLORTERM" in env) {
|
|
607
|
+
return 1;
|
|
608
|
+
}
|
|
609
|
+
return min;
|
|
610
|
+
}
|
|
611
|
+
function getSupportLevel(stream) {
|
|
612
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
613
|
+
return translateLevel(level);
|
|
614
|
+
}
|
|
615
|
+
module.exports = {
|
|
616
|
+
supportsColor: getSupportLevel,
|
|
617
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
618
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// node_modules/debug/src/node.js
|
|
624
|
+
var require_node = __commonJS({
|
|
625
|
+
"node_modules/debug/src/node.js"(exports, module) {
|
|
626
|
+
"use strict";
|
|
627
|
+
var tty = __require("tty");
|
|
628
|
+
var util = __require("util");
|
|
629
|
+
exports.init = init;
|
|
630
|
+
exports.log = log;
|
|
631
|
+
exports.formatArgs = formatArgs;
|
|
632
|
+
exports.save = save;
|
|
633
|
+
exports.load = load2;
|
|
634
|
+
exports.useColors = useColors;
|
|
635
|
+
exports.destroy = util.deprecate(
|
|
636
|
+
() => {
|
|
637
|
+
},
|
|
638
|
+
"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
|
|
639
|
+
);
|
|
640
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
641
|
+
try {
|
|
642
|
+
const supportsColor = require_supports_color();
|
|
643
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
644
|
+
exports.colors = [
|
|
645
|
+
20,
|
|
646
|
+
21,
|
|
647
|
+
26,
|
|
648
|
+
27,
|
|
649
|
+
32,
|
|
650
|
+
33,
|
|
651
|
+
38,
|
|
652
|
+
39,
|
|
653
|
+
40,
|
|
654
|
+
41,
|
|
655
|
+
42,
|
|
656
|
+
43,
|
|
657
|
+
44,
|
|
658
|
+
45,
|
|
659
|
+
56,
|
|
660
|
+
57,
|
|
661
|
+
62,
|
|
662
|
+
63,
|
|
663
|
+
68,
|
|
664
|
+
69,
|
|
665
|
+
74,
|
|
666
|
+
75,
|
|
667
|
+
76,
|
|
668
|
+
77,
|
|
669
|
+
78,
|
|
670
|
+
79,
|
|
671
|
+
80,
|
|
672
|
+
81,
|
|
673
|
+
92,
|
|
674
|
+
93,
|
|
675
|
+
98,
|
|
676
|
+
99,
|
|
677
|
+
112,
|
|
678
|
+
113,
|
|
679
|
+
128,
|
|
680
|
+
129,
|
|
681
|
+
134,
|
|
682
|
+
135,
|
|
683
|
+
148,
|
|
684
|
+
149,
|
|
685
|
+
160,
|
|
686
|
+
161,
|
|
687
|
+
162,
|
|
688
|
+
163,
|
|
689
|
+
164,
|
|
690
|
+
165,
|
|
691
|
+
166,
|
|
692
|
+
167,
|
|
693
|
+
168,
|
|
694
|
+
169,
|
|
695
|
+
170,
|
|
696
|
+
171,
|
|
697
|
+
172,
|
|
698
|
+
173,
|
|
699
|
+
178,
|
|
700
|
+
179,
|
|
701
|
+
184,
|
|
702
|
+
185,
|
|
703
|
+
196,
|
|
704
|
+
197,
|
|
705
|
+
198,
|
|
706
|
+
199,
|
|
707
|
+
200,
|
|
708
|
+
201,
|
|
709
|
+
202,
|
|
710
|
+
203,
|
|
711
|
+
204,
|
|
712
|
+
205,
|
|
713
|
+
206,
|
|
714
|
+
207,
|
|
715
|
+
208,
|
|
716
|
+
209,
|
|
717
|
+
214,
|
|
718
|
+
215,
|
|
719
|
+
220,
|
|
720
|
+
221
|
|
721
|
+
];
|
|
722
|
+
}
|
|
723
|
+
} catch (error) {
|
|
724
|
+
}
|
|
725
|
+
exports.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
726
|
+
return /^debug_/i.test(key);
|
|
727
|
+
}).reduce((obj, key) => {
|
|
728
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
729
|
+
return k.toUpperCase();
|
|
730
|
+
});
|
|
731
|
+
let val = process.env[key];
|
|
732
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
733
|
+
val = true;
|
|
734
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
735
|
+
val = false;
|
|
736
|
+
} else if (val === "null") {
|
|
737
|
+
val = null;
|
|
738
|
+
} else {
|
|
739
|
+
val = Number(val);
|
|
740
|
+
}
|
|
741
|
+
obj[prop] = val;
|
|
742
|
+
return obj;
|
|
743
|
+
}, {});
|
|
744
|
+
function useColors() {
|
|
745
|
+
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
746
|
+
}
|
|
747
|
+
function formatArgs(args) {
|
|
748
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
749
|
+
if (useColors2) {
|
|
750
|
+
const c = this.color;
|
|
751
|
+
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
752
|
+
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
753
|
+
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
754
|
+
args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
|
|
755
|
+
} else {
|
|
756
|
+
args[0] = getDate() + name + " " + args[0];
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
function getDate() {
|
|
760
|
+
if (exports.inspectOpts.hideDate) {
|
|
761
|
+
return "";
|
|
762
|
+
}
|
|
763
|
+
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
764
|
+
}
|
|
765
|
+
function log(...args) {
|
|
766
|
+
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
|
|
767
|
+
}
|
|
768
|
+
function save(namespaces) {
|
|
769
|
+
if (namespaces) {
|
|
770
|
+
process.env.DEBUG = namespaces;
|
|
771
|
+
} else {
|
|
772
|
+
delete process.env.DEBUG;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function load2() {
|
|
776
|
+
return process.env.DEBUG;
|
|
777
|
+
}
|
|
778
|
+
function init(debug3) {
|
|
779
|
+
debug3.inspectOpts = {};
|
|
780
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
781
|
+
for (let i = 0; i < keys.length; i++) {
|
|
782
|
+
debug3.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
module.exports = require_common()(exports);
|
|
786
|
+
var { formatters } = module.exports;
|
|
787
|
+
formatters.o = function(v) {
|
|
788
|
+
this.inspectOpts.colors = this.useColors;
|
|
789
|
+
return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
790
|
+
};
|
|
791
|
+
formatters.O = function(v) {
|
|
792
|
+
this.inspectOpts.colors = this.useColors;
|
|
793
|
+
return util.inspect(v, this.inspectOpts);
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
// node_modules/debug/src/index.js
|
|
799
|
+
var require_src = __commonJS({
|
|
800
|
+
"node_modules/debug/src/index.js"(exports, module) {
|
|
801
|
+
"use strict";
|
|
802
|
+
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
803
|
+
module.exports = require_browser();
|
|
804
|
+
} else {
|
|
805
|
+
module.exports = require_node();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
// node_modules/playwright-extra/dist/index.esm.js
|
|
811
|
+
var index_esm_exports = {};
|
|
812
|
+
__export(index_esm_exports, {
|
|
813
|
+
PlaywrightExtra: () => PlaywrightExtra,
|
|
814
|
+
PlaywrightExtraClass: () => PlaywrightExtraClass,
|
|
815
|
+
PluginList: () => PluginList,
|
|
816
|
+
_android: () => _android,
|
|
817
|
+
_electron: () => _electron,
|
|
818
|
+
addExtra: () => addExtra,
|
|
819
|
+
chromium: () => chromium,
|
|
820
|
+
default: () => index_esm_default,
|
|
821
|
+
devices: () => devices,
|
|
822
|
+
errors: () => errors,
|
|
823
|
+
firefox: () => firefox,
|
|
824
|
+
request: () => request,
|
|
825
|
+
selectors: () => selectors,
|
|
826
|
+
webkit: () => webkit
|
|
827
|
+
});
|
|
828
|
+
function requirePackages(packageNames) {
|
|
829
|
+
for (const name of packageNames) {
|
|
830
|
+
try {
|
|
831
|
+
return __require(name);
|
|
832
|
+
} catch (_) {
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
function addPuppeteerCompat(object) {
|
|
839
|
+
if (!object || typeof object !== "object") {
|
|
840
|
+
return object;
|
|
841
|
+
}
|
|
842
|
+
if (cache.objectToShim.has(object)) {
|
|
843
|
+
return cache.objectToShim.get(object);
|
|
844
|
+
}
|
|
845
|
+
if (isPuppeteerCompat(object)) {
|
|
846
|
+
return object;
|
|
847
|
+
}
|
|
848
|
+
debug("addPuppeteerCompat", cache.objectToShim.size);
|
|
849
|
+
if (isPlaywrightPage(object) || isPlaywrightFrame(object)) {
|
|
850
|
+
const shim = createPageShim(object);
|
|
851
|
+
cache.objectToShim.set(object, shim);
|
|
852
|
+
return shim;
|
|
853
|
+
}
|
|
854
|
+
if (isPlaywrightBrowser(object)) {
|
|
855
|
+
const shim = createBrowserShim(object);
|
|
856
|
+
cache.objectToShim.set(object, shim);
|
|
857
|
+
return shim;
|
|
858
|
+
}
|
|
859
|
+
debug("Received unknown object:", Reflect.ownKeys(object));
|
|
860
|
+
return object;
|
|
861
|
+
}
|
|
862
|
+
async function getPageCDPSession(page) {
|
|
863
|
+
let session = cache.cdpSession.page.get(page);
|
|
864
|
+
if (session) {
|
|
865
|
+
debug("getPageCDPSession: use existing");
|
|
866
|
+
return session;
|
|
867
|
+
}
|
|
868
|
+
debug("getPageCDPSession: use new");
|
|
869
|
+
const context = isPlaywrightFrame(page) ? page.page().context() : page.context();
|
|
870
|
+
try {
|
|
871
|
+
session = await context.newCDPSession(page);
|
|
872
|
+
cache.cdpSession.page.set(page, session);
|
|
873
|
+
return session;
|
|
874
|
+
} catch (err) {
|
|
875
|
+
debug("getPageCDPSession: error while creating session:", err.message);
|
|
876
|
+
debug("getPageCDPSession: Unable create CDP session (most likely a different browser than chromium) - returning a dummy");
|
|
877
|
+
}
|
|
878
|
+
return dummyCDPClient;
|
|
879
|
+
}
|
|
880
|
+
async function getBrowserCDPSession(browser) {
|
|
881
|
+
let session = cache.cdpSession.browser.get(browser);
|
|
882
|
+
if (session) {
|
|
883
|
+
debug("getBrowserCDPSession: use existing");
|
|
884
|
+
return session;
|
|
885
|
+
}
|
|
886
|
+
debug("getBrowserCDPSession: use new");
|
|
887
|
+
try {
|
|
888
|
+
session = await browser.newBrowserCDPSession();
|
|
889
|
+
cache.cdpSession.browser.set(browser, session);
|
|
890
|
+
return session;
|
|
891
|
+
} catch (err) {
|
|
892
|
+
debug("getBrowserCDPSession: error while creating session:", err.message);
|
|
893
|
+
debug("getBrowserCDPSession: Unable create CDP session (most likely a different browser than chromium) - returning a dummy");
|
|
894
|
+
}
|
|
895
|
+
return dummyCDPClient;
|
|
896
|
+
}
|
|
897
|
+
function createPageShim(page) {
|
|
898
|
+
const objId = Math.random().toString(36).substring(2, 7);
|
|
899
|
+
const shim = new Proxy(page, {
|
|
900
|
+
get(target, prop) {
|
|
901
|
+
if (prop === "isCompatShim" || prop === "isPlaywright") {
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
debug("page - get", objId, prop);
|
|
905
|
+
if (prop === "_client") {
|
|
906
|
+
return () => ({
|
|
907
|
+
send: async (method, params) => {
|
|
908
|
+
const session = await getPageCDPSession(page);
|
|
909
|
+
return await session.send(method, params);
|
|
910
|
+
},
|
|
911
|
+
on: (event, listener) => {
|
|
912
|
+
getPageCDPSession(page).then((session) => {
|
|
913
|
+
session.on(event, listener);
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
if (prop === "setBypassCSP") {
|
|
919
|
+
return async (enabled) => {
|
|
920
|
+
const session = await getPageCDPSession(page);
|
|
921
|
+
return await session.send("Page.setBypassCSP", {
|
|
922
|
+
enabled
|
|
923
|
+
});
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
if (prop === "setUserAgent") {
|
|
927
|
+
return async (userAgent, userAgentMetadata) => {
|
|
928
|
+
const session = await getPageCDPSession(page);
|
|
929
|
+
return await session.send("Emulation.setUserAgentOverride", {
|
|
930
|
+
userAgent,
|
|
931
|
+
userAgentMetadata
|
|
932
|
+
});
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
if (prop === "browser") {
|
|
936
|
+
if (isPlaywrightPage(page)) {
|
|
937
|
+
return () => {
|
|
938
|
+
let browser = page.context().browser();
|
|
939
|
+
if (!browser) {
|
|
940
|
+
debug("page.browser() - not available, most likely due to launchPersistentContext");
|
|
941
|
+
browser = page;
|
|
942
|
+
}
|
|
943
|
+
return addPuppeteerCompat(browser);
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
if (prop === "evaluateOnNewDocument") {
|
|
948
|
+
if (isPlaywrightPage(page)) {
|
|
949
|
+
return async function(pageFunction, ...args) {
|
|
950
|
+
return await page.addInitScript(pageFunction, args[0]);
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if (prop === "userAgent") {
|
|
955
|
+
return async (enabled) => {
|
|
956
|
+
const session = await getPageCDPSession(page);
|
|
957
|
+
const data = await session.send("Browser.getVersion");
|
|
958
|
+
return data.userAgent;
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
return Reflect.get(target, prop);
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
return shim;
|
|
965
|
+
}
|
|
966
|
+
function createBrowserShim(browser) {
|
|
967
|
+
const objId = Math.random().toString(36).substring(2, 7);
|
|
968
|
+
const shim = new Proxy(browser, {
|
|
969
|
+
get(target, prop) {
|
|
970
|
+
if (prop === "isCompatShim" || prop === "isPlaywright") {
|
|
971
|
+
return true;
|
|
972
|
+
}
|
|
973
|
+
debug("browser - get", objId, prop);
|
|
974
|
+
if (prop === "pages") {
|
|
975
|
+
return () => browser.contexts().flatMap((c) => c.pages().map((page) => addPuppeteerCompat(page)));
|
|
976
|
+
}
|
|
977
|
+
if (prop === "userAgent") {
|
|
978
|
+
return async () => {
|
|
979
|
+
const session = await getBrowserCDPSession(browser);
|
|
980
|
+
const data = await session.send("Browser.getVersion");
|
|
981
|
+
return data.userAgent;
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
return Reflect.get(target, prop);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
return shim;
|
|
988
|
+
}
|
|
989
|
+
var import_debug, Loader, playwrightLoader, debug, isPlaywrightPage, isPlaywrightFrame, isPlaywrightBrowser, isPuppeteerCompat, cache, dummyCDPClient, debug$1, PluginList, debug$2, PlaywrightExtraClass, PlaywrightExtra, addExtra, chromium, firefox, webkit, _android, _electron, request, selectors, devices, errors, moduleExports, index_esm_default;
|
|
990
|
+
var init_index_esm = __esm({
|
|
991
|
+
"node_modules/playwright-extra/dist/index.esm.js"() {
|
|
992
|
+
"use strict";
|
|
993
|
+
import_debug = __toESM(require_src());
|
|
994
|
+
Loader = class {
|
|
995
|
+
constructor(moduleName, packageNames) {
|
|
996
|
+
this.moduleName = moduleName;
|
|
997
|
+
this.packageNames = packageNames;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Lazy load a top level export from another module by wrapping it in a JS proxy.
|
|
1001
|
+
*
|
|
1002
|
+
* This allows us to re-export e.g. `devices` from `playwright` while redirecting direct calls
|
|
1003
|
+
* to it to the module version the user has installed, rather than shipping with a hardcoded version.
|
|
1004
|
+
*
|
|
1005
|
+
* If we don't do this and the user doesn't have the target module installed we'd throw immediately when our code is imported.
|
|
1006
|
+
*
|
|
1007
|
+
* We use a "super" Proxy defining all traps, so calls like `Object.keys(playwright.devices).length` will return the correct value.
|
|
1008
|
+
*/
|
|
1009
|
+
lazyloadExportOrDie(exportName) {
|
|
1010
|
+
const that = this;
|
|
1011
|
+
const trapHandler = Object.fromEntries(Object.getOwnPropertyNames(Reflect).map((name) => [
|
|
1012
|
+
name,
|
|
1013
|
+
function(target, ...args) {
|
|
1014
|
+
const moduleExport = that.loadModuleOrDie()[exportName];
|
|
1015
|
+
const customTarget = moduleExport;
|
|
1016
|
+
const result = Reflect[name](customTarget || target, ...args);
|
|
1017
|
+
return result;
|
|
1018
|
+
}
|
|
1019
|
+
]));
|
|
1020
|
+
return new Proxy({}, trapHandler);
|
|
1021
|
+
}
|
|
1022
|
+
/** Load the module if possible */
|
|
1023
|
+
loadModule() {
|
|
1024
|
+
return requirePackages(this.packageNames);
|
|
1025
|
+
}
|
|
1026
|
+
/** Load the module if possible or throw */
|
|
1027
|
+
loadModuleOrDie() {
|
|
1028
|
+
const module = requirePackages(this.packageNames);
|
|
1029
|
+
if (module) {
|
|
1030
|
+
return module;
|
|
1031
|
+
}
|
|
1032
|
+
throw this.requireError;
|
|
1033
|
+
}
|
|
1034
|
+
get requireError() {
|
|
1035
|
+
const moduleNamePretty = this.moduleName.charAt(0).toUpperCase() + this.moduleName.slice(1);
|
|
1036
|
+
return new Error(`
|
|
1037
|
+
${moduleNamePretty} is missing. :-)
|
|
1038
|
+
|
|
1039
|
+
I've tried loading ${this.packageNames.map((p) => `"${p}"`).join(", ")} - no luck.
|
|
1040
|
+
|
|
1041
|
+
Make sure you install one of those packages or use the named 'addExtra' export,
|
|
1042
|
+
to patch a specific (and maybe non-standard) implementation of ${moduleNamePretty}.
|
|
1043
|
+
|
|
1044
|
+
To get the latest stable version of ${moduleNamePretty} run:
|
|
1045
|
+
'yarn add ${this.moduleName}' or 'npm i ${this.moduleName}'
|
|
1046
|
+
`);
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
playwrightLoader = new Loader("playwright", [
|
|
1050
|
+
"playwright-core",
|
|
1051
|
+
"playwright"
|
|
1052
|
+
]);
|
|
1053
|
+
debug = (0, import_debug.default)("playwright-extra:puppeteer-compat");
|
|
1054
|
+
isPlaywrightPage = (obj) => {
|
|
1055
|
+
return "unroute" in obj;
|
|
1056
|
+
};
|
|
1057
|
+
isPlaywrightFrame = (obj) => {
|
|
1058
|
+
return ["parentFrame", "frameLocator"].every((x) => x in obj);
|
|
1059
|
+
};
|
|
1060
|
+
isPlaywrightBrowser = (obj) => {
|
|
1061
|
+
return "newContext" in obj;
|
|
1062
|
+
};
|
|
1063
|
+
isPuppeteerCompat = (obj) => {
|
|
1064
|
+
return !!obj && typeof obj === "object" && !!obj.isCompatShim;
|
|
1065
|
+
};
|
|
1066
|
+
cache = {
|
|
1067
|
+
objectToShim: /* @__PURE__ */ new Map(),
|
|
1068
|
+
cdpSession: {
|
|
1069
|
+
page: /* @__PURE__ */ new Map(),
|
|
1070
|
+
browser: /* @__PURE__ */ new Map()
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
dummyCDPClient = {
|
|
1074
|
+
send: async (...args) => {
|
|
1075
|
+
debug("dummy CDP client called", "send", args);
|
|
1076
|
+
},
|
|
1077
|
+
on: (...args) => {
|
|
1078
|
+
debug("dummy CDP client called", "on", args);
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
debug$1 = (0, import_debug.default)("playwright-extra:plugins");
|
|
1082
|
+
PluginList = class {
|
|
1083
|
+
constructor() {
|
|
1084
|
+
this._plugins = [];
|
|
1085
|
+
this._dependencyDefaults = /* @__PURE__ */ new Map();
|
|
1086
|
+
this._dependencyResolution = /* @__PURE__ */ new Map();
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Get a list of all registered plugins.
|
|
1090
|
+
*/
|
|
1091
|
+
get list() {
|
|
1092
|
+
return this._plugins;
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Get the names of all registered plugins.
|
|
1096
|
+
*/
|
|
1097
|
+
get names() {
|
|
1098
|
+
return this._plugins.map((p) => p.name);
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Add a new plugin to the list (after checking if it's well-formed).
|
|
1102
|
+
*
|
|
1103
|
+
* @param plugin
|
|
1104
|
+
* @internal
|
|
1105
|
+
*/
|
|
1106
|
+
add(plugin) {
|
|
1107
|
+
var _a;
|
|
1108
|
+
if (!this.isValidPluginInstance(plugin)) {
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1111
|
+
if (!!plugin.onPluginRegistered) {
|
|
1112
|
+
plugin.onPluginRegistered({ framework: "playwright" });
|
|
1113
|
+
}
|
|
1114
|
+
if (!!plugin._registerChildClassMembers) {
|
|
1115
|
+
plugin._registerChildClassMembers(Object.getPrototypeOf(plugin));
|
|
1116
|
+
}
|
|
1117
|
+
if ((_a = plugin.requirements) === null || _a === void 0 ? void 0 : _a.has("dataFromPlugins")) {
|
|
1118
|
+
plugin.getDataFromPlugins = this.getData.bind(this);
|
|
1119
|
+
}
|
|
1120
|
+
this._plugins.push(plugin);
|
|
1121
|
+
return true;
|
|
1122
|
+
}
|
|
1123
|
+
/** Check if the shape of a plugin is correct or warn */
|
|
1124
|
+
isValidPluginInstance(plugin) {
|
|
1125
|
+
if (!plugin || typeof plugin !== "object" || !plugin._isPuppeteerExtraPlugin) {
|
|
1126
|
+
console.error(`Warning: Plugin is not derived from PuppeteerExtraPlugin, ignoring.`, plugin);
|
|
1127
|
+
return false;
|
|
1128
|
+
}
|
|
1129
|
+
if (!plugin.name) {
|
|
1130
|
+
console.error(`Warning: Plugin with no name registering, ignoring.`, plugin);
|
|
1131
|
+
return false;
|
|
1132
|
+
}
|
|
1133
|
+
return true;
|
|
1134
|
+
}
|
|
1135
|
+
/** Error callback in case calling a plugin method throws an error. Can be overwritten. */
|
|
1136
|
+
onPluginError(plugin, method, err) {
|
|
1137
|
+
console.warn(`An error occured while executing "${method}" in plugin "${plugin.name}":`, err);
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Define default values for plugins implicitly required through the `dependencies` plugin stanza.
|
|
1141
|
+
*
|
|
1142
|
+
* @param dependencyPath - The string by which the dependency is listed (not the plugin name)
|
|
1143
|
+
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* chromium.use(stealth)
|
|
1146
|
+
* chromium.plugins.setDependencyDefaults('stealth/evasions/webgl.vendor', { vendor: 'Bob', renderer: 'Alice' })
|
|
1147
|
+
*/
|
|
1148
|
+
setDependencyDefaults(dependencyPath, opts) {
|
|
1149
|
+
this._dependencyDefaults.set(dependencyPath, opts);
|
|
1150
|
+
return this;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Define custom plugin modules for plugins implicitly required through the `dependencies` plugin stanza.
|
|
1154
|
+
*
|
|
1155
|
+
* Using this will prevent dynamic imports from being used, which JS bundlers often have issues with.
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* chromium.use(stealth)
|
|
1159
|
+
* chromium.plugins.setDependencyResolution('stealth/evasions/webgl.vendor', VendorPlugin)
|
|
1160
|
+
*/
|
|
1161
|
+
setDependencyResolution(dependencyPath, pluginModule) {
|
|
1162
|
+
this._dependencyResolution.set(dependencyPath, pluginModule);
|
|
1163
|
+
return this;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Prepare plugins to be used (resolve dependencies, ordering)
|
|
1167
|
+
* @internal
|
|
1168
|
+
*/
|
|
1169
|
+
prepare() {
|
|
1170
|
+
this.resolveDependencies();
|
|
1171
|
+
this.order();
|
|
1172
|
+
}
|
|
1173
|
+
/** Return all plugins using the supplied method */
|
|
1174
|
+
filterByMethod(methodName) {
|
|
1175
|
+
return this._plugins.filter((plugin) => {
|
|
1176
|
+
if (!!plugin._childClassMembers && Array.isArray(plugin._childClassMembers)) {
|
|
1177
|
+
return plugin._childClassMembers.includes(methodName);
|
|
1178
|
+
}
|
|
1179
|
+
return methodName in plugin;
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
/** Conditionally add puppeteer compatibility to values provided to the plugins */
|
|
1183
|
+
_addPuppeteerCompatIfNeeded(plugin, method, args) {
|
|
1184
|
+
const canUseShim = plugin._isPuppeteerExtraPlugin && !plugin.noPuppeteerShim;
|
|
1185
|
+
const methodWhitelist = [
|
|
1186
|
+
"onBrowser",
|
|
1187
|
+
"onPageCreated",
|
|
1188
|
+
"onPageClose",
|
|
1189
|
+
"afterConnect",
|
|
1190
|
+
"afterLaunch"
|
|
1191
|
+
];
|
|
1192
|
+
const shouldUseShim = methodWhitelist.includes(method);
|
|
1193
|
+
if (!canUseShim || !shouldUseShim) {
|
|
1194
|
+
return args;
|
|
1195
|
+
}
|
|
1196
|
+
debug$1("add puppeteer compatibility", plugin.name, method);
|
|
1197
|
+
return [...args.map((arg) => addPuppeteerCompat(arg))];
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Dispatch plugin lifecycle events in a typesafe way.
|
|
1201
|
+
* Only Plugins that expose the supplied property will be called.
|
|
1202
|
+
*
|
|
1203
|
+
* Will not await results to dispatch events as fast as possible to all plugins.
|
|
1204
|
+
*
|
|
1205
|
+
* @param method - The lifecycle method name
|
|
1206
|
+
* @param args - Optional: Any arguments to be supplied to the plugin methods
|
|
1207
|
+
* @internal
|
|
1208
|
+
*/
|
|
1209
|
+
dispatch(method, ...args) {
|
|
1210
|
+
var _a, _b;
|
|
1211
|
+
const plugins = this.filterByMethod(method);
|
|
1212
|
+
debug$1("dispatch", method, {
|
|
1213
|
+
all: this._plugins.length,
|
|
1214
|
+
filteredByMethod: plugins.length
|
|
1215
|
+
});
|
|
1216
|
+
for (const plugin of plugins) {
|
|
1217
|
+
try {
|
|
1218
|
+
args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
|
|
1219
|
+
const fnType = (_b = (_a = plugin[method]) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name;
|
|
1220
|
+
debug$1("dispatch to plugin", {
|
|
1221
|
+
plugin: plugin.name,
|
|
1222
|
+
method,
|
|
1223
|
+
fnType
|
|
1224
|
+
});
|
|
1225
|
+
if (fnType === "AsyncFunction") {
|
|
1226
|
+
;
|
|
1227
|
+
plugin[method](...args).catch((err) => this.onPluginError(plugin, method, err));
|
|
1228
|
+
} else {
|
|
1229
|
+
;
|
|
1230
|
+
plugin[method](...args);
|
|
1231
|
+
}
|
|
1232
|
+
} catch (err) {
|
|
1233
|
+
this.onPluginError(plugin, method, err);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Dispatch plugin lifecycle events in a typesafe way.
|
|
1239
|
+
* Only Plugins that expose the supplied property will be called.
|
|
1240
|
+
*
|
|
1241
|
+
* Can also be used to get a definite return value after passing it to plugins:
|
|
1242
|
+
* Calls plugins sequentially and passes on a value (waterfall style).
|
|
1243
|
+
*
|
|
1244
|
+
* The plugins can either modify the value or return an updated one.
|
|
1245
|
+
* Will return the latest, updated value which ran through all plugins.
|
|
1246
|
+
*
|
|
1247
|
+
* By convention only the first argument will be used as the updated value.
|
|
1248
|
+
*
|
|
1249
|
+
* @param method - The lifecycle method name
|
|
1250
|
+
* @param args - Optional: Any arguments to be supplied to the plugin methods
|
|
1251
|
+
* @internal
|
|
1252
|
+
*/
|
|
1253
|
+
async dispatchBlocking(method, ...args) {
|
|
1254
|
+
const plugins = this.filterByMethod(method);
|
|
1255
|
+
debug$1("dispatchBlocking", method, {
|
|
1256
|
+
all: this._plugins.length,
|
|
1257
|
+
filteredByMethod: plugins.length
|
|
1258
|
+
});
|
|
1259
|
+
let retValue = null;
|
|
1260
|
+
for (const plugin of plugins) {
|
|
1261
|
+
try {
|
|
1262
|
+
args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
|
|
1263
|
+
retValue = await plugin[method](...args);
|
|
1264
|
+
if (retValue !== void 0) {
|
|
1265
|
+
args[0] = retValue;
|
|
1266
|
+
}
|
|
1267
|
+
} catch (err) {
|
|
1268
|
+
this.onPluginError(plugin, method, err);
|
|
1269
|
+
return retValue;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
return retValue;
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Order plugins that have expressed a special placement requirement.
|
|
1276
|
+
*
|
|
1277
|
+
* This is useful/necessary for e.g. plugins that depend on the data from other plugins.
|
|
1278
|
+
*
|
|
1279
|
+
* @private
|
|
1280
|
+
*/
|
|
1281
|
+
order() {
|
|
1282
|
+
debug$1("order:before", this.names);
|
|
1283
|
+
const runLast = this._plugins.filter((p) => {
|
|
1284
|
+
var _a;
|
|
1285
|
+
return (_a = p.requirements) === null || _a === void 0 ? void 0 : _a.has("runLast");
|
|
1286
|
+
}).map((p) => p.name);
|
|
1287
|
+
for (const name of runLast) {
|
|
1288
|
+
const index = this._plugins.findIndex((p) => p.name === name);
|
|
1289
|
+
this._plugins.push(this._plugins.splice(index, 1)[0]);
|
|
1290
|
+
}
|
|
1291
|
+
debug$1("order:after", this.names);
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Collects the exposed `data` property of all registered plugins.
|
|
1295
|
+
* Will be reduced/flattened to a single array.
|
|
1296
|
+
*
|
|
1297
|
+
* Can be accessed by plugins that listed the `dataFromPlugins` requirement.
|
|
1298
|
+
*
|
|
1299
|
+
* Implemented mainly for plugins that need data from other plugins (e.g. `user-preferences`).
|
|
1300
|
+
*
|
|
1301
|
+
* @see [PuppeteerExtraPlugin]/data
|
|
1302
|
+
* @param name - Filter data by optional name
|
|
1303
|
+
*
|
|
1304
|
+
* @private
|
|
1305
|
+
*/
|
|
1306
|
+
getData(name) {
|
|
1307
|
+
const data = this._plugins.filter((p) => !!p.data).map((p) => Array.isArray(p.data) ? p.data : [p.data]).reduce((acc, arr) => [...acc, ...arr], []);
|
|
1308
|
+
return name ? data.filter((d) => d.name === name) : data;
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Handle `plugins` stanza (already instantiated plugins that don't require dynamic imports)
|
|
1312
|
+
*/
|
|
1313
|
+
resolvePluginsStanza() {
|
|
1314
|
+
debug$1("resolvePluginsStanza");
|
|
1315
|
+
const pluginNames = new Set(this.names);
|
|
1316
|
+
this._plugins.filter((p) => !!p.plugins && p.plugins.length).filter((p) => !pluginNames.has(p.name)).forEach((parent) => {
|
|
1317
|
+
(parent.plugins || []).forEach((p) => {
|
|
1318
|
+
debug$1(parent.name, "adding missing plugin", p.name);
|
|
1319
|
+
this.add(p);
|
|
1320
|
+
});
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Handle `dependencies` stanza (which requires dynamic imports)
|
|
1325
|
+
*
|
|
1326
|
+
* Plugins can define `dependencies` as a Set or Array of dependency paths, or a Map with additional opts
|
|
1327
|
+
*
|
|
1328
|
+
* @note
|
|
1329
|
+
* - The default opts for implicit dependencies can be defined using `setDependencyDefaults()`
|
|
1330
|
+
* - Dynamic imports can be avoided by providing plugin modules with `setDependencyResolution()`
|
|
1331
|
+
*/
|
|
1332
|
+
resolveDependenciesStanza() {
|
|
1333
|
+
debug$1("resolveDependenciesStanza");
|
|
1334
|
+
const requireDependencyOrDie = (parentName, dependencyPath) => {
|
|
1335
|
+
if (this._dependencyResolution.has(dependencyPath)) {
|
|
1336
|
+
return this._dependencyResolution.get(dependencyPath);
|
|
1337
|
+
}
|
|
1338
|
+
const possiblePrefixes = ["puppeteer-extra-plugin-"];
|
|
1339
|
+
const isAlreadyPrefixed = possiblePrefixes.some((prefix) => dependencyPath.startsWith(prefix));
|
|
1340
|
+
const packagePaths = [];
|
|
1341
|
+
if (!isAlreadyPrefixed) {
|
|
1342
|
+
packagePaths.push(...possiblePrefixes.map((prefix) => prefix + dependencyPath));
|
|
1343
|
+
}
|
|
1344
|
+
packagePaths.push(dependencyPath);
|
|
1345
|
+
const pluginModule = requirePackages(packagePaths);
|
|
1346
|
+
if (pluginModule) {
|
|
1347
|
+
return pluginModule;
|
|
1348
|
+
}
|
|
1349
|
+
const explanation = `
|
|
1350
|
+
The plugin '${parentName}' listed '${dependencyPath}' as dependency,
|
|
1351
|
+
which could not be found. Please install it:
|
|
1352
|
+
|
|
1353
|
+
${packagePaths.map((packagePath) => `yarn add ${packagePath.split("/")[0]}`).join(`
|
|
1354
|
+
or:
|
|
1355
|
+
`)}
|
|
1356
|
+
|
|
1357
|
+
Note: You don't need to require the plugin yourself,
|
|
1358
|
+
unless you want to modify it's default settings.
|
|
1359
|
+
|
|
1360
|
+
If your bundler has issues with dynamic imports take a look at '.plugins.setDependencyResolution()'.
|
|
1361
|
+
`;
|
|
1362
|
+
console.warn(explanation);
|
|
1363
|
+
throw new Error("Plugin dependency not found");
|
|
1364
|
+
};
|
|
1365
|
+
const existingPluginNames = new Set(this.names);
|
|
1366
|
+
const recursivelyLoadMissingDependencies = ({ name: parentName, dependencies }) => {
|
|
1367
|
+
if (!dependencies) {
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
const processDependency = (dependencyPath, opts) => {
|
|
1371
|
+
const pluginModule = requireDependencyOrDie(parentName, dependencyPath);
|
|
1372
|
+
opts = opts || this._dependencyDefaults.get(dependencyPath) || {};
|
|
1373
|
+
const plugin = pluginModule(opts);
|
|
1374
|
+
if (existingPluginNames.has(plugin.name)) {
|
|
1375
|
+
debug$1(parentName, "=> dependency already exists:", plugin.name);
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
existingPluginNames.add(plugin.name);
|
|
1379
|
+
debug$1(parentName, "=> adding new dependency:", plugin.name, opts);
|
|
1380
|
+
this.add(plugin);
|
|
1381
|
+
return recursivelyLoadMissingDependencies(plugin);
|
|
1382
|
+
};
|
|
1383
|
+
if (dependencies instanceof Set || Array.isArray(dependencies)) {
|
|
1384
|
+
return [...dependencies].forEach((dependencyPath) => processDependency(dependencyPath));
|
|
1385
|
+
}
|
|
1386
|
+
if (dependencies instanceof Map) {
|
|
1387
|
+
return dependencies.forEach((v, k) => processDependency(k, v));
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
this.list.forEach(recursivelyLoadMissingDependencies);
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Lightweight plugin dependency management to require plugins and code mods on demand.
|
|
1394
|
+
* @private
|
|
1395
|
+
*/
|
|
1396
|
+
resolveDependencies() {
|
|
1397
|
+
debug$1("resolveDependencies");
|
|
1398
|
+
this.resolvePluginsStanza();
|
|
1399
|
+
this.resolveDependenciesStanza();
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
debug$2 = (0, import_debug.default)("playwright-extra");
|
|
1403
|
+
PlaywrightExtraClass = class {
|
|
1404
|
+
constructor(_launcher) {
|
|
1405
|
+
this._launcher = _launcher;
|
|
1406
|
+
this.plugins = new PluginList();
|
|
1407
|
+
}
|
|
1408
|
+
/**
|
|
1409
|
+
* The **main interface** to register plugins.
|
|
1410
|
+
*
|
|
1411
|
+
* Can be called multiple times to enable multiple plugins.
|
|
1412
|
+
*
|
|
1413
|
+
* Plugins derived from `PuppeteerExtraPlugin` will be used with a compatiblity layer.
|
|
1414
|
+
*
|
|
1415
|
+
* @example
|
|
1416
|
+
* chromium.use(plugin1).use(plugin2)
|
|
1417
|
+
* firefox.use(plugin1).use(plugin2)
|
|
1418
|
+
*
|
|
1419
|
+
* @see [PuppeteerExtraPlugin]
|
|
1420
|
+
*
|
|
1421
|
+
* @return The same `PlaywrightExtra` instance (for optional chaining)
|
|
1422
|
+
*/
|
|
1423
|
+
use(plugin) {
|
|
1424
|
+
const isValid = plugin && "name" in plugin;
|
|
1425
|
+
if (!isValid) {
|
|
1426
|
+
throw new Error("A plugin must be provided to .use()");
|
|
1427
|
+
}
|
|
1428
|
+
if (this.plugins.add(plugin)) {
|
|
1429
|
+
debug$2("Plugin registered", plugin.name);
|
|
1430
|
+
}
|
|
1431
|
+
return this;
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* In order to support a default export which will require vanilla playwright automatically,
|
|
1435
|
+
* as well as `addExtra` to patch a provided launcher, we need to so some gymnastics here.
|
|
1436
|
+
*
|
|
1437
|
+
* Otherwise this would throw immediately, even when only using the `addExtra` export with an arbitrary compatible launcher.
|
|
1438
|
+
*
|
|
1439
|
+
* The solution is to make the vanilla launcher optional and only throw once we try to effectively use and can't find it.
|
|
1440
|
+
*
|
|
1441
|
+
* @internal
|
|
1442
|
+
*/
|
|
1443
|
+
get launcher() {
|
|
1444
|
+
if (!this._launcher) {
|
|
1445
|
+
throw playwrightLoader.requireError;
|
|
1446
|
+
}
|
|
1447
|
+
return this._launcher;
|
|
1448
|
+
}
|
|
1449
|
+
async launch(...args) {
|
|
1450
|
+
if (!this.launcher.launch) {
|
|
1451
|
+
throw new Error('Launcher does not support "launch"');
|
|
1452
|
+
}
|
|
1453
|
+
let [options] = args;
|
|
1454
|
+
options = Object.assign({ args: [] }, options || {});
|
|
1455
|
+
debug$2("launch", options);
|
|
1456
|
+
this.plugins.prepare();
|
|
1457
|
+
options = await this.plugins.dispatchBlocking("beforeLaunch", options) || options;
|
|
1458
|
+
debug$2("launch with options", options);
|
|
1459
|
+
if ("userDataDir" in options) {
|
|
1460
|
+
debug$2("A plugin defined userDataDir during .launch, which isn't supported by playwright - ignoring");
|
|
1461
|
+
delete options.userDataDir;
|
|
1462
|
+
}
|
|
1463
|
+
const browser = await this.launcher["launch"](options);
|
|
1464
|
+
await this.plugins.dispatchBlocking("onBrowser", browser);
|
|
1465
|
+
await this._bindBrowserEvents(browser);
|
|
1466
|
+
await this.plugins.dispatchBlocking("afterLaunch", browser);
|
|
1467
|
+
return browser;
|
|
1468
|
+
}
|
|
1469
|
+
async launchPersistentContext(...args) {
|
|
1470
|
+
if (!this.launcher.launchPersistentContext) {
|
|
1471
|
+
throw new Error('Launcher does not support "launchPersistentContext"');
|
|
1472
|
+
}
|
|
1473
|
+
let [userDataDir, options] = args;
|
|
1474
|
+
options = Object.assign({ args: [] }, options || {});
|
|
1475
|
+
debug$2("launchPersistentContext", options);
|
|
1476
|
+
this.plugins.prepare();
|
|
1477
|
+
options = await this.plugins.dispatchBlocking("beforeLaunch", options) || options;
|
|
1478
|
+
const context = await this.launcher["launchPersistentContext"](userDataDir, options);
|
|
1479
|
+
await this.plugins.dispatchBlocking("afterLaunch", context);
|
|
1480
|
+
this._bindBrowserContextEvents(context);
|
|
1481
|
+
return context;
|
|
1482
|
+
}
|
|
1483
|
+
async connect(wsEndpointOrOptions, wsOptions = {}) {
|
|
1484
|
+
if (!this.launcher.connect) {
|
|
1485
|
+
throw new Error('Launcher does not support "connect"');
|
|
1486
|
+
}
|
|
1487
|
+
this.plugins.prepare();
|
|
1488
|
+
let options = {};
|
|
1489
|
+
let wsEndpointAsString = false;
|
|
1490
|
+
if (typeof wsEndpointOrOptions === "object") {
|
|
1491
|
+
options = Object.assign(Object.assign({}, wsEndpointOrOptions), wsOptions);
|
|
1492
|
+
} else {
|
|
1493
|
+
wsEndpointAsString = true;
|
|
1494
|
+
options = Object.assign({ wsEndpoint: wsEndpointOrOptions }, wsOptions);
|
|
1495
|
+
}
|
|
1496
|
+
debug$2("connect", options);
|
|
1497
|
+
options = await this.plugins.dispatchBlocking("beforeConnect", options) || options;
|
|
1498
|
+
const args = [];
|
|
1499
|
+
const wsEndpoint = options.wsEndpoint;
|
|
1500
|
+
if (wsEndpointAsString) {
|
|
1501
|
+
delete options.wsEndpoint;
|
|
1502
|
+
args.push(wsEndpoint, options);
|
|
1503
|
+
} else {
|
|
1504
|
+
args.push(options);
|
|
1505
|
+
}
|
|
1506
|
+
const browser = await this.launcher["connect"](...args);
|
|
1507
|
+
await this.plugins.dispatchBlocking("onBrowser", browser);
|
|
1508
|
+
await this._bindBrowserEvents(browser);
|
|
1509
|
+
await this.plugins.dispatchBlocking("afterConnect", browser);
|
|
1510
|
+
return browser;
|
|
1511
|
+
}
|
|
1512
|
+
async connectOverCDP(wsEndpointOrOptions, wsOptions = {}) {
|
|
1513
|
+
if (!this.launcher.connectOverCDP) {
|
|
1514
|
+
throw new Error(`Launcher does not implement 'connectOverCDP'`);
|
|
1515
|
+
}
|
|
1516
|
+
this.plugins.prepare();
|
|
1517
|
+
let options = {};
|
|
1518
|
+
let wsEndpointAsString = false;
|
|
1519
|
+
if (typeof wsEndpointOrOptions === "object") {
|
|
1520
|
+
options = Object.assign(Object.assign({}, wsEndpointOrOptions), wsOptions);
|
|
1521
|
+
} else {
|
|
1522
|
+
wsEndpointAsString = true;
|
|
1523
|
+
options = Object.assign({ endpointURL: wsEndpointOrOptions }, wsOptions);
|
|
1524
|
+
}
|
|
1525
|
+
debug$2("connectOverCDP"), options;
|
|
1526
|
+
options = await this.plugins.dispatchBlocking("beforeConnect", options) || options;
|
|
1527
|
+
const args = [];
|
|
1528
|
+
const endpointURL = options.endpointURL;
|
|
1529
|
+
if (wsEndpointAsString) {
|
|
1530
|
+
delete options.endpointURL;
|
|
1531
|
+
args.push(endpointURL, options);
|
|
1532
|
+
} else {
|
|
1533
|
+
args.push(options);
|
|
1534
|
+
}
|
|
1535
|
+
const browser = await this.launcher["connectOverCDP"](...args);
|
|
1536
|
+
await this.plugins.dispatchBlocking("onBrowser", browser);
|
|
1537
|
+
await this._bindBrowserEvents(browser);
|
|
1538
|
+
await this.plugins.dispatchBlocking("afterConnect", browser);
|
|
1539
|
+
return browser;
|
|
1540
|
+
}
|
|
1541
|
+
async _bindBrowserContextEvents(context, contextOptions) {
|
|
1542
|
+
debug$2("_bindBrowserContextEvents");
|
|
1543
|
+
this.plugins.dispatch("onContextCreated", context, contextOptions);
|
|
1544
|
+
context.newPage = /* @__PURE__ */ ((originalMethod, ctx) => {
|
|
1545
|
+
return async () => {
|
|
1546
|
+
const page = await originalMethod.call(ctx);
|
|
1547
|
+
await page.goto("about:blank");
|
|
1548
|
+
return page;
|
|
1549
|
+
};
|
|
1550
|
+
})(context.newPage, context);
|
|
1551
|
+
context.on("close", () => {
|
|
1552
|
+
if (!context.browser()) {
|
|
1553
|
+
this.plugins.dispatch("onDisconnected");
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1556
|
+
context.on("page", (page) => {
|
|
1557
|
+
this.plugins.dispatch("onPageCreated", page);
|
|
1558
|
+
page.on("close", () => {
|
|
1559
|
+
this.plugins.dispatch("onPageClose", page);
|
|
1560
|
+
});
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
async _bindBrowserEvents(browser) {
|
|
1564
|
+
debug$2("_bindPlaywrightBrowserEvents");
|
|
1565
|
+
browser.on("disconnected", () => {
|
|
1566
|
+
this.plugins.dispatch("onDisconnected", browser);
|
|
1567
|
+
});
|
|
1568
|
+
browser.newContext = /* @__PURE__ */ ((originalMethod, ctx) => {
|
|
1569
|
+
return async (options = {}) => {
|
|
1570
|
+
const contextOptions = await this.plugins.dispatchBlocking("beforeContext", options, browser) || options;
|
|
1571
|
+
const context = await originalMethod.call(ctx, contextOptions);
|
|
1572
|
+
this._bindBrowserContextEvents(context, contextOptions);
|
|
1573
|
+
return context;
|
|
1574
|
+
};
|
|
1575
|
+
})(browser.newContext, browser);
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
PlaywrightExtra = new Proxy(PlaywrightExtraClass, {
|
|
1579
|
+
construct(classTarget, args) {
|
|
1580
|
+
debug$2(`create instance of ${classTarget.name}`);
|
|
1581
|
+
const result = Reflect.construct(classTarget, args);
|
|
1582
|
+
return new Proxy(result, {
|
|
1583
|
+
get(target, prop) {
|
|
1584
|
+
if (prop in target) {
|
|
1585
|
+
return Reflect.get(target, prop);
|
|
1586
|
+
}
|
|
1587
|
+
debug$2("proxying property to original launcher: ", prop);
|
|
1588
|
+
return Reflect.get(target.launcher, prop);
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
addExtra = (launcher) => new PlaywrightExtra(launcher);
|
|
1594
|
+
chromium = addExtra((playwrightLoader.loadModule() || {}).chromium);
|
|
1595
|
+
firefox = addExtra((playwrightLoader.loadModule() || {}).firefox);
|
|
1596
|
+
webkit = addExtra((playwrightLoader.loadModule() || {}).webkit);
|
|
1597
|
+
_android = playwrightLoader.lazyloadExportOrDie("_android");
|
|
1598
|
+
_electron = playwrightLoader.lazyloadExportOrDie("_electron");
|
|
1599
|
+
request = playwrightLoader.lazyloadExportOrDie("request");
|
|
1600
|
+
selectors = playwrightLoader.lazyloadExportOrDie("selectors");
|
|
1601
|
+
devices = playwrightLoader.lazyloadExportOrDie("devices");
|
|
1602
|
+
errors = playwrightLoader.lazyloadExportOrDie("errors");
|
|
1603
|
+
moduleExports = {
|
|
1604
|
+
// custom exports
|
|
1605
|
+
PlaywrightExtra,
|
|
1606
|
+
PlaywrightExtraClass,
|
|
1607
|
+
PluginList,
|
|
1608
|
+
addExtra,
|
|
1609
|
+
chromium,
|
|
1610
|
+
firefox,
|
|
1611
|
+
webkit,
|
|
1612
|
+
// vanilla exports
|
|
1613
|
+
_android,
|
|
1614
|
+
_electron,
|
|
1615
|
+
request,
|
|
1616
|
+
selectors,
|
|
1617
|
+
devices,
|
|
1618
|
+
errors
|
|
1619
|
+
};
|
|
1620
|
+
index_esm_default = moduleExports;
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
|
|
1624
|
+
// node_modules/arr-union/index.js
|
|
1625
|
+
var require_arr_union = __commonJS({
|
|
1626
|
+
"node_modules/arr-union/index.js"(exports, module) {
|
|
1627
|
+
"use strict";
|
|
1628
|
+
module.exports = function union(init) {
|
|
1629
|
+
if (!Array.isArray(init)) {
|
|
1630
|
+
throw new TypeError("arr-union expects the first argument to be an array.");
|
|
1631
|
+
}
|
|
1632
|
+
var len = arguments.length;
|
|
1633
|
+
var i = 0;
|
|
1634
|
+
while (++i < len) {
|
|
1635
|
+
var arg = arguments[i];
|
|
1636
|
+
if (!arg) continue;
|
|
1637
|
+
if (!Array.isArray(arg)) {
|
|
1638
|
+
arg = [arg];
|
|
1639
|
+
}
|
|
1640
|
+
for (var j = 0; j < arg.length; j++) {
|
|
1641
|
+
var ele = arg[j];
|
|
1642
|
+
if (init.indexOf(ele) >= 0) {
|
|
1643
|
+
continue;
|
|
1644
|
+
}
|
|
1645
|
+
init.push(ele);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return init;
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
// node_modules/lazy-cache/index.js
|
|
1654
|
+
var require_lazy_cache = __commonJS({
|
|
1655
|
+
"node_modules/lazy-cache/index.js"(exports, module) {
|
|
1656
|
+
"use strict";
|
|
1657
|
+
function lazyCache(fn) {
|
|
1658
|
+
var cache2 = {};
|
|
1659
|
+
var proxy = function(mod, name) {
|
|
1660
|
+
name = name || camelcase(mod);
|
|
1661
|
+
if (process.env.UNLAZY === "true" || process.env.UNLAZY === true || process.env.TRAVIS) {
|
|
1662
|
+
cache2[name] = fn(mod);
|
|
1663
|
+
}
|
|
1664
|
+
Object.defineProperty(proxy, name, {
|
|
1665
|
+
enumerable: true,
|
|
1666
|
+
configurable: true,
|
|
1667
|
+
get: getter
|
|
1668
|
+
});
|
|
1669
|
+
function getter() {
|
|
1670
|
+
if (cache2.hasOwnProperty(name)) {
|
|
1671
|
+
return cache2[name];
|
|
1672
|
+
}
|
|
1673
|
+
return cache2[name] = fn(mod);
|
|
1674
|
+
}
|
|
1675
|
+
return getter;
|
|
1676
|
+
};
|
|
1677
|
+
return proxy;
|
|
1678
|
+
}
|
|
1679
|
+
function camelcase(str) {
|
|
1680
|
+
if (str.length === 1) {
|
|
1681
|
+
return str.toLowerCase();
|
|
1682
|
+
}
|
|
1683
|
+
str = str.replace(/^[\W_]+|[\W_]+$/g, "").toLowerCase();
|
|
1684
|
+
return str.replace(/[\W_]+(\w|$)/g, function(_, ch) {
|
|
1685
|
+
return ch.toUpperCase();
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
module.exports = lazyCache;
|
|
1689
|
+
}
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
// node_modules/for-in/index.js
|
|
1693
|
+
var require_for_in = __commonJS({
|
|
1694
|
+
"node_modules/for-in/index.js"(exports, module) {
|
|
1695
|
+
"use strict";
|
|
1696
|
+
module.exports = function forIn(obj, fn, thisArg) {
|
|
1697
|
+
for (var key in obj) {
|
|
1698
|
+
if (fn.call(thisArg, obj[key], key, obj) === false) {
|
|
1699
|
+
break;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
|
|
1706
|
+
// node_modules/for-own/index.js
|
|
1707
|
+
var require_for_own = __commonJS({
|
|
1708
|
+
"node_modules/for-own/index.js"(exports, module) {
|
|
1709
|
+
"use strict";
|
|
1710
|
+
var forIn = require_for_in();
|
|
1711
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
1712
|
+
module.exports = function forOwn(obj, fn, thisArg) {
|
|
1713
|
+
forIn(obj, function(val, key) {
|
|
1714
|
+
if (hasOwn.call(obj, key)) {
|
|
1715
|
+
return fn.call(thisArg, obj[key], key, obj);
|
|
1716
|
+
}
|
|
1717
|
+
});
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
|
|
1722
|
+
// node_modules/clone-deep/utils.js
|
|
1723
|
+
var require_utils = __commonJS({
|
|
1724
|
+
"node_modules/clone-deep/utils.js"(exports, module) {
|
|
1725
|
+
"use strict";
|
|
1726
|
+
var utils = require_lazy_cache()(__require);
|
|
1727
|
+
var fn = __require;
|
|
1728
|
+
__require = utils;
|
|
1729
|
+
__require("is-plain-object", "isObject");
|
|
1730
|
+
__require("shallow-clone", "clone");
|
|
1731
|
+
__require("kind-of", "typeOf");
|
|
1732
|
+
require_for_own();
|
|
1733
|
+
__require = fn;
|
|
1734
|
+
module.exports = utils;
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
|
|
1738
|
+
// node_modules/clone-deep/index.js
|
|
1739
|
+
var require_clone_deep = __commonJS({
|
|
1740
|
+
"node_modules/clone-deep/index.js"(exports, module) {
|
|
1741
|
+
"use strict";
|
|
1742
|
+
var utils = require_utils();
|
|
1743
|
+
function cloneDeep(val, instanceClone) {
|
|
1744
|
+
switch (utils.typeOf(val)) {
|
|
1745
|
+
case "object":
|
|
1746
|
+
return cloneObjectDeep(val, instanceClone);
|
|
1747
|
+
case "array":
|
|
1748
|
+
return cloneArrayDeep(val, instanceClone);
|
|
1749
|
+
default:
|
|
1750
|
+
return utils.clone(val);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
function cloneObjectDeep(obj, instanceClone) {
|
|
1754
|
+
if (utils.isObject(obj)) {
|
|
1755
|
+
var res = {};
|
|
1756
|
+
utils.forOwn(obj, function(obj2, key) {
|
|
1757
|
+
this[key] = cloneDeep(obj2, instanceClone);
|
|
1758
|
+
}, res);
|
|
1759
|
+
return res;
|
|
1760
|
+
} else if (instanceClone) {
|
|
1761
|
+
return instanceClone(obj);
|
|
1762
|
+
} else {
|
|
1763
|
+
return obj;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
function cloneArrayDeep(arr, instanceClone) {
|
|
1767
|
+
var len = arr.length, res = [];
|
|
1768
|
+
var i = -1;
|
|
1769
|
+
while (++i < len) {
|
|
1770
|
+
res[i] = cloneDeep(arr[i], instanceClone);
|
|
1771
|
+
}
|
|
1772
|
+
return res;
|
|
1773
|
+
}
|
|
1774
|
+
module.exports = cloneDeep;
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
|
|
1778
|
+
// node_modules/is-buffer/index.js
|
|
1779
|
+
var require_is_buffer = __commonJS({
|
|
1780
|
+
"node_modules/is-buffer/index.js"(exports, module) {
|
|
1781
|
+
"use strict";
|
|
1782
|
+
module.exports = function(obj) {
|
|
1783
|
+
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
|
|
1784
|
+
};
|
|
1785
|
+
function isBuffer(obj) {
|
|
1786
|
+
return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
1787
|
+
}
|
|
1788
|
+
function isSlowBuffer(obj) {
|
|
1789
|
+
return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isBuffer(obj.slice(0, 0));
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1793
|
+
|
|
1794
|
+
// node_modules/kind-of/index.js
|
|
1795
|
+
var require_kind_of = __commonJS({
|
|
1796
|
+
"node_modules/kind-of/index.js"(exports, module) {
|
|
1797
|
+
"use strict";
|
|
1798
|
+
var isBuffer = require_is_buffer();
|
|
1799
|
+
var toString = Object.prototype.toString;
|
|
1800
|
+
module.exports = function kindOf(val) {
|
|
1801
|
+
if (typeof val === "undefined") {
|
|
1802
|
+
return "undefined";
|
|
1803
|
+
}
|
|
1804
|
+
if (val === null) {
|
|
1805
|
+
return "null";
|
|
1806
|
+
}
|
|
1807
|
+
if (val === true || val === false || val instanceof Boolean) {
|
|
1808
|
+
return "boolean";
|
|
1809
|
+
}
|
|
1810
|
+
if (typeof val === "string" || val instanceof String) {
|
|
1811
|
+
return "string";
|
|
1812
|
+
}
|
|
1813
|
+
if (typeof val === "number" || val instanceof Number) {
|
|
1814
|
+
return "number";
|
|
1815
|
+
}
|
|
1816
|
+
if (typeof val === "function" || val instanceof Function) {
|
|
1817
|
+
return "function";
|
|
1818
|
+
}
|
|
1819
|
+
if (typeof Array.isArray !== "undefined" && Array.isArray(val)) {
|
|
1820
|
+
return "array";
|
|
1821
|
+
}
|
|
1822
|
+
if (val instanceof RegExp) {
|
|
1823
|
+
return "regexp";
|
|
1824
|
+
}
|
|
1825
|
+
if (val instanceof Date) {
|
|
1826
|
+
return "date";
|
|
1827
|
+
}
|
|
1828
|
+
var type = toString.call(val);
|
|
1829
|
+
if (type === "[object RegExp]") {
|
|
1830
|
+
return "regexp";
|
|
1831
|
+
}
|
|
1832
|
+
if (type === "[object Date]") {
|
|
1833
|
+
return "date";
|
|
1834
|
+
}
|
|
1835
|
+
if (type === "[object Arguments]") {
|
|
1836
|
+
return "arguments";
|
|
1837
|
+
}
|
|
1838
|
+
if (type === "[object Error]") {
|
|
1839
|
+
return "error";
|
|
1840
|
+
}
|
|
1841
|
+
if (isBuffer(val)) {
|
|
1842
|
+
return "buffer";
|
|
1843
|
+
}
|
|
1844
|
+
if (type === "[object Set]") {
|
|
1845
|
+
return "set";
|
|
1846
|
+
}
|
|
1847
|
+
if (type === "[object WeakSet]") {
|
|
1848
|
+
return "weakset";
|
|
1849
|
+
}
|
|
1850
|
+
if (type === "[object Map]") {
|
|
1851
|
+
return "map";
|
|
1852
|
+
}
|
|
1853
|
+
if (type === "[object WeakMap]") {
|
|
1854
|
+
return "weakmap";
|
|
1855
|
+
}
|
|
1856
|
+
if (type === "[object Symbol]") {
|
|
1857
|
+
return "symbol";
|
|
1858
|
+
}
|
|
1859
|
+
if (type === "[object Int8Array]") {
|
|
1860
|
+
return "int8array";
|
|
1861
|
+
}
|
|
1862
|
+
if (type === "[object Uint8Array]") {
|
|
1863
|
+
return "uint8array";
|
|
1864
|
+
}
|
|
1865
|
+
if (type === "[object Uint8ClampedArray]") {
|
|
1866
|
+
return "uint8clampedarray";
|
|
1867
|
+
}
|
|
1868
|
+
if (type === "[object Int16Array]") {
|
|
1869
|
+
return "int16array";
|
|
1870
|
+
}
|
|
1871
|
+
if (type === "[object Uint16Array]") {
|
|
1872
|
+
return "uint16array";
|
|
1873
|
+
}
|
|
1874
|
+
if (type === "[object Int32Array]") {
|
|
1875
|
+
return "int32array";
|
|
1876
|
+
}
|
|
1877
|
+
if (type === "[object Uint32Array]") {
|
|
1878
|
+
return "uint32array";
|
|
1879
|
+
}
|
|
1880
|
+
if (type === "[object Float32Array]") {
|
|
1881
|
+
return "float32array";
|
|
1882
|
+
}
|
|
1883
|
+
if (type === "[object Float64Array]") {
|
|
1884
|
+
return "float64array";
|
|
1885
|
+
}
|
|
1886
|
+
return "object";
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
});
|
|
1890
|
+
|
|
1891
|
+
// node_modules/merge-deep/index.js
|
|
1892
|
+
var require_merge_deep = __commonJS({
|
|
1893
|
+
"node_modules/merge-deep/index.js"(exports, module) {
|
|
1894
|
+
"use strict";
|
|
1895
|
+
var union = require_arr_union();
|
|
1896
|
+
var clone = require_clone_deep();
|
|
1897
|
+
var typeOf = require_kind_of();
|
|
1898
|
+
module.exports = function mergeDeep(orig, objects) {
|
|
1899
|
+
if (!isObject(orig) && !Array.isArray(orig)) {
|
|
1900
|
+
orig = {};
|
|
1901
|
+
}
|
|
1902
|
+
var target = clone(orig);
|
|
1903
|
+
var len = arguments.length;
|
|
1904
|
+
var idx = 0;
|
|
1905
|
+
while (++idx < len) {
|
|
1906
|
+
var val = arguments[idx];
|
|
1907
|
+
if (isObject(val) || Array.isArray(val)) {
|
|
1908
|
+
merge2(target, val);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
return target;
|
|
1912
|
+
};
|
|
1913
|
+
function merge2(target, obj) {
|
|
1914
|
+
for (var key in obj) {
|
|
1915
|
+
if (!isValidKey(key) || !hasOwn(obj, key)) {
|
|
1916
|
+
continue;
|
|
1917
|
+
}
|
|
1918
|
+
var oldVal = obj[key];
|
|
1919
|
+
var newVal = target[key];
|
|
1920
|
+
if (isObject(newVal) && isObject(oldVal)) {
|
|
1921
|
+
target[key] = merge2(newVal, oldVal);
|
|
1922
|
+
} else if (Array.isArray(newVal)) {
|
|
1923
|
+
target[key] = union([], newVal, oldVal);
|
|
1924
|
+
} else {
|
|
1925
|
+
target[key] = clone(oldVal);
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
return target;
|
|
1929
|
+
}
|
|
1930
|
+
function hasOwn(obj, key) {
|
|
1931
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1932
|
+
}
|
|
1933
|
+
function isObject(val) {
|
|
1934
|
+
return typeOf(val) === "object" || typeOf(val) === "function";
|
|
1935
|
+
}
|
|
1936
|
+
function isValidKey(key) {
|
|
1937
|
+
return key !== "__proto__" && key !== "constructor" && key !== "prototype";
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
|
|
1942
|
+
// node_modules/puppeteer-extra-plugin/dist/index.esm.js
|
|
1943
|
+
var index_esm_exports2 = {};
|
|
1944
|
+
__export(index_esm_exports2, {
|
|
1945
|
+
PuppeteerExtraPlugin: () => PuppeteerExtraPlugin
|
|
1946
|
+
});
|
|
1947
|
+
var import_debug2, merge, PuppeteerExtraPlugin;
|
|
1948
|
+
var init_index_esm2 = __esm({
|
|
1949
|
+
"node_modules/puppeteer-extra-plugin/dist/index.esm.js"() {
|
|
1950
|
+
"use strict";
|
|
1951
|
+
import_debug2 = __toESM(require_src());
|
|
1952
|
+
merge = require_merge_deep();
|
|
1953
|
+
PuppeteerExtraPlugin = class {
|
|
1954
|
+
constructor(opts) {
|
|
1955
|
+
this._debugBase = (0, import_debug2.default)(`puppeteer-extra-plugin:base:${this.name}`);
|
|
1956
|
+
this._childClassMembers = [];
|
|
1957
|
+
this._opts = merge(this.defaults, opts || {});
|
|
1958
|
+
this._debugBase("Initialized.");
|
|
1959
|
+
}
|
|
1960
|
+
/**
|
|
1961
|
+
* Plugin name (required).
|
|
1962
|
+
*
|
|
1963
|
+
* Convention:
|
|
1964
|
+
* - Package: `puppeteer-extra-plugin-anonymize-ua`
|
|
1965
|
+
* - Name: `anonymize-ua`
|
|
1966
|
+
*
|
|
1967
|
+
* @example
|
|
1968
|
+
* get name () { return 'anonymize-ua' }
|
|
1969
|
+
*/
|
|
1970
|
+
get name() {
|
|
1971
|
+
throw new Error('Plugin must override "name"');
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Plugin defaults (optional).
|
|
1975
|
+
*
|
|
1976
|
+
* If defined will be ([deep-](https://github.com/jonschlinkert/merge-deep))merged with the (optional) user supplied options (supplied during plugin instantiation).
|
|
1977
|
+
*
|
|
1978
|
+
* The result of merging defaults with user supplied options can be accessed through `this.opts`.
|
|
1979
|
+
*
|
|
1980
|
+
* @see [[opts]]
|
|
1981
|
+
*
|
|
1982
|
+
* @example
|
|
1983
|
+
* get defaults () {
|
|
1984
|
+
* return {
|
|
1985
|
+
* stripHeadless: true,
|
|
1986
|
+
* makeWindows: true,
|
|
1987
|
+
* customFn: null
|
|
1988
|
+
* }
|
|
1989
|
+
* }
|
|
1990
|
+
*
|
|
1991
|
+
* // Users can overwrite plugin defaults during instantiation:
|
|
1992
|
+
* puppeteer.use(require('puppeteer-extra-plugin-foobar')({ makeWindows: false }))
|
|
1993
|
+
*/
|
|
1994
|
+
get defaults() {
|
|
1995
|
+
return {};
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* Plugin requirements (optional).
|
|
1999
|
+
*
|
|
2000
|
+
* Signal certain plugin requirements to the base class and the user.
|
|
2001
|
+
*
|
|
2002
|
+
* Currently supported:
|
|
2003
|
+
* - `launch`
|
|
2004
|
+
* - If the plugin only supports locally created browser instances (no `puppeteer.connect()`),
|
|
2005
|
+
* will output a warning to the user.
|
|
2006
|
+
* - `headful`
|
|
2007
|
+
* - If the plugin doesn't work in `headless: true` mode,
|
|
2008
|
+
* will output a warning to the user.
|
|
2009
|
+
* - `dataFromPlugins`
|
|
2010
|
+
* - In case the plugin requires data from other plugins.
|
|
2011
|
+
* will enable usage of `this.getDataFromPlugins()`.
|
|
2012
|
+
* - `runLast`
|
|
2013
|
+
* - In case the plugin prefers to run after the others.
|
|
2014
|
+
* Useful when the plugin needs data from others.
|
|
2015
|
+
*
|
|
2016
|
+
* @example
|
|
2017
|
+
* get requirements () {
|
|
2018
|
+
* return new Set(['runLast', 'dataFromPlugins'])
|
|
2019
|
+
* }
|
|
2020
|
+
*/
|
|
2021
|
+
get requirements() {
|
|
2022
|
+
return /* @__PURE__ */ new Set([]);
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* Plugin dependencies (optional).
|
|
2026
|
+
*
|
|
2027
|
+
* Missing plugins will be required() by puppeteer-extra.
|
|
2028
|
+
*
|
|
2029
|
+
* @example
|
|
2030
|
+
* get dependencies () {
|
|
2031
|
+
* return new Set(['user-preferences'])
|
|
2032
|
+
* }
|
|
2033
|
+
* // Will ensure the 'puppeteer-extra-plugin-user-preferences' plugin is loaded.
|
|
2034
|
+
*/
|
|
2035
|
+
get dependencies() {
|
|
2036
|
+
return /* @__PURE__ */ new Set([]);
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Plugin data (optional).
|
|
2040
|
+
*
|
|
2041
|
+
* Plugins can expose data (an array of objects), which in turn can be consumed by other plugins,
|
|
2042
|
+
* that list the `dataFromPlugins` requirement (by using `this.getDataFromPlugins()`).
|
|
2043
|
+
*
|
|
2044
|
+
* Convention: `[ {name: 'Any name', value: 'Any value'} ]`
|
|
2045
|
+
*
|
|
2046
|
+
* @see [[getDataFromPlugins]]
|
|
2047
|
+
*
|
|
2048
|
+
* @example
|
|
2049
|
+
* // plugin1.js
|
|
2050
|
+
* get data () {
|
|
2051
|
+
* return [
|
|
2052
|
+
* {
|
|
2053
|
+
* name: 'userPreferences',
|
|
2054
|
+
* value: { foo: 'bar' }
|
|
2055
|
+
* },
|
|
2056
|
+
* {
|
|
2057
|
+
* name: 'userPreferences',
|
|
2058
|
+
* value: { hello: 'world' }
|
|
2059
|
+
* }
|
|
2060
|
+
* ]
|
|
2061
|
+
*
|
|
2062
|
+
* // plugin2.js
|
|
2063
|
+
* get requirements () { return new Set(['dataFromPlugins']) }
|
|
2064
|
+
*
|
|
2065
|
+
* async beforeLaunch () {
|
|
2066
|
+
* const prefs = this.getDataFromPlugins('userPreferences').map(d => d.value)
|
|
2067
|
+
* this.debug(prefs) // => [ { foo: 'bar' }, { hello: 'world' } ]
|
|
2068
|
+
* }
|
|
2069
|
+
*/
|
|
2070
|
+
get data() {
|
|
2071
|
+
return [];
|
|
2072
|
+
}
|
|
2073
|
+
/**
|
|
2074
|
+
* Access the plugin options (usually the `defaults` merged with user defined options)
|
|
2075
|
+
*
|
|
2076
|
+
* To skip the auto-merging of defaults with user supplied opts don't define a `defaults`
|
|
2077
|
+
* property and set the `this._opts` Object in your plugin constructor directly.
|
|
2078
|
+
*
|
|
2079
|
+
* @see [[defaults]]
|
|
2080
|
+
*
|
|
2081
|
+
* @example
|
|
2082
|
+
* get defaults () { return { foo: "bar" } }
|
|
2083
|
+
*
|
|
2084
|
+
* async onPageCreated (page) {
|
|
2085
|
+
* this.debug(this.opts.foo) // => bar
|
|
2086
|
+
* }
|
|
2087
|
+
*/
|
|
2088
|
+
get opts() {
|
|
2089
|
+
return this._opts;
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Convenience debug logger based on the [debug] module.
|
|
2093
|
+
* Will automatically namespace the logging output to the plugin package name.
|
|
2094
|
+
* [debug]: https://www.npmjs.com/package/debug
|
|
2095
|
+
*
|
|
2096
|
+
* ```bash
|
|
2097
|
+
* # toggle output using environment variables
|
|
2098
|
+
* DEBUG=puppeteer-extra-plugin:<plugin_name> node foo.js
|
|
2099
|
+
* # to debug all the things:
|
|
2100
|
+
* DEBUG=puppeteer-extra,puppeteer-extra-plugin:* node foo.js
|
|
2101
|
+
* ```
|
|
2102
|
+
*
|
|
2103
|
+
* @example
|
|
2104
|
+
* this.debug('hello world')
|
|
2105
|
+
* // will output e.g. 'puppeteer-extra-plugin:anonymize-ua hello world'
|
|
2106
|
+
*/
|
|
2107
|
+
get debug() {
|
|
2108
|
+
return (0, import_debug2.default)(`puppeteer-extra-plugin:${this.name}`);
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* Before a new browser instance is created/launched.
|
|
2112
|
+
*
|
|
2113
|
+
* Can be used to modify the puppeteer launch options by modifying or returning them.
|
|
2114
|
+
*
|
|
2115
|
+
* Plugins using this method will be called in sequence to each
|
|
2116
|
+
* be able to update the launch options.
|
|
2117
|
+
*
|
|
2118
|
+
* @example
|
|
2119
|
+
* async beforeLaunch (options) {
|
|
2120
|
+
* if (this.opts.flashPluginPath) {
|
|
2121
|
+
* options.args.push(`--ppapi-flash-path=${this.opts.flashPluginPath}`)
|
|
2122
|
+
* }
|
|
2123
|
+
* }
|
|
2124
|
+
*
|
|
2125
|
+
* @param options - Puppeteer launch options
|
|
2126
|
+
*/
|
|
2127
|
+
async beforeLaunch(options) {
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* After the browser has launched.
|
|
2131
|
+
*
|
|
2132
|
+
* Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
2133
|
+
* It's possible that `pupeeteer.launch` will be called multiple times and more than one browser created.
|
|
2134
|
+
* In order to make the plugins as stateless as possible don't store a reference to the browser instance
|
|
2135
|
+
* in the plugin but rather consider alternatives.
|
|
2136
|
+
*
|
|
2137
|
+
* E.g. when using `onPageCreated` you can get a browser reference by using `page.browser()`.
|
|
2138
|
+
*
|
|
2139
|
+
* Alternatively you could expose a class method that takes a browser instance as a parameter to work with:
|
|
2140
|
+
*
|
|
2141
|
+
* ```es6
|
|
2142
|
+
* const fancyPlugin = require('puppeteer-extra-plugin-fancy')()
|
|
2143
|
+
* puppeteer.use(fancyPlugin)
|
|
2144
|
+
* const browser = await puppeteer.launch()
|
|
2145
|
+
* await fancyPlugin.killBrowser(browser)
|
|
2146
|
+
* ```
|
|
2147
|
+
*
|
|
2148
|
+
* @param browser - The `puppeteer` browser instance.
|
|
2149
|
+
* @param opts.options - Puppeteer launch options used.
|
|
2150
|
+
*
|
|
2151
|
+
* @example
|
|
2152
|
+
* async afterLaunch (browser, opts) {
|
|
2153
|
+
* this.debug('browser has been launched', opts.options)
|
|
2154
|
+
* }
|
|
2155
|
+
*/
|
|
2156
|
+
async afterLaunch(browser, opts = { options: {} }) {
|
|
2157
|
+
}
|
|
2158
|
+
/**
|
|
2159
|
+
* Before connecting to an existing browser instance.
|
|
2160
|
+
*
|
|
2161
|
+
* Can be used to modify the puppeteer connect options by modifying or returning them.
|
|
2162
|
+
*
|
|
2163
|
+
* Plugins using this method will be called in sequence to each
|
|
2164
|
+
* be able to update the launch options.
|
|
2165
|
+
*
|
|
2166
|
+
* @param {Object} options - Puppeteer connect options
|
|
2167
|
+
* @return {Object=}
|
|
2168
|
+
*/
|
|
2169
|
+
async beforeConnect(options) {
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* After connecting to an existing browser instance.
|
|
2173
|
+
*
|
|
2174
|
+
* > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
2175
|
+
*
|
|
2176
|
+
* @param browser - The `puppeteer` browser instance.
|
|
2177
|
+
* @param {Object} opts
|
|
2178
|
+
* @param {Object} opts.options - Puppeteer connect options used.
|
|
2179
|
+
*
|
|
2180
|
+
*/
|
|
2181
|
+
async afterConnect(browser, opts = {}) {
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Called when a browser instance is available.
|
|
2185
|
+
*
|
|
2186
|
+
* This applies to both `puppeteer.launch()` and `puppeteer.connect()`.
|
|
2187
|
+
*
|
|
2188
|
+
* Convenience method created for plugins that need access to a browser instance
|
|
2189
|
+
* and don't mind if it has been created through `launch` or `connect`.
|
|
2190
|
+
*
|
|
2191
|
+
* > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
2192
|
+
*
|
|
2193
|
+
* @param browser - The `puppeteer` browser instance.
|
|
2194
|
+
*/
|
|
2195
|
+
async onBrowser(browser, opts) {
|
|
2196
|
+
}
|
|
2197
|
+
/**
|
|
2198
|
+
* Called when a target is created, for example when a new page is opened by window.open or browser.newPage.
|
|
2199
|
+
*
|
|
2200
|
+
* > Note: This includes target creations in incognito browser contexts.
|
|
2201
|
+
*
|
|
2202
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2203
|
+
*
|
|
2204
|
+
* @param {Puppeteer.Target} target
|
|
2205
|
+
*/
|
|
2206
|
+
async onTargetCreated(target) {
|
|
2207
|
+
}
|
|
2208
|
+
/**
|
|
2209
|
+
* Same as `onTargetCreated` but prefiltered to only contain Pages, for convenience.
|
|
2210
|
+
*
|
|
2211
|
+
* > Note: This includes page creations in incognito browser contexts.
|
|
2212
|
+
*
|
|
2213
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2214
|
+
*
|
|
2215
|
+
* @param {Puppeteer.Target} target
|
|
2216
|
+
*
|
|
2217
|
+
* @example
|
|
2218
|
+
* async onPageCreated (page) {
|
|
2219
|
+
* let ua = await page.browser().userAgent()
|
|
2220
|
+
* if (this.opts.stripHeadless) {
|
|
2221
|
+
* ua = ua.replace('HeadlessChrome/', 'Chrome/')
|
|
2222
|
+
* }
|
|
2223
|
+
* this.debug('new ua', ua)
|
|
2224
|
+
* await page.setUserAgent(ua)
|
|
2225
|
+
* }
|
|
2226
|
+
*/
|
|
2227
|
+
async onPageCreated(page) {
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Called when the url of a target changes.
|
|
2231
|
+
*
|
|
2232
|
+
* > Note: This includes target changes in incognito browser contexts.
|
|
2233
|
+
*
|
|
2234
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2235
|
+
*
|
|
2236
|
+
* @param {Puppeteer.Target} target
|
|
2237
|
+
*/
|
|
2238
|
+
async onTargetChanged(target) {
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* Called when a target is destroyed, for example when a page is closed.
|
|
2242
|
+
*
|
|
2243
|
+
* > Note: This includes target destructions in incognito browser contexts.
|
|
2244
|
+
*
|
|
2245
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2246
|
+
*
|
|
2247
|
+
* @param {Puppeteer.Target} target
|
|
2248
|
+
*/
|
|
2249
|
+
async onTargetDestroyed(target) {
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Called when Puppeteer gets disconnected from the Chromium instance.
|
|
2253
|
+
*
|
|
2254
|
+
* This might happen because of one of the following:
|
|
2255
|
+
* - Chromium is closed or crashed
|
|
2256
|
+
* - The `browser.disconnect` method was called
|
|
2257
|
+
*/
|
|
2258
|
+
async onDisconnected() {
|
|
2259
|
+
}
|
|
2260
|
+
/**
|
|
2261
|
+
* **Deprecated:** Since puppeteer v1.6.0 `onDisconnected` has been improved
|
|
2262
|
+
* and should be used instead of `onClose`.
|
|
2263
|
+
*
|
|
2264
|
+
* In puppeteer < v1.6.0 `onDisconnected` was not catching all exit scenarios.
|
|
2265
|
+
* In order for plugins to clean up properly (e.g. deleting temporary files)
|
|
2266
|
+
* the `onClose` method had been introduced.
|
|
2267
|
+
*
|
|
2268
|
+
* > Note: Might be called multiple times on exit.
|
|
2269
|
+
*
|
|
2270
|
+
* > Note: This only includes browser instances created through `.launch()`.
|
|
2271
|
+
*/
|
|
2272
|
+
async onClose() {
|
|
2273
|
+
}
|
|
2274
|
+
/**
|
|
2275
|
+
* After the plugin has been registered in `puppeteer-extra`.
|
|
2276
|
+
*
|
|
2277
|
+
* Normally right after `puppeteer.use(plugin)` is called
|
|
2278
|
+
*/
|
|
2279
|
+
async onPluginRegistered() {
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Helper method to retrieve `data` objects from other plugins.
|
|
2283
|
+
*
|
|
2284
|
+
* A plugin needs to state the `dataFromPlugins` requirement
|
|
2285
|
+
* in order to use this method. Will be mapped to `puppeteer.getPluginData`.
|
|
2286
|
+
*
|
|
2287
|
+
* @param name - Filter data by `name` property
|
|
2288
|
+
*
|
|
2289
|
+
* @see [data]
|
|
2290
|
+
* @see [requirements]
|
|
2291
|
+
*/
|
|
2292
|
+
getDataFromPlugins(name) {
|
|
2293
|
+
return [];
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* Will match plugin dependencies against all currently registered plugins.
|
|
2297
|
+
* Is being called by `puppeteer-extra` and used to require missing dependencies.
|
|
2298
|
+
*
|
|
2299
|
+
* @param {Array<Object>} plugins
|
|
2300
|
+
* @return {Set} - list of missing plugin names
|
|
2301
|
+
*
|
|
2302
|
+
* @private
|
|
2303
|
+
*/
|
|
2304
|
+
_getMissingDependencies(plugins) {
|
|
2305
|
+
const pluginNames = new Set(plugins.map((p) => p.name));
|
|
2306
|
+
const missing = new Set(Array.from(this.dependencies.values()).filter((x) => !pluginNames.has(x)));
|
|
2307
|
+
return missing;
|
|
2308
|
+
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Conditionally bind browser/process events to class members.
|
|
2311
|
+
* The idea is to reduce event binding boilerplate in plugins.
|
|
2312
|
+
*
|
|
2313
|
+
* For efficiency we make sure the plugin is using the respective event
|
|
2314
|
+
* by checking the child class members before registering the listener.
|
|
2315
|
+
*
|
|
2316
|
+
* @param {<Puppeteer.Browser>} browser
|
|
2317
|
+
* @param {Object} opts - Options
|
|
2318
|
+
* @param {string} opts.context - Puppeteer context (launch/connect)
|
|
2319
|
+
* @param {Object} [opts.options] - Puppeteer launch or connect options
|
|
2320
|
+
* @param {Array<string>} [opts.defaultArgs] - The default flags that Chromium will be launched with
|
|
2321
|
+
*
|
|
2322
|
+
* @private
|
|
2323
|
+
*/
|
|
2324
|
+
async _bindBrowserEvents(browser, opts = {}) {
|
|
2325
|
+
if (this._hasChildClassMember("onTargetCreated") || this._hasChildClassMember("onPageCreated")) {
|
|
2326
|
+
browser.on("targetcreated", this._onTargetCreated.bind(this));
|
|
2327
|
+
}
|
|
2328
|
+
if (this._hasChildClassMember("onTargetChanged") && this.onTargetChanged) {
|
|
2329
|
+
browser.on("targetchanged", this.onTargetChanged.bind(this));
|
|
2330
|
+
}
|
|
2331
|
+
if (this._hasChildClassMember("onTargetDestroyed") && this.onTargetDestroyed) {
|
|
2332
|
+
browser.on("targetdestroyed", this.onTargetDestroyed.bind(this));
|
|
2333
|
+
}
|
|
2334
|
+
if (this._hasChildClassMember("onDisconnected") && this.onDisconnected) {
|
|
2335
|
+
browser.on("disconnected", this.onDisconnected.bind(this));
|
|
2336
|
+
}
|
|
2337
|
+
if (opts.context === "launch" && this._hasChildClassMember("onClose")) {
|
|
2338
|
+
if (this.onClose) {
|
|
2339
|
+
process.on("exit", this.onClose.bind(this));
|
|
2340
|
+
browser.on("disconnected", this.onClose.bind(this));
|
|
2341
|
+
if (opts.options.handleSIGINT !== false) {
|
|
2342
|
+
process.on("SIGINT", this.onClose.bind(this));
|
|
2343
|
+
}
|
|
2344
|
+
if (opts.options.handleSIGTERM !== false) {
|
|
2345
|
+
process.on("SIGTERM", this.onClose.bind(this));
|
|
2346
|
+
}
|
|
2347
|
+
if (opts.options.handleSIGHUP !== false) {
|
|
2348
|
+
process.on("SIGHUP", this.onClose.bind(this));
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
if (opts.context === "launch" && this.afterLaunch) {
|
|
2353
|
+
await this.afterLaunch(browser, opts);
|
|
2354
|
+
}
|
|
2355
|
+
if (opts.context === "connect" && this.afterConnect) {
|
|
2356
|
+
await this.afterConnect(browser, opts);
|
|
2357
|
+
}
|
|
2358
|
+
if (this.onBrowser)
|
|
2359
|
+
await this.onBrowser(browser, opts);
|
|
2360
|
+
}
|
|
2361
|
+
/**
|
|
2362
|
+
* @private
|
|
2363
|
+
*/
|
|
2364
|
+
async _onTargetCreated(target) {
|
|
2365
|
+
if (this.onTargetCreated)
|
|
2366
|
+
await this.onTargetCreated(target);
|
|
2367
|
+
if (target.type() === "page") {
|
|
2368
|
+
try {
|
|
2369
|
+
const page = await target.page();
|
|
2370
|
+
if (!page) {
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
const validPage = "isClosed" in page && !page.isClosed();
|
|
2374
|
+
if (this.onPageCreated && validPage) {
|
|
2375
|
+
await this.onPageCreated(page);
|
|
2376
|
+
}
|
|
2377
|
+
} catch (err) {
|
|
2378
|
+
console.error(err);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* @private
|
|
2384
|
+
*/
|
|
2385
|
+
_register(prototype) {
|
|
2386
|
+
this._registerChildClassMembers(prototype);
|
|
2387
|
+
if (this.onPluginRegistered)
|
|
2388
|
+
this.onPluginRegistered();
|
|
2389
|
+
}
|
|
2390
|
+
/**
|
|
2391
|
+
* @private
|
|
2392
|
+
*/
|
|
2393
|
+
_registerChildClassMembers(prototype) {
|
|
2394
|
+
this._childClassMembers = Object.getOwnPropertyNames(prototype);
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* @private
|
|
2398
|
+
*/
|
|
2399
|
+
_hasChildClassMember(name) {
|
|
2400
|
+
return !!this._childClassMembers.includes(name);
|
|
2401
|
+
}
|
|
2402
|
+
/**
|
|
2403
|
+
* @private
|
|
2404
|
+
*/
|
|
2405
|
+
get _isPuppeteerExtraPlugin() {
|
|
2406
|
+
return true;
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
});
|
|
2411
|
+
|
|
2412
|
+
// node_modules/puppeteer-extra-plugin-stealth/index.js
|
|
2413
|
+
var require_puppeteer_extra_plugin_stealth = __commonJS({
|
|
2414
|
+
"node_modules/puppeteer-extra-plugin-stealth/index.js"(exports, module) {
|
|
2415
|
+
"use strict";
|
|
2416
|
+
var { PuppeteerExtraPlugin: PuppeteerExtraPlugin2 } = (init_index_esm2(), __toCommonJS(index_esm_exports2));
|
|
2417
|
+
var StealthPlugin = class extends PuppeteerExtraPlugin2 {
|
|
2418
|
+
constructor(opts = {}) {
|
|
2419
|
+
super(opts);
|
|
2420
|
+
}
|
|
2421
|
+
get name() {
|
|
2422
|
+
return "stealth";
|
|
2423
|
+
}
|
|
2424
|
+
get defaults() {
|
|
2425
|
+
const availableEvasions = /* @__PURE__ */ new Set([
|
|
2426
|
+
"chrome.app",
|
|
2427
|
+
"chrome.csi",
|
|
2428
|
+
"chrome.loadTimes",
|
|
2429
|
+
"chrome.runtime",
|
|
2430
|
+
"defaultArgs",
|
|
2431
|
+
"iframe.contentWindow",
|
|
2432
|
+
"media.codecs",
|
|
2433
|
+
"navigator.hardwareConcurrency",
|
|
2434
|
+
"navigator.languages",
|
|
2435
|
+
"navigator.permissions",
|
|
2436
|
+
"navigator.plugins",
|
|
2437
|
+
"navigator.webdriver",
|
|
2438
|
+
"sourceurl",
|
|
2439
|
+
"user-agent-override",
|
|
2440
|
+
"webgl.vendor",
|
|
2441
|
+
"window.outerdimensions"
|
|
2442
|
+
]);
|
|
2443
|
+
return {
|
|
2444
|
+
availableEvasions,
|
|
2445
|
+
// Enable all available evasions by default
|
|
2446
|
+
enabledEvasions: /* @__PURE__ */ new Set([...availableEvasions])
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Requires evasion techniques dynamically based on configuration.
|
|
2451
|
+
*
|
|
2452
|
+
* @private
|
|
2453
|
+
*/
|
|
2454
|
+
get dependencies() {
|
|
2455
|
+
return new Set(
|
|
2456
|
+
[...this.opts.enabledEvasions].map((e) => `${this.name}/evasions/${e}`)
|
|
2457
|
+
);
|
|
2458
|
+
}
|
|
2459
|
+
/**
|
|
2460
|
+
* Get all available evasions.
|
|
2461
|
+
*
|
|
2462
|
+
* Please look into the [evasions directory](./evasions/) for an up to date list.
|
|
2463
|
+
*
|
|
2464
|
+
* @type {Set<string>} - A Set of all available evasions.
|
|
2465
|
+
*
|
|
2466
|
+
* @example
|
|
2467
|
+
* const pluginStealth = require('puppeteer-extra-plugin-stealth')()
|
|
2468
|
+
* console.log(pluginStealth.availableEvasions) // => Set { 'user-agent', 'console.debug' }
|
|
2469
|
+
* puppeteer.use(pluginStealth)
|
|
2470
|
+
*/
|
|
2471
|
+
get availableEvasions() {
|
|
2472
|
+
return this.defaults.availableEvasions;
|
|
2473
|
+
}
|
|
2474
|
+
/**
|
|
2475
|
+
* Get all enabled evasions.
|
|
2476
|
+
*
|
|
2477
|
+
* Enabled evasions can be configured either through `opts` or by modifying this property.
|
|
2478
|
+
*
|
|
2479
|
+
* @type {Set<string>} - A Set of all enabled evasions.
|
|
2480
|
+
*
|
|
2481
|
+
* @example
|
|
2482
|
+
* // Remove specific evasion from enabled ones dynamically
|
|
2483
|
+
* const pluginStealth = require('puppeteer-extra-plugin-stealth')()
|
|
2484
|
+
* pluginStealth.enabledEvasions.delete('console.debug')
|
|
2485
|
+
* puppeteer.use(pluginStealth)
|
|
2486
|
+
*/
|
|
2487
|
+
get enabledEvasions() {
|
|
2488
|
+
return this.opts.enabledEvasions;
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* @private
|
|
2492
|
+
*/
|
|
2493
|
+
set enabledEvasions(evasions) {
|
|
2494
|
+
this.opts.enabledEvasions = evasions;
|
|
2495
|
+
}
|
|
2496
|
+
async onBrowser(browser) {
|
|
2497
|
+
if (browser && browser.setMaxListeners) {
|
|
2498
|
+
browser.setMaxListeners(30);
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
};
|
|
2502
|
+
var defaultExport = (opts) => new StealthPlugin(opts);
|
|
2503
|
+
module.exports = defaultExport;
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2
2506
|
|
|
3
2507
|
// src/index.ts
|
|
4
2508
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -21,7 +2525,11 @@ var DEFAULT_BROWSER_CONFIG = {
|
|
|
21
2525
|
renderTimeout: 1e4,
|
|
22
2526
|
downloadsPath: join(homedir(), ".vsl", "downloads"),
|
|
23
2527
|
downloadTimeout: 6e4,
|
|
24
|
-
acceptDownloads: true
|
|
2528
|
+
acceptDownloads: true,
|
|
2529
|
+
userDataDir: void 0,
|
|
2530
|
+
// Дефолт ~/.vsl/browser-profile применяется в manager.ts
|
|
2531
|
+
cdpPort: 9222
|
|
2532
|
+
// Дефолтный CDP port для подключения множественных агентов
|
|
25
2533
|
};
|
|
26
2534
|
function loadConfig() {
|
|
27
2535
|
const fileConfig = loadConfigFile();
|
|
@@ -39,7 +2547,9 @@ function loadConfig() {
|
|
|
39
2547
|
renderTimeout: process.env.VSL_RENDER_TIMEOUT ? parseInt(process.env.VSL_RENDER_TIMEOUT, 10) : fileConfig.browser?.renderTimeout ?? DEFAULT_BROWSER_CONFIG.renderTimeout,
|
|
40
2548
|
downloadsPath: process.env.VSL_DOWNLOADS_PATH || fileConfig.browser?.downloadsPath || DEFAULT_BROWSER_CONFIG.downloadsPath,
|
|
41
2549
|
downloadTimeout: process.env.VSL_DOWNLOAD_TIMEOUT ? parseInt(process.env.VSL_DOWNLOAD_TIMEOUT, 10) : fileConfig.browser?.downloadTimeout ?? DEFAULT_BROWSER_CONFIG.downloadTimeout,
|
|
42
|
-
acceptDownloads: process.env.VSL_ACCEPT_DOWNLOADS ? process.env.VSL_ACCEPT_DOWNLOADS === "true" : fileConfig.browser?.acceptDownloads ?? DEFAULT_BROWSER_CONFIG.acceptDownloads
|
|
2550
|
+
acceptDownloads: process.env.VSL_ACCEPT_DOWNLOADS ? process.env.VSL_ACCEPT_DOWNLOADS === "true" : fileConfig.browser?.acceptDownloads ?? DEFAULT_BROWSER_CONFIG.acceptDownloads,
|
|
2551
|
+
userDataDir: process.env.VSL_USER_DATA_DIR || fileConfig.browser?.userDataDir || DEFAULT_BROWSER_CONFIG.userDataDir,
|
|
2552
|
+
cdpPort: process.env.VSL_CDP_PORT ? parseInt(process.env.VSL_CDP_PORT, 10) : fileConfig.browser?.cdpPort ?? DEFAULT_BROWSER_CONFIG.cdpPort
|
|
43
2553
|
};
|
|
44
2554
|
return {
|
|
45
2555
|
vision: {
|
|
@@ -152,22 +2662,22 @@ function buildInjectionScript() {
|
|
|
152
2662
|
}
|
|
153
2663
|
};
|
|
154
2664
|
}
|
|
155
|
-
async function injectVslIdsIntoDom(browser, objects, semanticMap = /* @__PURE__ */ new Map()) {
|
|
156
|
-
const page = await browser.getPage();
|
|
2665
|
+
async function injectVslIdsIntoDom(browser, objects, semanticMap = /* @__PURE__ */ new Map(), sessionId) {
|
|
2666
|
+
const page = await browser.getPage(sessionId);
|
|
157
2667
|
await page.waitForTimeout(50);
|
|
158
2668
|
const semanticMapObj = {};
|
|
159
2669
|
for (const [key, value] of semanticMap) {
|
|
160
2670
|
semanticMapObj[key] = value;
|
|
161
2671
|
}
|
|
162
|
-
await browser.evaluate(buildInjectionScript(), objects, semanticMapObj);
|
|
2672
|
+
await browser.evaluate(buildInjectionScript(), sessionId, objects, semanticMapObj);
|
|
163
2673
|
}
|
|
164
|
-
async function injectVslIdsIntoFrame(browser, frame, objects, semanticMap = /* @__PURE__ */ new Map()) {
|
|
2674
|
+
async function injectVslIdsIntoFrame(browser, frame, objects, semanticMap = /* @__PURE__ */ new Map(), sessionId) {
|
|
165
2675
|
try {
|
|
166
2676
|
const semanticMapObj = {};
|
|
167
2677
|
for (const [key, value] of semanticMap) {
|
|
168
2678
|
semanticMapObj[key] = value;
|
|
169
2679
|
}
|
|
170
|
-
await browser.evaluateInFrame(frame, buildInjectionScript(), objects, semanticMapObj);
|
|
2680
|
+
await browser.evaluateInFrame(frame, buildInjectionScript(), sessionId, objects, semanticMapObj);
|
|
171
2681
|
} catch (error) {
|
|
172
2682
|
console.warn("[VSL] Failed to inject data-vsl-id into iframe:", error);
|
|
173
2683
|
}
|
|
@@ -753,17 +3263,51 @@ async function extractDomTreeFromFrame(browser, frame) {
|
|
|
753
3263
|
}
|
|
754
3264
|
return extraction;
|
|
755
3265
|
}
|
|
756
|
-
async function extractDomTree(browser) {
|
|
3266
|
+
async function extractDomTree(browser, sessionId) {
|
|
757
3267
|
const extractionResult = await browser.evaluate(
|
|
758
|
-
extractDomTreeInBrowser
|
|
3268
|
+
extractDomTreeInBrowser,
|
|
3269
|
+
sessionId
|
|
759
3270
|
);
|
|
760
3271
|
const extraction = Array.isArray(extractionResult) ? extractionResult[0] : void 0;
|
|
761
3272
|
if (!extraction || !Array.isArray(extraction.elements)) {
|
|
762
3273
|
throw new Error("Failed to extract DOM tree: empty result");
|
|
763
3274
|
}
|
|
3275
|
+
const invalidCount = countMalformedElements(extraction.elements);
|
|
3276
|
+
if (invalidCount > 0) {
|
|
3277
|
+
console.warn(`[VSL] Filtering ${invalidCount} malformed elements (missing attributes) from DOM extraction`);
|
|
3278
|
+
extraction.elements = filterMalformedElements(extraction.elements);
|
|
3279
|
+
}
|
|
764
3280
|
return extraction;
|
|
765
3281
|
}
|
|
766
|
-
|
|
3282
|
+
function countMalformedElements(elements) {
|
|
3283
|
+
let count = 0;
|
|
3284
|
+
for (const el of elements) {
|
|
3285
|
+
if (!el || typeof el !== "object" || !("attributes" in el)) {
|
|
3286
|
+
count++;
|
|
3287
|
+
}
|
|
3288
|
+
const children = el?.children;
|
|
3289
|
+
if (Array.isArray(children)) {
|
|
3290
|
+
count += countMalformedElements(children);
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
return count;
|
|
3294
|
+
}
|
|
3295
|
+
function filterMalformedElements(elements) {
|
|
3296
|
+
const result = [];
|
|
3297
|
+
for (const el of elements) {
|
|
3298
|
+
if (!el || typeof el !== "object" || !("attributes" in el)) {
|
|
3299
|
+
continue;
|
|
3300
|
+
}
|
|
3301
|
+
const clean = { ...el };
|
|
3302
|
+
const children = clean.children;
|
|
3303
|
+
if (Array.isArray(children)) {
|
|
3304
|
+
clean.children = filterMalformedElements(children);
|
|
3305
|
+
}
|
|
3306
|
+
result.push(clean);
|
|
3307
|
+
}
|
|
3308
|
+
return result;
|
|
3309
|
+
}
|
|
3310
|
+
async function handleGetSnapshot(args, browser, session, _config, sessionId) {
|
|
767
3311
|
const startTime = Date.now();
|
|
768
3312
|
const detailLevel = args.detail_level || "medium";
|
|
769
3313
|
const ttl = args.ttl ?? DEFAULT_SNAPSHOT_TTL_MS;
|
|
@@ -816,7 +3360,7 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
816
3360
|
}
|
|
817
3361
|
}
|
|
818
3362
|
if (args.url) {
|
|
819
|
-
await browser.navigate(args.url);
|
|
3363
|
+
await browser.navigate(args.url, sessionId);
|
|
820
3364
|
}
|
|
821
3365
|
const isAvailable = await browser.isAvailable();
|
|
822
3366
|
if (!isAvailable) {
|
|
@@ -825,13 +3369,13 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
825
3369
|
error: "Playwright is not installed. Install it with: npm install playwright"
|
|
826
3370
|
};
|
|
827
3371
|
}
|
|
828
|
-
const extraction = await extractDomTree(browser);
|
|
3372
|
+
const extraction = await extractDomTree(browser, sessionId);
|
|
829
3373
|
const extractedElements = extraction.elements;
|
|
830
3374
|
const viewport = extraction.viewport;
|
|
831
|
-
const url = args.url || await browser.evaluate(() => window.location.href);
|
|
832
|
-
const title = await browser.evaluate(() => document.title);
|
|
3375
|
+
const url = args.url || await browser.evaluate(() => window.location.href, sessionId);
|
|
3376
|
+
const title = await browser.evaluate(() => document.title, sessionId);
|
|
833
3377
|
const semanticMap = buildSemanticMap(extractedElements);
|
|
834
|
-
const iframeElementsRaw = await browser.evaluate(extractIframesInBrowser);
|
|
3378
|
+
const iframeElementsRaw = await browser.evaluate(extractIframesInBrowser, sessionId);
|
|
835
3379
|
const iframeElements = Array.isArray(iframeElementsRaw) ? iframeElementsRaw : [];
|
|
836
3380
|
if (iframeElements.length > 0) {
|
|
837
3381
|
console.error(`[VSL] Found ${iframeElements.length} iframe elements:`);
|
|
@@ -843,7 +3387,7 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
843
3387
|
for (const iframeInfo of iframeElements) {
|
|
844
3388
|
if (!iframeInfo.url) continue;
|
|
845
3389
|
try {
|
|
846
|
-
const allFrames = await browser.getFrames();
|
|
3390
|
+
const allFrames = await browser.getFrames(sessionId);
|
|
847
3391
|
const frame = allFrames.find((f) => {
|
|
848
3392
|
const frameUrl = f.url();
|
|
849
3393
|
return frameUrl === iframeInfo.url || frameUrl.includes(iframeInfo.url) || iframeInfo.url.includes(frameUrl);
|
|
@@ -973,7 +3517,7 @@ function computeToolMetrics(result, startTime) {
|
|
|
973
3517
|
}
|
|
974
3518
|
|
|
975
3519
|
// src/tools/navigate.ts
|
|
976
|
-
async function handleNavigate(args, browser, session) {
|
|
3520
|
+
async function handleNavigate(args, browser, session, sessionId) {
|
|
977
3521
|
const startTime = Date.now();
|
|
978
3522
|
try {
|
|
979
3523
|
if (!args.url || typeof args.url !== "string") {
|
|
@@ -997,13 +3541,13 @@ async function handleNavigate(args, browser, session) {
|
|
|
997
3541
|
error: "Playwright is not installed. Install it with: npm install playwright"
|
|
998
3542
|
};
|
|
999
3543
|
}
|
|
1000
|
-
await browser.navigate(args.url);
|
|
1001
|
-
const title = await browser.evaluate(() => document.title);
|
|
3544
|
+
await browser.navigate(args.url, sessionId);
|
|
3545
|
+
const title = await browser.evaluate(() => document.title, sessionId);
|
|
1002
3546
|
let snapshot;
|
|
1003
3547
|
let snapshotWarning;
|
|
1004
3548
|
let scrollableMeta;
|
|
1005
3549
|
try {
|
|
1006
|
-
const extraction = await extractDomTree(browser);
|
|
3550
|
+
const extraction = await extractDomTree(browser, sessionId);
|
|
1007
3551
|
const input = {
|
|
1008
3552
|
viewport: extraction.viewport,
|
|
1009
3553
|
url: args.url,
|
|
@@ -1013,7 +3557,7 @@ async function handleNavigate(args, browser, session) {
|
|
|
1013
3557
|
};
|
|
1014
3558
|
session.snapshotFromElements(extraction.elements, input);
|
|
1015
3559
|
const currentDoc = session.getSnapshot();
|
|
1016
|
-
await injectVslIdsIntoDom(browser, currentDoc.objects);
|
|
3560
|
+
await injectVslIdsIntoDom(browser, currentDoc.objects, /* @__PURE__ */ new Map(), sessionId);
|
|
1017
3561
|
const scrollContext = session.getScrollContext();
|
|
1018
3562
|
const win = computeVisibleWindow(currentDoc.canvas.viewport, scrollContext);
|
|
1019
3563
|
scrollableMeta = computeScrollable(currentDoc.canvas.viewport, scrollContext);
|
|
@@ -1074,6 +3618,7 @@ var VALID_ACTIONS = [
|
|
|
1074
3618
|
"type",
|
|
1075
3619
|
"fill",
|
|
1076
3620
|
// alias for type — convenience for LLM agents
|
|
3621
|
+
"clear",
|
|
1077
3622
|
"scroll",
|
|
1078
3623
|
"select",
|
|
1079
3624
|
"hover",
|
|
@@ -1083,11 +3628,23 @@ var VALID_ACTIONS = [
|
|
|
1083
3628
|
"uncheck",
|
|
1084
3629
|
"press",
|
|
1085
3630
|
"download",
|
|
1086
|
-
"upload"
|
|
3631
|
+
"upload",
|
|
3632
|
+
"drag",
|
|
3633
|
+
"drop",
|
|
3634
|
+
"submit",
|
|
3635
|
+
"reset",
|
|
3636
|
+
"open",
|
|
3637
|
+
"close",
|
|
3638
|
+
"expand",
|
|
3639
|
+
"collapse",
|
|
3640
|
+
"wait",
|
|
3641
|
+
"go_back",
|
|
3642
|
+
"go_forward",
|
|
3643
|
+
"refresh"
|
|
1087
3644
|
];
|
|
1088
|
-
async function getStateAfterAction(session, browser, url) {
|
|
3645
|
+
async function getStateAfterAction(session, browser, url, sessionId) {
|
|
1089
3646
|
try {
|
|
1090
|
-
const extraction = await extractDomTree(browser);
|
|
3647
|
+
const extraction = await extractDomTree(browser, sessionId);
|
|
1091
3648
|
const input = {
|
|
1092
3649
|
viewport: extraction.viewport,
|
|
1093
3650
|
url,
|
|
@@ -1153,7 +3710,7 @@ function buildScrollStateFromCache(session, scrollContext) {
|
|
|
1153
3710
|
return { error: errorMessage };
|
|
1154
3711
|
}
|
|
1155
3712
|
}
|
|
1156
|
-
async function handleExecuteAction(args, browser, session) {
|
|
3713
|
+
async function handleExecuteAction(args, browser, session, sessionId) {
|
|
1157
3714
|
const startTime = Date.now();
|
|
1158
3715
|
try {
|
|
1159
3716
|
if (!args.action || typeof args.action !== "string") {
|
|
@@ -1228,16 +3785,16 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1228
3785
|
const snapshot = session.getSnapshot();
|
|
1229
3786
|
const snapshotUrl = snapshot.canvas.url;
|
|
1230
3787
|
if (snapshotUrl) {
|
|
1231
|
-
const currentUrl = await browser.evaluate(() => window.location.href);
|
|
3788
|
+
const currentUrl = await browser.evaluate(() => window.location.href, sessionId);
|
|
1232
3789
|
if (currentUrl !== snapshotUrl) {
|
|
1233
|
-
await browser.navigate(snapshotUrl);
|
|
3790
|
+
await browser.navigate(snapshotUrl, sessionId);
|
|
1234
3791
|
}
|
|
1235
3792
|
}
|
|
1236
3793
|
const hasVslIds = await browser.evaluate(() => {
|
|
1237
3794
|
return document.querySelector("[data-vsl-id]") !== null;
|
|
1238
|
-
});
|
|
3795
|
+
}, sessionId);
|
|
1239
3796
|
if (!hasVslIds) {
|
|
1240
|
-
const extraction = await extractDomTree(browser);
|
|
3797
|
+
const extraction = await extractDomTree(browser, sessionId);
|
|
1241
3798
|
const input = {
|
|
1242
3799
|
viewport: extraction.viewport,
|
|
1243
3800
|
url: snapshotUrl || "",
|
|
@@ -1261,7 +3818,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1261
3818
|
error: `Frame iframe_${frameIndex} not found in registry. Call vsl_get_snapshot first.`
|
|
1262
3819
|
};
|
|
1263
3820
|
}
|
|
1264
|
-
const frames = await browser.getFrames();
|
|
3821
|
+
const frames = await browser.getFrames(sessionId);
|
|
1265
3822
|
targetFrame = frames.find((f) => {
|
|
1266
3823
|
const u = f.url();
|
|
1267
3824
|
return u === frameUrl || u.includes(frameUrl) || frameUrl.includes(u);
|
|
@@ -1277,7 +3834,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1277
3834
|
const resolvedId = idMap.get(args.target_id) || localShortId;
|
|
1278
3835
|
const localId = resolvedId;
|
|
1279
3836
|
const selector = `[data-vsl-id="${localId}"], #${localId}, .${localId}`;
|
|
1280
|
-
const page = await browser.getPage();
|
|
3837
|
+
const page = await browser.getPage(sessionId);
|
|
1281
3838
|
const target = targetFrame || page;
|
|
1282
3839
|
switch (args.action) {
|
|
1283
3840
|
case "click": {
|
|
@@ -1347,7 +3904,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1347
3904
|
const dy = scrollDir === "up" ? -scrollAmount : scrollDir === "down" ? scrollAmount : 0;
|
|
1348
3905
|
await browser.evaluate(({ dx: dx2, dy: dy2 }) => {
|
|
1349
3906
|
window.scrollBy(dx2, dy2);
|
|
1350
|
-
}, { dx, dy });
|
|
3907
|
+
}, sessionId, { dx, dy });
|
|
1351
3908
|
await page.waitForTimeout(50);
|
|
1352
3909
|
const prevScroll = session.getScrollContext();
|
|
1353
3910
|
let newScroll = null;
|
|
@@ -1357,7 +3914,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1357
3914
|
y: window.scrollY,
|
|
1358
3915
|
width: document.documentElement.scrollWidth,
|
|
1359
3916
|
height: document.documentElement.scrollHeight
|
|
1360
|
-
}));
|
|
3917
|
+
}), sessionId);
|
|
1361
3918
|
const r = raw;
|
|
1362
3919
|
if (r !== null && typeof r === "object" && typeof r.x === "number" && typeof r.y === "number" && typeof r.width === "number" && typeof r.height === "number") {
|
|
1363
3920
|
newScroll = r;
|
|
@@ -1399,12 +3956,12 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1399
3956
|
await browser.evaluateInFrame(targetFrame, ({ sel, val }) => {
|
|
1400
3957
|
const el = document.querySelector(sel);
|
|
1401
3958
|
if (el) el.value = val;
|
|
1402
|
-
}, { sel: selector, val: args.value });
|
|
3959
|
+
}, sessionId, { sel: selector, val: args.value });
|
|
1403
3960
|
} else {
|
|
1404
3961
|
await browser.evaluate(({ sel, val }) => {
|
|
1405
3962
|
const el = document.querySelector(sel);
|
|
1406
3963
|
if (el) el.value = val;
|
|
1407
|
-
}, { sel: selector, val: args.value });
|
|
3964
|
+
}, sessionId, { sel: selector, val: args.value });
|
|
1408
3965
|
}
|
|
1409
3966
|
break;
|
|
1410
3967
|
case "hover":
|
|
@@ -1415,7 +3972,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1415
3972
|
const event = new MouseEvent("mouseover", { bubbles: true });
|
|
1416
3973
|
el.dispatchEvent(event);
|
|
1417
3974
|
}
|
|
1418
|
-
}, selector);
|
|
3975
|
+
}, sessionId, selector);
|
|
1419
3976
|
} else {
|
|
1420
3977
|
await browser.evaluate((sel) => {
|
|
1421
3978
|
const el = document.querySelector(sel);
|
|
@@ -1423,7 +3980,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1423
3980
|
const event = new MouseEvent("mouseover", { bubbles: true });
|
|
1424
3981
|
el.dispatchEvent(event);
|
|
1425
3982
|
}
|
|
1426
|
-
}, selector);
|
|
3983
|
+
}, sessionId, selector);
|
|
1427
3984
|
}
|
|
1428
3985
|
break;
|
|
1429
3986
|
case "blur":
|
|
@@ -1431,12 +3988,12 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1431
3988
|
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
1432
3989
|
const el = document.querySelector(sel);
|
|
1433
3990
|
if (el) el.blur();
|
|
1434
|
-
}, selector);
|
|
3991
|
+
}, sessionId, selector);
|
|
1435
3992
|
} else {
|
|
1436
3993
|
await browser.evaluate((sel) => {
|
|
1437
3994
|
const el = document.querySelector(sel);
|
|
1438
3995
|
if (el) el.blur();
|
|
1439
|
-
}, selector);
|
|
3996
|
+
}, sessionId, selector);
|
|
1440
3997
|
}
|
|
1441
3998
|
break;
|
|
1442
3999
|
case "focus":
|
|
@@ -1444,12 +4001,12 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1444
4001
|
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
1445
4002
|
const el = document.querySelector(sel);
|
|
1446
4003
|
if (el) el.focus();
|
|
1447
|
-
}, selector);
|
|
4004
|
+
}, sessionId, selector);
|
|
1448
4005
|
} else {
|
|
1449
4006
|
await browser.evaluate((sel) => {
|
|
1450
4007
|
const el = document.querySelector(sel);
|
|
1451
4008
|
if (el) el.focus();
|
|
1452
|
-
}, selector);
|
|
4009
|
+
}, sessionId, selector);
|
|
1453
4010
|
}
|
|
1454
4011
|
break;
|
|
1455
4012
|
case "press": {
|
|
@@ -1474,7 +4031,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1474
4031
|
document.body.appendChild(a);
|
|
1475
4032
|
a.click();
|
|
1476
4033
|
document.body.removeChild(a);
|
|
1477
|
-
}, args.value);
|
|
4034
|
+
}, sessionId, args.value);
|
|
1478
4035
|
} else {
|
|
1479
4036
|
await browser.evaluate((url) => {
|
|
1480
4037
|
const a = document.createElement("a");
|
|
@@ -1483,19 +4040,19 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1483
4040
|
document.body.appendChild(a);
|
|
1484
4041
|
a.click();
|
|
1485
4042
|
document.body.removeChild(a);
|
|
1486
|
-
}, args.value);
|
|
4043
|
+
}, sessionId, args.value);
|
|
1487
4044
|
}
|
|
1488
4045
|
} else {
|
|
1489
4046
|
if (targetFrame) {
|
|
1490
4047
|
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
1491
4048
|
const el = document.querySelector(sel);
|
|
1492
4049
|
if (el) el.click();
|
|
1493
|
-
}, selector);
|
|
4050
|
+
}, sessionId, selector);
|
|
1494
4051
|
} else {
|
|
1495
4052
|
await browser.evaluate((sel) => {
|
|
1496
4053
|
const el = document.querySelector(sel);
|
|
1497
4054
|
if (el) el.click();
|
|
1498
|
-
}, selector);
|
|
4055
|
+
}, sessionId, selector);
|
|
1499
4056
|
}
|
|
1500
4057
|
}
|
|
1501
4058
|
const pollDeadline = Date.now() + 5e3;
|
|
@@ -1505,87 +4062,354 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1505
4062
|
(d) => !downloadsBefore.some((b) => b.downloadId === d.downloadId)
|
|
1506
4063
|
);
|
|
1507
4064
|
if (!newDownload) {
|
|
1508
|
-
await browser.evaluate(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
|
4065
|
+
await browser.evaluate(() => new Promise((resolve) => setTimeout(resolve, 50)), sessionId);
|
|
4066
|
+
}
|
|
4067
|
+
}
|
|
4068
|
+
if (!newDownload) {
|
|
4069
|
+
return {
|
|
4070
|
+
status: "error",
|
|
4071
|
+
error: "Download not detected after click (timeout 5000ms). The page may navigate instead of downloading."
|
|
4072
|
+
};
|
|
4073
|
+
}
|
|
4074
|
+
const downloadInfo = await browser.waitForDownload(newDownload.downloadId, args.timeout);
|
|
4075
|
+
if (args.save_path) {
|
|
4076
|
+
await browser.saveDownload(downloadInfo.downloadId, args.save_path);
|
|
4077
|
+
}
|
|
4078
|
+
const result2 = {
|
|
4079
|
+
status: "success",
|
|
4080
|
+
data: {
|
|
4081
|
+
action: args.action,
|
|
4082
|
+
target_id: args.target_id,
|
|
4083
|
+
success: downloadInfo.status === "completed",
|
|
4084
|
+
download: {
|
|
4085
|
+
downloadId: downloadInfo.downloadId,
|
|
4086
|
+
filename: downloadInfo.filename,
|
|
4087
|
+
url: downloadInfo.url,
|
|
4088
|
+
status: downloadInfo.status,
|
|
4089
|
+
path: args.save_path ?? downloadInfo.path ?? void 0
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
};
|
|
4093
|
+
if (args.return_state !== false) {
|
|
4094
|
+
const currentUrl = await browser.evaluate(() => window.location.href, sessionId);
|
|
4095
|
+
const state = await getStateAfterAction(session, browser, currentUrl, sessionId);
|
|
4096
|
+
if (result2.data) {
|
|
4097
|
+
result2.data.state = state;
|
|
4098
|
+
if (state.error) {
|
|
4099
|
+
result2.warning = `State extraction failed: ${state.error}`;
|
|
4100
|
+
}
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
result2.metadata = computeToolMetrics(result2.data, startTime);
|
|
4104
|
+
return result2;
|
|
4105
|
+
}
|
|
4106
|
+
case "upload": {
|
|
4107
|
+
if (!args.value) {
|
|
4108
|
+
return {
|
|
4109
|
+
status: "error",
|
|
4110
|
+
error: "value is required for upload action (file path(s), comma-separated)"
|
|
4111
|
+
};
|
|
4112
|
+
}
|
|
4113
|
+
const filePaths = args.value.split(",").map((p) => p.trim()).filter(Boolean);
|
|
4114
|
+
if (filePaths.length === 0) {
|
|
4115
|
+
return {
|
|
4116
|
+
status: "error",
|
|
4117
|
+
error: "value must contain at least one file path"
|
|
4118
|
+
};
|
|
4119
|
+
}
|
|
4120
|
+
await target.locator(selector).setInputFiles(filePaths.length === 1 ? filePaths[0] : filePaths);
|
|
4121
|
+
const result2 = {
|
|
4122
|
+
status: "success",
|
|
4123
|
+
data: {
|
|
4124
|
+
action: args.action,
|
|
4125
|
+
target_id: args.target_id,
|
|
4126
|
+
success: true,
|
|
4127
|
+
upload: {
|
|
4128
|
+
selector,
|
|
4129
|
+
files: filePaths,
|
|
4130
|
+
success: true
|
|
4131
|
+
}
|
|
4132
|
+
}
|
|
4133
|
+
};
|
|
4134
|
+
if (args.return_state !== false) {
|
|
4135
|
+
const currentUrl = await browser.evaluate(() => window.location.href, sessionId);
|
|
4136
|
+
const state = await getStateAfterAction(session, browser, currentUrl, sessionId);
|
|
4137
|
+
if (result2.data) {
|
|
4138
|
+
result2.data.state = state;
|
|
4139
|
+
if (state.error) {
|
|
4140
|
+
result2.warning = `State extraction failed: ${state.error}`;
|
|
4141
|
+
}
|
|
1509
4142
|
}
|
|
1510
4143
|
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
4144
|
+
result2.metadata = computeToolMetrics(result2.data, startTime);
|
|
4145
|
+
return result2;
|
|
4146
|
+
}
|
|
4147
|
+
case "clear": {
|
|
4148
|
+
if (targetFrame) {
|
|
4149
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4150
|
+
const el = document.querySelector(sel);
|
|
4151
|
+
if (el) {
|
|
4152
|
+
el.value = "";
|
|
4153
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
4154
|
+
el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
4155
|
+
}
|
|
4156
|
+
}, sessionId, selector);
|
|
4157
|
+
} else {
|
|
4158
|
+
await browser.evaluate((sel) => {
|
|
4159
|
+
const el = document.querySelector(sel);
|
|
4160
|
+
if (el) {
|
|
4161
|
+
el.value = "";
|
|
4162
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
4163
|
+
el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
4164
|
+
}
|
|
4165
|
+
}, sessionId, selector);
|
|
4166
|
+
}
|
|
4167
|
+
break;
|
|
4168
|
+
}
|
|
4169
|
+
case "drag": {
|
|
4170
|
+
if (!args.value) {
|
|
4171
|
+
return {
|
|
4172
|
+
status: "error",
|
|
4173
|
+
error: "value is required for drag action (destination element ID)"
|
|
4174
|
+
};
|
|
4175
|
+
}
|
|
4176
|
+
const destIdMap = session.getIdMap();
|
|
4177
|
+
const destResolvedId = destIdMap.get(args.value) || args.value;
|
|
4178
|
+
const destSelector = `[data-vsl-id="${destResolvedId}"], #${destResolvedId}, .${destResolvedId}`;
|
|
4179
|
+
if (targetFrame) {
|
|
4180
|
+
await browser.evaluateInFrame(targetFrame, ({ srcSel, dstSel }) => {
|
|
4181
|
+
const source = document.querySelector(srcSel);
|
|
4182
|
+
const destination = document.querySelector(dstSel);
|
|
4183
|
+
if (source && destination) {
|
|
4184
|
+
const dispatchDragEvent = (el, type) => {
|
|
4185
|
+
if (typeof DragEvent === "function") {
|
|
4186
|
+
el.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true }));
|
|
4187
|
+
} else {
|
|
4188
|
+
el.dispatchEvent(new Event(type, { bubbles: true, cancelable: true }));
|
|
4189
|
+
}
|
|
4190
|
+
};
|
|
4191
|
+
dispatchDragEvent(source, "dragstart");
|
|
4192
|
+
dispatchDragEvent(destination, "dragenter");
|
|
4193
|
+
dispatchDragEvent(destination, "dragover");
|
|
4194
|
+
dispatchDragEvent(destination, "drop");
|
|
4195
|
+
dispatchDragEvent(source, "dragend");
|
|
4196
|
+
}
|
|
4197
|
+
}, sessionId, { srcSel: selector, dstSel: destSelector });
|
|
4198
|
+
} else {
|
|
4199
|
+
await browser.evaluate(({ srcSel, dstSel }) => {
|
|
4200
|
+
const source = document.querySelector(srcSel);
|
|
4201
|
+
const destination = document.querySelector(dstSel);
|
|
4202
|
+
if (source && destination) {
|
|
4203
|
+
const dispatchDragEvent = (el, type) => {
|
|
4204
|
+
if (typeof DragEvent === "function") {
|
|
4205
|
+
el.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true }));
|
|
4206
|
+
} else {
|
|
4207
|
+
el.dispatchEvent(new Event(type, { bubbles: true, cancelable: true }));
|
|
4208
|
+
}
|
|
4209
|
+
};
|
|
4210
|
+
dispatchDragEvent(source, "dragstart");
|
|
4211
|
+
dispatchDragEvent(destination, "dragenter");
|
|
4212
|
+
dispatchDragEvent(destination, "dragover");
|
|
4213
|
+
dispatchDragEvent(destination, "drop");
|
|
4214
|
+
dispatchDragEvent(source, "dragend");
|
|
4215
|
+
}
|
|
4216
|
+
}, sessionId, { srcSel: selector, dstSel: destSelector });
|
|
4217
|
+
}
|
|
4218
|
+
break;
|
|
4219
|
+
}
|
|
4220
|
+
case "drop": {
|
|
4221
|
+
if (targetFrame) {
|
|
4222
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4223
|
+
const el = document.querySelector(sel);
|
|
4224
|
+
if (el) {
|
|
4225
|
+
const dispatchDragEvent = (el2, type) => {
|
|
4226
|
+
if (typeof DragEvent === "function") {
|
|
4227
|
+
el2.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true }));
|
|
4228
|
+
} else {
|
|
4229
|
+
el2.dispatchEvent(new Event(type, { bubbles: true, cancelable: true }));
|
|
4230
|
+
}
|
|
4231
|
+
};
|
|
4232
|
+
dispatchDragEvent(el, "dragover");
|
|
4233
|
+
dispatchDragEvent(el, "drop");
|
|
4234
|
+
}
|
|
4235
|
+
}, sessionId, selector);
|
|
4236
|
+
} else {
|
|
4237
|
+
await browser.evaluate((sel) => {
|
|
4238
|
+
const el = document.querySelector(sel);
|
|
4239
|
+
if (el) {
|
|
4240
|
+
const dispatchDragEvent = (el2, type) => {
|
|
4241
|
+
if (typeof DragEvent === "function") {
|
|
4242
|
+
el2.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true }));
|
|
4243
|
+
} else {
|
|
4244
|
+
el2.dispatchEvent(new Event(type, { bubbles: true, cancelable: true }));
|
|
4245
|
+
}
|
|
4246
|
+
};
|
|
4247
|
+
dispatchDragEvent(el, "dragover");
|
|
4248
|
+
dispatchDragEvent(el, "drop");
|
|
4249
|
+
}
|
|
4250
|
+
}, sessionId, selector);
|
|
4251
|
+
}
|
|
4252
|
+
break;
|
|
4253
|
+
}
|
|
4254
|
+
case "submit": {
|
|
4255
|
+
if (targetFrame) {
|
|
4256
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4257
|
+
const form = document.querySelector(sel);
|
|
4258
|
+
if (form) {
|
|
4259
|
+
form.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
|
|
4260
|
+
}
|
|
4261
|
+
}, sessionId, selector);
|
|
4262
|
+
} else {
|
|
4263
|
+
await browser.evaluate((sel) => {
|
|
4264
|
+
const form = document.querySelector(sel);
|
|
4265
|
+
if (form) {
|
|
4266
|
+
form.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
|
|
4267
|
+
}
|
|
4268
|
+
}, sessionId, selector);
|
|
4269
|
+
}
|
|
4270
|
+
break;
|
|
4271
|
+
}
|
|
4272
|
+
case "reset": {
|
|
4273
|
+
if (targetFrame) {
|
|
4274
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4275
|
+
const form = document.querySelector(sel);
|
|
4276
|
+
if (form) {
|
|
4277
|
+
form.reset();
|
|
4278
|
+
}
|
|
4279
|
+
}, sessionId, selector);
|
|
4280
|
+
} else {
|
|
4281
|
+
await browser.evaluate((sel) => {
|
|
4282
|
+
const form = document.querySelector(sel);
|
|
4283
|
+
if (form) {
|
|
4284
|
+
form.reset();
|
|
4285
|
+
}
|
|
4286
|
+
}, sessionId, selector);
|
|
4287
|
+
}
|
|
4288
|
+
break;
|
|
4289
|
+
}
|
|
4290
|
+
case "open": {
|
|
4291
|
+
if (targetFrame) {
|
|
4292
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4293
|
+
const el = document.querySelector(sel);
|
|
4294
|
+
if (typeof HTMLDialogElement !== "undefined" && el instanceof HTMLDialogElement) {
|
|
4295
|
+
el.showModal();
|
|
4296
|
+
} else if (el instanceof HTMLDetailsElement) {
|
|
4297
|
+
el.open = true;
|
|
4298
|
+
}
|
|
4299
|
+
}, sessionId, selector);
|
|
4300
|
+
} else {
|
|
4301
|
+
await browser.evaluate((sel) => {
|
|
4302
|
+
const el = document.querySelector(sel);
|
|
4303
|
+
if (typeof HTMLDialogElement !== "undefined" && el instanceof HTMLDialogElement) {
|
|
4304
|
+
el.showModal();
|
|
4305
|
+
} else if (el instanceof HTMLDetailsElement) {
|
|
4306
|
+
el.open = true;
|
|
4307
|
+
}
|
|
4308
|
+
}, sessionId, selector);
|
|
4309
|
+
}
|
|
4310
|
+
break;
|
|
4311
|
+
}
|
|
4312
|
+
case "close": {
|
|
4313
|
+
if (targetFrame) {
|
|
4314
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4315
|
+
const el = document.querySelector(sel);
|
|
4316
|
+
if (typeof HTMLDialogElement !== "undefined" && el instanceof HTMLDialogElement) {
|
|
4317
|
+
el.close();
|
|
4318
|
+
} else if (el instanceof HTMLDetailsElement) {
|
|
4319
|
+
el.open = false;
|
|
4320
|
+
}
|
|
4321
|
+
}, sessionId, selector);
|
|
4322
|
+
} else {
|
|
4323
|
+
await browser.evaluate((sel) => {
|
|
4324
|
+
const el = document.querySelector(sel);
|
|
4325
|
+
if (typeof HTMLDialogElement !== "undefined" && el instanceof HTMLDialogElement) {
|
|
4326
|
+
el.close();
|
|
4327
|
+
} else if (el instanceof HTMLDetailsElement) {
|
|
4328
|
+
el.open = false;
|
|
4329
|
+
}
|
|
4330
|
+
}, sessionId, selector);
|
|
1516
4331
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
4332
|
+
break;
|
|
4333
|
+
}
|
|
4334
|
+
case "expand": {
|
|
4335
|
+
if (targetFrame) {
|
|
4336
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4337
|
+
const el = document.querySelector(sel);
|
|
4338
|
+
if (el) {
|
|
4339
|
+
if (el instanceof HTMLDetailsElement) {
|
|
4340
|
+
el.open = true;
|
|
4341
|
+
} else if (el.hasAttribute("aria-expanded")) {
|
|
4342
|
+
el.setAttribute("aria-expanded", "true");
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
}, sessionId, selector);
|
|
4346
|
+
} else {
|
|
4347
|
+
await browser.evaluate((sel) => {
|
|
4348
|
+
const el = document.querySelector(sel);
|
|
4349
|
+
if (el) {
|
|
4350
|
+
if (el instanceof HTMLDetailsElement) {
|
|
4351
|
+
el.open = true;
|
|
4352
|
+
} else if (el.hasAttribute("aria-expanded")) {
|
|
4353
|
+
el.setAttribute("aria-expanded", "true");
|
|
4354
|
+
}
|
|
4355
|
+
}
|
|
4356
|
+
}, sessionId, selector);
|
|
1520
4357
|
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
4358
|
+
break;
|
|
4359
|
+
}
|
|
4360
|
+
case "collapse": {
|
|
4361
|
+
if (targetFrame) {
|
|
4362
|
+
await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
4363
|
+
const el = document.querySelector(sel);
|
|
4364
|
+
if (el) {
|
|
4365
|
+
if (el instanceof HTMLDetailsElement) {
|
|
4366
|
+
el.open = false;
|
|
4367
|
+
} else if (el.hasAttribute("aria-expanded")) {
|
|
4368
|
+
el.setAttribute("aria-expanded", "false");
|
|
4369
|
+
}
|
|
1533
4370
|
}
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
4371
|
+
}, sessionId, selector);
|
|
4372
|
+
} else {
|
|
4373
|
+
await browser.evaluate((sel) => {
|
|
4374
|
+
const el = document.querySelector(sel);
|
|
4375
|
+
if (el) {
|
|
4376
|
+
if (el instanceof HTMLDetailsElement) {
|
|
4377
|
+
el.open = false;
|
|
4378
|
+
} else if (el.hasAttribute("aria-expanded")) {
|
|
4379
|
+
el.setAttribute("aria-expanded", "false");
|
|
4380
|
+
}
|
|
1543
4381
|
}
|
|
1544
|
-
}
|
|
4382
|
+
}, sessionId, selector);
|
|
1545
4383
|
}
|
|
1546
|
-
|
|
1547
|
-
return result2;
|
|
4384
|
+
break;
|
|
1548
4385
|
}
|
|
1549
|
-
case "
|
|
4386
|
+
case "wait": {
|
|
1550
4387
|
if (!args.value) {
|
|
1551
4388
|
return {
|
|
1552
4389
|
status: "error",
|
|
1553
|
-
error:
|
|
1554
|
-
};
|
|
1555
|
-
}
|
|
1556
|
-
const filePaths = args.value.split(",").map((p) => p.trim()).filter(Boolean);
|
|
1557
|
-
if (filePaths.length === 0) {
|
|
1558
|
-
return {
|
|
1559
|
-
status: "error",
|
|
1560
|
-
error: "value must contain at least one file path"
|
|
4390
|
+
error: 'value is required for wait action (selector or "idle")'
|
|
1561
4391
|
};
|
|
1562
4392
|
}
|
|
1563
|
-
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
success: true,
|
|
1570
|
-
upload: {
|
|
1571
|
-
selector,
|
|
1572
|
-
files: filePaths,
|
|
1573
|
-
success: true
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
};
|
|
1577
|
-
if (args.return_state !== false) {
|
|
1578
|
-
const currentUrl = await browser.evaluate(() => window.location.href);
|
|
1579
|
-
const state = await getStateAfterAction(session, browser, currentUrl);
|
|
1580
|
-
if (result2.data) {
|
|
1581
|
-
result2.data.state = state;
|
|
1582
|
-
if (state.error) {
|
|
1583
|
-
result2.warning = `State extraction failed: ${state.error}`;
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
4393
|
+
const timeout = args.timeout || 5e3;
|
|
4394
|
+
const condition = args.value;
|
|
4395
|
+
if (condition === "idle") {
|
|
4396
|
+
await page.waitForLoadState("domcontentloaded", { timeout });
|
|
4397
|
+
} else {
|
|
4398
|
+
await page.waitForSelector(condition, { timeout, state: "attached" });
|
|
1586
4399
|
}
|
|
1587
|
-
|
|
1588
|
-
|
|
4400
|
+
break;
|
|
4401
|
+
}
|
|
4402
|
+
case "go_back": {
|
|
4403
|
+
await page.goBack({ timeout: args.timeout || 5e3 });
|
|
4404
|
+
break;
|
|
4405
|
+
}
|
|
4406
|
+
case "go_forward": {
|
|
4407
|
+
await page.goForward({ timeout: args.timeout || 5e3 });
|
|
4408
|
+
break;
|
|
4409
|
+
}
|
|
4410
|
+
case "refresh": {
|
|
4411
|
+
await page.reload({ timeout: args.timeout || 5e3 });
|
|
4412
|
+
break;
|
|
1589
4413
|
}
|
|
1590
4414
|
default:
|
|
1591
4415
|
return {
|
|
@@ -1604,11 +4428,11 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1604
4428
|
if (args.return_state !== false) {
|
|
1605
4429
|
await browser.evaluate(() => {
|
|
1606
4430
|
return new Promise((resolve) => {
|
|
1607
|
-
setTimeout(
|
|
4431
|
+
setTimeout(resolve, 100);
|
|
1608
4432
|
});
|
|
1609
|
-
});
|
|
1610
|
-
const currentUrl = await browser.evaluate(() => window.location.href);
|
|
1611
|
-
const state = await getStateAfterAction(session, browser, currentUrl);
|
|
4433
|
+
}, sessionId);
|
|
4434
|
+
const currentUrl = await browser.evaluate(() => window.location.href, sessionId);
|
|
4435
|
+
const state = await getStateAfterAction(session, browser, currentUrl, sessionId);
|
|
1612
4436
|
if (result.data) {
|
|
1613
4437
|
result.data.state = state;
|
|
1614
4438
|
if (state.error) {
|
|
@@ -1627,7 +4451,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1627
4451
|
}
|
|
1628
4452
|
|
|
1629
4453
|
// src/tools/getVisual.ts
|
|
1630
|
-
async function handleGetVisual(args, browser, session) {
|
|
4454
|
+
async function handleGetVisual(args, browser, session, sessionId) {
|
|
1631
4455
|
const startTime = Date.now();
|
|
1632
4456
|
try {
|
|
1633
4457
|
if (!args.element_id || typeof args.element_id !== "string") {
|
|
@@ -1658,7 +4482,7 @@ async function handleGetVisual(args, browser, session) {
|
|
|
1658
4482
|
};
|
|
1659
4483
|
}
|
|
1660
4484
|
if (args.element_id === "root_0") {
|
|
1661
|
-
const page2 = await browser.getPage();
|
|
4485
|
+
const page2 = await browser.getPage(sessionId);
|
|
1662
4486
|
const screenshotBuffer2 = await page2.screenshot({ type: "png", fullPage: false });
|
|
1663
4487
|
const base64Image2 = screenshotBuffer2.toString("base64");
|
|
1664
4488
|
const result2 = {
|
|
@@ -1675,12 +4499,12 @@ async function handleGetVisual(args, browser, session) {
|
|
|
1675
4499
|
const selector = `[data-vsl-id="${resolvedId}"], #${resolvedId}, [id="${resolvedId}"]`;
|
|
1676
4500
|
let elementExists = await browser.evaluate((sel) => {
|
|
1677
4501
|
return document.querySelector(sel) !== null;
|
|
1678
|
-
}, selector);
|
|
4502
|
+
}, sessionId, selector);
|
|
1679
4503
|
if (!elementExists && args.auto_refresh && session) {
|
|
1680
|
-
await handleGetSnapshot({}, browser, session, { downloadsPath: "" });
|
|
4504
|
+
await handleGetSnapshot({}, browser, session, { downloadsPath: "" }, sessionId);
|
|
1681
4505
|
elementExists = await browser.evaluate((sel) => {
|
|
1682
4506
|
return document.querySelector(sel) !== null;
|
|
1683
|
-
}, selector);
|
|
4507
|
+
}, sessionId, selector);
|
|
1684
4508
|
}
|
|
1685
4509
|
if (!elementExists) {
|
|
1686
4510
|
const suggestions = [
|
|
@@ -1700,7 +4524,7 @@ async function handleGetVisual(args, browser, session) {
|
|
|
1700
4524
|
suggestions
|
|
1701
4525
|
};
|
|
1702
4526
|
}
|
|
1703
|
-
const page = await browser.getPage();
|
|
4527
|
+
const page = await browser.getPage(sessionId);
|
|
1704
4528
|
const autoScroll = args.auto_scroll !== false;
|
|
1705
4529
|
let scrolled = false;
|
|
1706
4530
|
let scrollOffset;
|
|
@@ -1717,7 +4541,7 @@ async function handleGetVisual(args, browser, session) {
|
|
|
1717
4541
|
}
|
|
1718
4542
|
el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
|
|
1719
4543
|
return { needsScroll: true, scrolled: true };
|
|
1720
|
-
}, selector);
|
|
4544
|
+
}, sessionId, selector);
|
|
1721
4545
|
if (scrollResult.scrolled) {
|
|
1722
4546
|
scrolled = true;
|
|
1723
4547
|
await browser.evaluate(() => {
|
|
@@ -1728,10 +4552,10 @@ async function handleGetVisual(args, browser, session) {
|
|
|
1728
4552
|
});
|
|
1729
4553
|
});
|
|
1730
4554
|
});
|
|
1731
|
-
});
|
|
4555
|
+
}, sessionId);
|
|
1732
4556
|
scrollOffset = await browser.evaluate(() => {
|
|
1733
4557
|
return { x: window.scrollX, y: window.scrollY };
|
|
1734
|
-
});
|
|
4558
|
+
}, sessionId);
|
|
1735
4559
|
}
|
|
1736
4560
|
}
|
|
1737
4561
|
const rect = await browser.evaluate((sel) => {
|
|
@@ -1744,7 +4568,7 @@ async function handleGetVisual(args, browser, session) {
|
|
|
1744
4568
|
width: r.width,
|
|
1745
4569
|
height: r.height
|
|
1746
4570
|
};
|
|
1747
|
-
}, selector);
|
|
4571
|
+
}, sessionId, selector);
|
|
1748
4572
|
if (!rect) {
|
|
1749
4573
|
return {
|
|
1750
4574
|
content: [{ type: "text", text: `Error: Could not get bounding box for element: ${args.element_id}` }],
|
|
@@ -2051,7 +4875,7 @@ function determineActions(type, state, $el) {
|
|
|
2051
4875
|
}
|
|
2052
4876
|
|
|
2053
4877
|
// src/tools/readPage.ts
|
|
2054
|
-
async function handleReadPage(args, browser, session, _config) {
|
|
4878
|
+
async function handleReadPage(args, browser, session, _config, sessionId) {
|
|
2055
4879
|
const startTime = Date.now();
|
|
2056
4880
|
if (!args.url || typeof args.url !== "string" || args.url.trim() === "") {
|
|
2057
4881
|
return {
|
|
@@ -2099,12 +4923,12 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
2099
4923
|
error: "Playwright is not installed. Install it with: npm install playwright\nStatic pages can still be read via HTTP path (no browser required)."
|
|
2100
4924
|
};
|
|
2101
4925
|
}
|
|
2102
|
-
await browser.navigate(args.url);
|
|
2103
|
-
const html = await browser.getContent();
|
|
4926
|
+
await browser.navigate(args.url, sessionId);
|
|
4927
|
+
const html = await browser.getContent(sessionId);
|
|
2104
4928
|
const isSpa = detectSpa(html);
|
|
2105
4929
|
const hadPreviousSnapshot2 = session.hasSnapshot();
|
|
2106
4930
|
try {
|
|
2107
|
-
const extraction = await extractDomTree(browser);
|
|
4931
|
+
const extraction = await extractDomTree(browser, sessionId);
|
|
2108
4932
|
session.snapshotFromElements(extraction.elements, {
|
|
2109
4933
|
viewport: extraction.viewport,
|
|
2110
4934
|
url: args.url,
|
|
@@ -2112,10 +4936,10 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
2112
4936
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2113
4937
|
scroll: extraction.scroll
|
|
2114
4938
|
});
|
|
2115
|
-
await injectVslIdsIntoDom(browser, session.getSnapshot().objects);
|
|
4939
|
+
await injectVslIdsIntoDom(browser, session.getSnapshot().objects, /* @__PURE__ */ new Map(), sessionId);
|
|
2116
4940
|
} catch (extractError) {
|
|
2117
4941
|
console.error("[vsl_read_page] SDK extraction failed, falling back to legacy extraction:", extractError);
|
|
2118
|
-
const fallbackDoc = await extractVslFromPage(browser);
|
|
4942
|
+
const fallbackDoc = await extractVslFromPage(browser, sessionId);
|
|
2119
4943
|
session.setSnapshot(fallbackDoc);
|
|
2120
4944
|
}
|
|
2121
4945
|
const hasDiff2 = hadPreviousSnapshot2;
|
|
@@ -2141,7 +4965,7 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
2141
4965
|
url: args.url,
|
|
2142
4966
|
mode: "render",
|
|
2143
4967
|
content,
|
|
2144
|
-
vslDocument: rawSnapshot2,
|
|
4968
|
+
vslDocument: replaceIdsInDocument(rawSnapshot2, reverseIdMap2),
|
|
2145
4969
|
snapshot: finalSnapshot2,
|
|
2146
4970
|
diff: finalDiff2,
|
|
2147
4971
|
hasDiff: hasDiff2,
|
|
@@ -2187,7 +5011,7 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
2187
5011
|
url: args.url,
|
|
2188
5012
|
mode: "http",
|
|
2189
5013
|
content: httpResult.textContent,
|
|
2190
|
-
vslDocument:
|
|
5014
|
+
vslDocument: replaceIdsInDocument(rawSnapshot, reverseIdMap),
|
|
2191
5015
|
snapshot: finalSnapshot,
|
|
2192
5016
|
diff: finalDiff,
|
|
2193
5017
|
hasDiff,
|
|
@@ -2216,7 +5040,7 @@ Stack: ${stack}`
|
|
|
2216
5040
|
};
|
|
2217
5041
|
}
|
|
2218
5042
|
}
|
|
2219
|
-
async function extractVslFromPage(browser) {
|
|
5043
|
+
async function extractVslFromPage(browser, sessionId) {
|
|
2220
5044
|
let domTree = null;
|
|
2221
5045
|
try {
|
|
2222
5046
|
domTree = await browser.evaluate(() => {
|
|
@@ -2246,7 +5070,7 @@ async function extractVslFromPage(browser) {
|
|
|
2246
5070
|
};
|
|
2247
5071
|
};
|
|
2248
5072
|
return extractElement(document.documentElement);
|
|
2249
|
-
});
|
|
5073
|
+
}, sessionId);
|
|
2250
5074
|
} catch (error) {
|
|
2251
5075
|
console.error("extractVslFromPage: browser.evaluate failed:", error);
|
|
2252
5076
|
domTree = null;
|
|
@@ -2365,6 +5189,154 @@ async function handleGetTextBlock(args, session) {
|
|
|
2365
5189
|
}
|
|
2366
5190
|
}
|
|
2367
5191
|
|
|
5192
|
+
// src/tools/clickCoordinates.ts
|
|
5193
|
+
async function handleClickCoordinates(args, browser, session, sessionId) {
|
|
5194
|
+
const startTime = Date.now();
|
|
5195
|
+
try {
|
|
5196
|
+
let findObjectById2 = function(objects, targetId) {
|
|
5197
|
+
for (const obj of objects) {
|
|
5198
|
+
const o = obj;
|
|
5199
|
+
if (o.id === targetId) return o;
|
|
5200
|
+
if (o.ch && Array.isArray(o.ch)) {
|
|
5201
|
+
const found = findObjectById2(o.ch, targetId);
|
|
5202
|
+
if (found) return found;
|
|
5203
|
+
}
|
|
5204
|
+
}
|
|
5205
|
+
return null;
|
|
5206
|
+
};
|
|
5207
|
+
var findObjectById = findObjectById2;
|
|
5208
|
+
if (!args.target_id || typeof args.target_id !== "string") {
|
|
5209
|
+
return { status: "error", error: "target_id is required" };
|
|
5210
|
+
}
|
|
5211
|
+
if (!args.clicks || !Array.isArray(args.clicks) || args.clicks.length === 0) {
|
|
5212
|
+
return { status: "error", error: "clicks array is required and must not be empty" };
|
|
5213
|
+
}
|
|
5214
|
+
for (let i = 0; i < args.clicks.length; i++) {
|
|
5215
|
+
const click = args.clicks[i];
|
|
5216
|
+
if (typeof click.x !== "number" || typeof click.y !== "number") {
|
|
5217
|
+
return { status: "error", error: `clicks[${i}]: x and y must be numbers` };
|
|
5218
|
+
}
|
|
5219
|
+
if (click.delay_after_ms !== void 0 && typeof click.delay_after_ms !== "number") {
|
|
5220
|
+
return { status: "error", error: `clicks[${i}]: delay_after_ms must be a number` };
|
|
5221
|
+
}
|
|
5222
|
+
}
|
|
5223
|
+
if (args.return_state !== void 0 && typeof args.return_state !== "boolean") {
|
|
5224
|
+
return { status: "error", error: "return_state must be a boolean (true or false)" };
|
|
5225
|
+
}
|
|
5226
|
+
if (!session.hasSnapshot()) {
|
|
5227
|
+
return {
|
|
5228
|
+
status: "error",
|
|
5229
|
+
error: "No snapshot available. Call vsl_get_snapshot first."
|
|
5230
|
+
};
|
|
5231
|
+
}
|
|
5232
|
+
const isAvailable = await browser.isAvailable();
|
|
5233
|
+
if (!isAvailable) {
|
|
5234
|
+
return {
|
|
5235
|
+
status: "error",
|
|
5236
|
+
error: "Playwright is not installed. Install it with: npm install playwright"
|
|
5237
|
+
};
|
|
5238
|
+
}
|
|
5239
|
+
const page = await browser.getPage(sessionId);
|
|
5240
|
+
let targetFrame = null;
|
|
5241
|
+
const frameMatch = args.target_id.match(/^iframe_(\d+):(.+)$/);
|
|
5242
|
+
if (frameMatch) {
|
|
5243
|
+
const frameIndex = parseInt(frameMatch[1], 10);
|
|
5244
|
+
const frameUrl = iframeFrameRegistry.get(frameIndex);
|
|
5245
|
+
if (!frameUrl) {
|
|
5246
|
+
return {
|
|
5247
|
+
status: "error",
|
|
5248
|
+
error: `Frame iframe_${frameIndex} not found in registry. Call vsl_get_snapshot first.`
|
|
5249
|
+
};
|
|
5250
|
+
}
|
|
5251
|
+
const frames = await browser.getFrames(sessionId);
|
|
5252
|
+
targetFrame = frames.find((f) => {
|
|
5253
|
+
const u = f.url();
|
|
5254
|
+
return u === frameUrl || u.includes(frameUrl) || frameUrl.includes(u);
|
|
5255
|
+
}) || null;
|
|
5256
|
+
if (!targetFrame) {
|
|
5257
|
+
return {
|
|
5258
|
+
status: "error",
|
|
5259
|
+
error: `Frame with URL "${frameUrl}" not found. Available frames: ${frames.map((f) => f.url()).join(", ")}`
|
|
5260
|
+
};
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
5263
|
+
const idMap = session.getIdMap();
|
|
5264
|
+
const longId = idMap.get(args.target_id);
|
|
5265
|
+
if (!longId) {
|
|
5266
|
+
return {
|
|
5267
|
+
status: "error",
|
|
5268
|
+
error: `Short ID "${args.target_id}" not found in idMap. Available short IDs: ${Array.from(idMap.keys()).join(", ")}`
|
|
5269
|
+
};
|
|
5270
|
+
}
|
|
5271
|
+
const snapshotDoc = session.getSnapshot();
|
|
5272
|
+
const snapshotObjects = snapshotDoc.objects ?? [];
|
|
5273
|
+
const snapshotObj = findObjectById2(snapshotObjects, longId);
|
|
5274
|
+
if (!snapshotObj || !snapshotObj.p || !snapshotObj.s) {
|
|
5275
|
+
return {
|
|
5276
|
+
status: "error",
|
|
5277
|
+
error: `Element "${args.target_id}" (resolved: ${longId}) not found in snapshot or has no position/size. Call vsl_get_snapshot first.`
|
|
5278
|
+
};
|
|
5279
|
+
}
|
|
5280
|
+
const elementRect = {
|
|
5281
|
+
x: snapshotObj.p[0] - snapshotObj.s[0] / 2,
|
|
5282
|
+
y: snapshotObj.p[1] - snapshotObj.s[1] / 2,
|
|
5283
|
+
width: snapshotObj.s[0],
|
|
5284
|
+
height: snapshotObj.s[1]
|
|
5285
|
+
};
|
|
5286
|
+
let actionsCompleted = 0;
|
|
5287
|
+
for (const click of args.clicks) {
|
|
5288
|
+
const absoluteX = elementRect.x + click.x;
|
|
5289
|
+
const absoluteY = elementRect.y + click.y;
|
|
5290
|
+
await page.mouse.click(absoluteX, absoluteY);
|
|
5291
|
+
actionsCompleted++;
|
|
5292
|
+
if (click.delay_after_ms && click.delay_after_ms > 0) {
|
|
5293
|
+
await page.waitForTimeout(click.delay_after_ms);
|
|
5294
|
+
}
|
|
5295
|
+
}
|
|
5296
|
+
await page.waitForTimeout(100);
|
|
5297
|
+
const returnState = args.return_state !== false;
|
|
5298
|
+
const result = {
|
|
5299
|
+
status: "success",
|
|
5300
|
+
data: {
|
|
5301
|
+
actions_completed: actionsCompleted
|
|
5302
|
+
},
|
|
5303
|
+
metadata: computeToolMetrics(
|
|
5304
|
+
{ actions_completed: actionsCompleted, target_id: args.target_id },
|
|
5305
|
+
startTime
|
|
5306
|
+
)
|
|
5307
|
+
};
|
|
5308
|
+
if (returnState) {
|
|
5309
|
+
const currentUrl = await browser.evaluate(() => window.location.href, sessionId);
|
|
5310
|
+
const state = await getStateAfterAction(session, browser, currentUrl, sessionId);
|
|
5311
|
+
if (state.error) {
|
|
5312
|
+
result.data.diff = void 0;
|
|
5313
|
+
result.data.snapshot = void 0;
|
|
5314
|
+
} else {
|
|
5315
|
+
result.data.diff = state.diff;
|
|
5316
|
+
result.data.snapshot = state.snapshot;
|
|
5317
|
+
result.data.scrollable = state.scrollable;
|
|
5318
|
+
}
|
|
5319
|
+
try {
|
|
5320
|
+
const screenshotBuffer = await page.screenshot({ type: "png", fullPage: false });
|
|
5321
|
+
const base64Image = screenshotBuffer.toString("base64");
|
|
5322
|
+
result.data.screenshot = {
|
|
5323
|
+
type: "image",
|
|
5324
|
+
data: base64Image,
|
|
5325
|
+
mimeType: "image/png"
|
|
5326
|
+
};
|
|
5327
|
+
} catch (screenshotError) {
|
|
5328
|
+
console.error("[vsl_click_coordinates] Screenshot failed:", screenshotError);
|
|
5329
|
+
}
|
|
5330
|
+
}
|
|
5331
|
+
return result;
|
|
5332
|
+
} catch (error) {
|
|
5333
|
+
return {
|
|
5334
|
+
status: "error",
|
|
5335
|
+
error: `vsl_click_coordinates failed: ${error instanceof Error ? error.message : String(error)}`
|
|
5336
|
+
};
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
|
|
2368
5340
|
// src/tools/index.ts
|
|
2369
5341
|
var VSL_TOOLS = [
|
|
2370
5342
|
{
|
|
@@ -2498,6 +5470,37 @@ var VSL_TOOLS = [
|
|
|
2498
5470
|
},
|
|
2499
5471
|
required: ["block_id"]
|
|
2500
5472
|
}
|
|
5473
|
+
},
|
|
5474
|
+
{
|
|
5475
|
+
name: "vsl_click_coordinates",
|
|
5476
|
+
description: '\u0412\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u043C\u043D\u043E\u0436\u0435\u0441\u0442\u0432\u0435\u043D\u043D\u044B\u0435 \u043A\u043B\u0438\u043A\u0438 \u043F\u043E \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430\u043C \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0446\u0435\u043B\u0435\u0432\u043E\u0433\u043E \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430. \u041A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u044B (x, y) \u0437\u0430\u0434\u0430\u044E\u0442\u0441\u044F \u0432 \u043F\u0438\u043A\u0441\u0435\u043B\u044F\u0445 \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u0443\u0433\u043B\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 (\u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 bbox \u0438\u0437 snapshot). \u041F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u043A\u0438 \u043C\u0435\u0436\u0434\u0443 \u043A\u043B\u0438\u043A\u0430\u043C\u0438. \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 diff + snapshot + screenshot \u043F\u043E\u0441\u043B\u0435 \u0432\u0441\u0435\u0445 \u043A\u043B\u0438\u043A\u043E\u0432. \u041F\u0440\u0438\u043C\u0435\u0440: {target_id: "iframe_2", clicks: [{x: 50, y: 50, delay_after_ms: 500}, {x: 150, y: 50}]}.',
|
|
5477
|
+
inputSchema: {
|
|
5478
|
+
type: "object",
|
|
5479
|
+
properties: {
|
|
5480
|
+
target_id: {
|
|
5481
|
+
type: "string",
|
|
5482
|
+
description: "ID \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 \u0432 VSL JSON (\u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440, iframe_2 \u0434\u043B\u044F reCAPTCHA challenge iframe)"
|
|
5483
|
+
},
|
|
5484
|
+
clicks: {
|
|
5485
|
+
type: "array",
|
|
5486
|
+
description: "\u041C\u0430\u0441\u0441\u0438\u0432 \u043A\u043B\u0438\u043A\u043E\u0432. \u041A\u0430\u0436\u0434\u044B\u0439 \u043A\u043B\u0438\u043A: {x: number, y: number, delay_after_ms?: number}. \u041A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u044B \u0432 \u043F\u0438\u043A\u0441\u0435\u043B\u044F\u0445 \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u0443\u0433\u043B\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430.",
|
|
5487
|
+
items: {
|
|
5488
|
+
type: "object",
|
|
5489
|
+
properties: {
|
|
5490
|
+
x: { type: "number", description: "X \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430 (pixels \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u043A\u0440\u0430\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430)" },
|
|
5491
|
+
y: { type: "number", description: "Y \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430 (pixels \u043E\u0442 \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u043A\u0440\u0430\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430)" },
|
|
5492
|
+
delay_after_ms: { type: "number", description: "\u0417\u0430\u0434\u0435\u0440\u0436\u043A\u0430 \u043F\u043E\u0441\u043B\u0435 \u043A\u043B\u0438\u043A\u0430 (\u043C\u0441)" }
|
|
5493
|
+
},
|
|
5494
|
+
required: ["x", "y"]
|
|
5495
|
+
}
|
|
5496
|
+
},
|
|
5497
|
+
return_state: {
|
|
5498
|
+
type: "boolean",
|
|
5499
|
+
description: "\u0415\u0441\u043B\u0438 true (default), \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 diff + snapshot + screenshot \u043F\u043E\u0441\u043B\u0435 \u0432\u0441\u0435\u0445 \u043A\u043B\u0438\u043A\u043E\u0432."
|
|
5500
|
+
}
|
|
5501
|
+
},
|
|
5502
|
+
required: ["target_id", "clicks"]
|
|
5503
|
+
}
|
|
2501
5504
|
}
|
|
2502
5505
|
];
|
|
2503
5506
|
function registerTools(server, config, sessionManager) {
|
|
@@ -2506,34 +5509,38 @@ function registerTools(server, config, sessionManager) {
|
|
|
2506
5509
|
tools: VSL_TOOLS
|
|
2507
5510
|
};
|
|
2508
5511
|
});
|
|
2509
|
-
server.setRequestHandler(CallToolRequestSchema, async (
|
|
2510
|
-
const { name, arguments: args, _meta } =
|
|
5512
|
+
server.setRequestHandler(CallToolRequestSchema, async (request2) => {
|
|
5513
|
+
const { name, arguments: args, _meta } = request2.params;
|
|
2511
5514
|
const sessionId = _meta?.sessionId ?? sessionManager.getDefaultSessionId();
|
|
2512
|
-
const {
|
|
5515
|
+
const { session } = sessionManager.getSession(sessionId);
|
|
5516
|
+
const browser = sessionManager.getBrowserManager();
|
|
2513
5517
|
try {
|
|
2514
5518
|
let result;
|
|
2515
5519
|
switch (name) {
|
|
2516
5520
|
case "vsl_get_snapshot":
|
|
2517
|
-
result = await handleGetSnapshot(args, browser, session, config);
|
|
5521
|
+
result = await handleGetSnapshot(args, browser, session, config, sessionId);
|
|
2518
5522
|
break;
|
|
2519
5523
|
case "vsl_execute_action":
|
|
2520
|
-
result = await handleExecuteAction(args, browser, session);
|
|
5524
|
+
result = await handleExecuteAction(args, browser, session, sessionId);
|
|
2521
5525
|
break;
|
|
2522
5526
|
case "vsl_navigate":
|
|
2523
|
-
result = await handleNavigate(args, browser, session);
|
|
5527
|
+
result = await handleNavigate(args, browser, session, sessionId);
|
|
2524
5528
|
break;
|
|
2525
5529
|
case "vsl_clear_cache":
|
|
2526
5530
|
result = await handleClearCache(session);
|
|
2527
5531
|
break;
|
|
2528
5532
|
case "vsl_get_visual":
|
|
2529
|
-
result = await handleGetVisual(args, browser, session);
|
|
5533
|
+
result = await handleGetVisual(args, browser, session, sessionId);
|
|
2530
5534
|
break;
|
|
2531
5535
|
case "vsl_read_page":
|
|
2532
|
-
result = await handleReadPage(args, browser, session, config);
|
|
5536
|
+
result = await handleReadPage(args, browser, session, config, sessionId);
|
|
2533
5537
|
break;
|
|
2534
5538
|
case "vsl_get_text_block":
|
|
2535
5539
|
result = await handleGetTextBlock(args, session);
|
|
2536
5540
|
break;
|
|
5541
|
+
case "vsl_click_coordinates":
|
|
5542
|
+
result = await handleClickCoordinates(args, browser, session, sessionId);
|
|
5543
|
+
break;
|
|
2537
5544
|
default:
|
|
2538
5545
|
return {
|
|
2539
5546
|
content: [
|
|
@@ -2599,9 +5606,9 @@ function registerResources(server, _config, sessionManager) {
|
|
|
2599
5606
|
resources: VSL_RESOURCES
|
|
2600
5607
|
};
|
|
2601
5608
|
});
|
|
2602
|
-
server.setRequestHandler(ReadResourceRequestSchema, async (
|
|
2603
|
-
const { uri } =
|
|
2604
|
-
const sessionId =
|
|
5609
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request2) => {
|
|
5610
|
+
const { uri } = request2.params;
|
|
5611
|
+
const sessionId = request2.params._meta?.sessionId ?? sessionManager.getDefaultSessionId();
|
|
2605
5612
|
const { session } = sessionManager.getSession(sessionId);
|
|
2606
5613
|
ensureSubscribed(sessionId, session);
|
|
2607
5614
|
switch (uri) {
|
|
@@ -2693,9 +5700,11 @@ import os from "os";
|
|
|
2693
5700
|
var BrowserManager = class {
|
|
2694
5701
|
browser = null;
|
|
2695
5702
|
context = null;
|
|
2696
|
-
|
|
5703
|
+
pages = /* @__PURE__ */ new Map();
|
|
2697
5704
|
playwright = null;
|
|
2698
5705
|
config;
|
|
5706
|
+
/** Флаг: браузер подключён через CDP (не закрывать при close()). */
|
|
5707
|
+
connectedViaCDP = false;
|
|
2699
5708
|
/** Активные загрузки: downloadId -> PlaywrightDownload. */
|
|
2700
5709
|
activeDownloads = /* @__PURE__ */ new Map();
|
|
2701
5710
|
constructor(config) {
|
|
@@ -2708,62 +5717,108 @@ var BrowserManager = class {
|
|
|
2708
5717
|
async loadPlaywright() {
|
|
2709
5718
|
if (this.playwright) return this.playwright;
|
|
2710
5719
|
try {
|
|
2711
|
-
const
|
|
2712
|
-
|
|
5720
|
+
const pwExtra = await Promise.resolve().then(() => (init_index_esm(), index_esm_exports));
|
|
5721
|
+
const stealthModule = await Promise.resolve().then(() => __toESM(require_puppeteer_extra_plugin_stealth(), 1));
|
|
5722
|
+
const stealth = stealthModule.default ?? stealthModule;
|
|
5723
|
+
const chromium2 = pwExtra.chromium;
|
|
5724
|
+
chromium2.use(stealth());
|
|
5725
|
+
this.playwright = { chromium: chromium2 };
|
|
2713
5726
|
return this.playwright;
|
|
2714
5727
|
} catch {
|
|
2715
|
-
|
|
5728
|
+
try {
|
|
5729
|
+
const pw = await import("playwright");
|
|
5730
|
+
this.playwright = pw;
|
|
5731
|
+
return this.playwright;
|
|
5732
|
+
} catch {
|
|
5733
|
+
return null;
|
|
5734
|
+
}
|
|
2716
5735
|
}
|
|
2717
5736
|
}
|
|
2718
5737
|
/**
|
|
2719
5738
|
* Запускает браузер (lazy, при первом вызове).
|
|
2720
|
-
*
|
|
5739
|
+
* Логика для множественных агентов:
|
|
5740
|
+
* 1. Если cdpPort задан → пробуем connectOverCDP (подключиться к уже запущенному браузеру)
|
|
5741
|
+
* 2. Если connectOverCDP упал (браузер не запущен) → запускаем launchPersistentContext с --remote-debugging-port
|
|
5742
|
+
* 3. Если cdpPort НЕ задан → просто launchPersistentContext без CDP
|
|
2721
5743
|
* @throws Error если Playwright не установлен
|
|
2722
5744
|
*/
|
|
2723
5745
|
async launch() {
|
|
2724
|
-
if (this.browser) return;
|
|
5746
|
+
if (this.browser || this.context) return;
|
|
2725
5747
|
const pw = await this.loadPlaywright();
|
|
2726
5748
|
if (!pw) {
|
|
2727
5749
|
throw new Error(
|
|
2728
5750
|
"Playwright is not installed. Install it with: npm install playwright"
|
|
2729
5751
|
);
|
|
2730
5752
|
}
|
|
2731
|
-
this.
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
5753
|
+
if (this.config.cdpPort) {
|
|
5754
|
+
try {
|
|
5755
|
+
this.browser = await pw.chromium.connectOverCDP({
|
|
5756
|
+
endpointURL: `http://localhost:${this.config.cdpPort}`
|
|
5757
|
+
});
|
|
5758
|
+
this.connectedViaCDP = true;
|
|
5759
|
+
const contexts = this.browser.contexts();
|
|
5760
|
+
if (contexts.length > 0 && contexts[0]) {
|
|
5761
|
+
this.context = contexts[0];
|
|
5762
|
+
} else {
|
|
5763
|
+
const contextOptions = {
|
|
5764
|
+
acceptDownloads: this.config.acceptDownloads ?? true
|
|
5765
|
+
};
|
|
5766
|
+
if (this.config.downloadsPath) {
|
|
5767
|
+
contextOptions.downloadsPath = this.config.downloadsPath;
|
|
5768
|
+
}
|
|
5769
|
+
this.context = await this.browser.newContext(contextOptions);
|
|
5770
|
+
}
|
|
5771
|
+
return;
|
|
5772
|
+
} catch {
|
|
5773
|
+
}
|
|
5774
|
+
}
|
|
5775
|
+
const userDataDir = this.config.userDataDir ?? path.join(os.homedir(), ".vsl", "browser-profile");
|
|
5776
|
+
const persistentOptions = {
|
|
5777
|
+
headless: this.config.headless,
|
|
2735
5778
|
acceptDownloads: this.config.acceptDownloads ?? true
|
|
2736
5779
|
};
|
|
2737
5780
|
if (this.config.downloadsPath) {
|
|
2738
|
-
|
|
5781
|
+
persistentOptions.downloadsPath = this.config.downloadsPath;
|
|
5782
|
+
}
|
|
5783
|
+
if (this.config.cdpPort) {
|
|
5784
|
+
persistentOptions.args = [`--remote-debugging-port=${this.config.cdpPort}`];
|
|
2739
5785
|
}
|
|
2740
|
-
this.context = await
|
|
5786
|
+
this.context = await pw.chromium.launchPersistentContext(
|
|
5787
|
+
userDataDir,
|
|
5788
|
+
persistentOptions
|
|
5789
|
+
);
|
|
5790
|
+
this.browser = null;
|
|
2741
5791
|
}
|
|
2742
5792
|
/**
|
|
2743
|
-
* Возвращает страницу (создаёт новую из context, если нет).
|
|
5793
|
+
* Возвращает страницу для указанной сессии (создаёт новую из context, если нет).
|
|
5794
|
+
* @param sessionId - ID сессии для изоляции страниц
|
|
2744
5795
|
* @throws Error если браузер не запущен
|
|
2745
5796
|
*/
|
|
2746
|
-
async getPage() {
|
|
2747
|
-
if (!this.browser) {
|
|
5797
|
+
async getPage(sessionId) {
|
|
5798
|
+
if (!this.browser && !this.context) {
|
|
2748
5799
|
await this.launch();
|
|
2749
5800
|
}
|
|
2750
|
-
if (!this.
|
|
5801
|
+
if (!this.context) {
|
|
2751
5802
|
throw new Error("Browser not available");
|
|
2752
5803
|
}
|
|
2753
|
-
|
|
2754
|
-
|
|
5804
|
+
let page = this.pages.get(sessionId);
|
|
5805
|
+
if (!page) {
|
|
5806
|
+
page = await this.context.newPage();
|
|
5807
|
+
this.pages.set(sessionId, page);
|
|
2755
5808
|
this.context.on("download", (download) => {
|
|
2756
5809
|
const downloadId = `download_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
2757
5810
|
this.activeDownloads.set(downloadId, download);
|
|
2758
5811
|
});
|
|
2759
5812
|
}
|
|
2760
|
-
return
|
|
5813
|
+
return page;
|
|
2761
5814
|
}
|
|
2762
5815
|
/**
|
|
2763
5816
|
* Переходит по URL.
|
|
5817
|
+
* @param url - URL для навигации
|
|
5818
|
+
* @param sessionId - ID сессии для получения правильной страницы
|
|
2764
5819
|
*/
|
|
2765
|
-
async navigate(url) {
|
|
2766
|
-
const page = await this.getPage();
|
|
5820
|
+
async navigate(url, sessionId) {
|
|
5821
|
+
const page = await this.getPage(sessionId);
|
|
2767
5822
|
await page.goto(url, {
|
|
2768
5823
|
timeout: this.config.navigationTimeout,
|
|
2769
5824
|
waitUntil: "domcontentloaded"
|
|
@@ -2771,26 +5826,27 @@ var BrowserManager = class {
|
|
|
2771
5826
|
}
|
|
2772
5827
|
/**
|
|
2773
5828
|
* Получает HTML-контент текущей страницы.
|
|
5829
|
+
* @param sessionId - ID сессии
|
|
2774
5830
|
*/
|
|
2775
|
-
async getContent() {
|
|
2776
|
-
const page = await this.getPage();
|
|
5831
|
+
async getContent(sessionId) {
|
|
5832
|
+
const page = await this.getPage(sessionId);
|
|
2777
5833
|
return page.content();
|
|
2778
5834
|
}
|
|
2779
|
-
/**
|
|
2780
|
-
* Выполняет JavaScript в контексте страницы.
|
|
2781
|
-
*/
|
|
2782
5835
|
/**
|
|
2783
5836
|
* Возвращает все фреймы на странице (включая iframe).
|
|
5837
|
+
* @param sessionId - ID сессии
|
|
2784
5838
|
*/
|
|
2785
|
-
async getFrames() {
|
|
2786
|
-
const page = await this.getPage();
|
|
5839
|
+
async getFrames(sessionId) {
|
|
5840
|
+
const page = await this.getPage(sessionId);
|
|
2787
5841
|
return page.frames();
|
|
2788
5842
|
}
|
|
2789
5843
|
/**
|
|
2790
5844
|
* Находит фрейм по URL или имени.
|
|
5845
|
+
* @param urlOrName - URL или имя фрейма
|
|
5846
|
+
* @param sessionId - ID сессии
|
|
2791
5847
|
*/
|
|
2792
|
-
async getFrame(urlOrName) {
|
|
2793
|
-
const page = await this.getPage();
|
|
5848
|
+
async getFrame(urlOrName, sessionId) {
|
|
5849
|
+
const page = await this.getPage(sessionId);
|
|
2794
5850
|
return page.frame(urlOrName);
|
|
2795
5851
|
}
|
|
2796
5852
|
/**
|
|
@@ -2806,16 +5862,23 @@ var BrowserManager = class {
|
|
|
2806
5862
|
async locatorInFrame(frame, selector) {
|
|
2807
5863
|
return frame.locator(selector);
|
|
2808
5864
|
}
|
|
5865
|
+
/**
|
|
5866
|
+
* Выполняет JavaScript в контексте страницы.
|
|
5867
|
+
* @param fn - Функция или строка кода для выполнения
|
|
5868
|
+
* @param sessionId - ID сессии
|
|
5869
|
+
*/
|
|
2809
5870
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2810
|
-
async evaluate(fn, ...args) {
|
|
2811
|
-
const page = await this.getPage();
|
|
5871
|
+
async evaluate(fn, sessionId, ...args) {
|
|
5872
|
+
const page = await this.getPage(sessionId);
|
|
2812
5873
|
return page.evaluate(fn, ...args);
|
|
2813
5874
|
}
|
|
2814
5875
|
/**
|
|
2815
5876
|
* Делает скриншот страницы.
|
|
5877
|
+
* @param options - Опции скриншота
|
|
5878
|
+
* @param sessionId - ID сессии (опционально, по умолчанию 'default')
|
|
2816
5879
|
*/
|
|
2817
|
-
async screenshot(options) {
|
|
2818
|
-
const page = await this.getPage();
|
|
5880
|
+
async screenshot(options, sessionId) {
|
|
5881
|
+
const page = await this.getPage(sessionId ?? "default");
|
|
2819
5882
|
return page.screenshot({ type: "png", fullPage: options?.fullPage, clip: options?.clip });
|
|
2820
5883
|
}
|
|
2821
5884
|
/**
|
|
@@ -2930,10 +5993,11 @@ var BrowserManager = class {
|
|
|
2930
5993
|
* относительно CWD с path traversal проверкой.
|
|
2931
5994
|
* @param selector - CSS-селектор input[type=file] элемента
|
|
2932
5995
|
* @param filePaths - Массив путей к файлам (абсолютные или относительные)
|
|
5996
|
+
* @param sessionId - ID сессии
|
|
2933
5997
|
* @throws Error если путь выходит за допустимые границы или файл не существует
|
|
2934
5998
|
*/
|
|
2935
|
-
async uploadFile(selector, filePaths) {
|
|
2936
|
-
const page = await this.getPage();
|
|
5999
|
+
async uploadFile(selector, filePaths, sessionId) {
|
|
6000
|
+
const page = await this.getPage(sessionId);
|
|
2937
6001
|
if (filePaths.length === 0) {
|
|
2938
6002
|
throw new Error("filePaths must contain at least one file path");
|
|
2939
6003
|
}
|
|
@@ -2956,35 +6020,48 @@ var BrowserManager = class {
|
|
|
2956
6020
|
/**
|
|
2957
6021
|
* Ожидает появления file chooser dialog (для кастомных file picker'ов).
|
|
2958
6022
|
* Возвращает FileChooser, через который можно установить файлы.
|
|
6023
|
+
* @param sessionId - ID сессии
|
|
2959
6024
|
* @param timeout - Таймаут ожидания в мс (по умолчанию из config.downloadTimeout)
|
|
2960
6025
|
* @returns PlaywrightFileChooser для установки файлов
|
|
2961
6026
|
*/
|
|
2962
|
-
async waitForFileChooser(timeout) {
|
|
2963
|
-
const page = await this.getPage();
|
|
6027
|
+
async waitForFileChooser(sessionId, timeout) {
|
|
6028
|
+
const page = await this.getPage(sessionId);
|
|
2964
6029
|
const waitTimeout = timeout ?? this.config.downloadTimeout ?? 6e4;
|
|
2965
6030
|
const fileChooser = await page.waitForEvent("filechooser", { timeout: waitTimeout });
|
|
2966
6031
|
return fileChooser;
|
|
2967
6032
|
}
|
|
2968
6033
|
/**
|
|
2969
6034
|
* Закрывает браузер и очищает ресурсы.
|
|
6035
|
+
* Если браузер подключён через CDP — закрывает только context,
|
|
6036
|
+
* сам браузер не закрывается (сохраняет сессию пользователя).
|
|
2970
6037
|
*/
|
|
2971
6038
|
async close() {
|
|
2972
6039
|
this.activeDownloads.clear();
|
|
6040
|
+
for (const page of this.pages.values()) {
|
|
6041
|
+
try {
|
|
6042
|
+
await page.close();
|
|
6043
|
+
} catch (error) {
|
|
6044
|
+
console.error("[BrowserManager] Error closing page:", error);
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
6047
|
+
this.pages.clear();
|
|
2973
6048
|
try {
|
|
2974
6049
|
if (this.context) {
|
|
2975
6050
|
await this.context.close();
|
|
2976
6051
|
this.context = null;
|
|
2977
6052
|
}
|
|
2978
|
-
if (this.browser) {
|
|
6053
|
+
if (this.browser && !this.connectedViaCDP) {
|
|
2979
6054
|
await this.browser.close();
|
|
2980
6055
|
this.browser = null;
|
|
6056
|
+
} else if (this.connectedViaCDP) {
|
|
6057
|
+
this.browser = null;
|
|
2981
6058
|
}
|
|
2982
6059
|
} catch (error) {
|
|
2983
6060
|
console.error("[BrowserManager] Error during close():", error);
|
|
2984
6061
|
this.context = null;
|
|
2985
6062
|
this.browser = null;
|
|
2986
6063
|
}
|
|
2987
|
-
this.
|
|
6064
|
+
this.connectedViaCDP = false;
|
|
2988
6065
|
}
|
|
2989
6066
|
};
|
|
2990
6067
|
|
|
@@ -3197,6 +6274,8 @@ var SessionManager = class {
|
|
|
3197
6274
|
sessionTtlMs;
|
|
3198
6275
|
defaultSessionId;
|
|
3199
6276
|
cleanupTimer = null;
|
|
6277
|
+
/** Singleton BrowserManager — один браузер на все сессии. */
|
|
6278
|
+
browserManager = null;
|
|
3200
6279
|
constructor(browserConfig, options) {
|
|
3201
6280
|
this.browserConfig = browserConfig;
|
|
3202
6281
|
this.cleanupIntervalMs = options?.cleanupIntervalMs ?? 6e4;
|
|
@@ -3211,16 +6290,27 @@ var SessionManager = class {
|
|
|
3211
6290
|
getDefaultSessionId() {
|
|
3212
6291
|
return this.defaultSessionId;
|
|
3213
6292
|
}
|
|
6293
|
+
/**
|
|
6294
|
+
* Возвращает singleton BrowserManager (создаёт при первом вызове).
|
|
6295
|
+
* Все сессии делят один браузер — это стандартный паттерн Playwright
|
|
6296
|
+
* для multi-tenant scenarios.
|
|
6297
|
+
*/
|
|
6298
|
+
getBrowserManager() {
|
|
6299
|
+
if (!this.browserManager) {
|
|
6300
|
+
this.browserManager = new BrowserManager(this.browserConfig);
|
|
6301
|
+
}
|
|
6302
|
+
return this.browserManager;
|
|
6303
|
+
}
|
|
3214
6304
|
/**
|
|
3215
6305
|
* Получает или создаёт сессию по sessionId.
|
|
3216
|
-
* Если сессия не существует — создаёт новую с
|
|
6306
|
+
* Если сессия не существует — создаёт новую с ServerSession.
|
|
6307
|
+
* Все сессии делят ОДИН BrowserManager (singleton).
|
|
3217
6308
|
*/
|
|
3218
6309
|
getSession(sessionId) {
|
|
3219
6310
|
const normalizedId = sessionId || this.defaultSessionId;
|
|
3220
6311
|
if (!this.sessions.has(normalizedId)) {
|
|
3221
6312
|
const context2 = {
|
|
3222
6313
|
sessionId: normalizedId,
|
|
3223
|
-
browser: new BrowserManager(this.browserConfig),
|
|
3224
6314
|
session: new ServerSession(),
|
|
3225
6315
|
createdAt: Date.now(),
|
|
3226
6316
|
lastAccessedAt: Date.now()
|
|
@@ -3238,29 +6328,29 @@ var SessionManager = class {
|
|
|
3238
6328
|
return this.sessions.has(sessionId || this.defaultSessionId);
|
|
3239
6329
|
}
|
|
3240
6330
|
/**
|
|
3241
|
-
* Закрывает сессию и освобождает ресурсы (
|
|
6331
|
+
* Закрывает сессию и освобождает ресурсы (cache).
|
|
6332
|
+
* Браузер НЕ закрывается — он общий для всех сессий.
|
|
3242
6333
|
*/
|
|
3243
6334
|
async closeSession(sessionId) {
|
|
3244
6335
|
const normalizedId = sessionId || this.defaultSessionId;
|
|
3245
6336
|
const context = this.sessions.get(normalizedId);
|
|
3246
6337
|
if (context) {
|
|
3247
|
-
await context.browser.close();
|
|
3248
6338
|
this.sessions.delete(normalizedId);
|
|
3249
6339
|
}
|
|
3250
6340
|
}
|
|
3251
6341
|
/**
|
|
3252
|
-
* Закрывает все сессии (при shutdown сервера).
|
|
6342
|
+
* Закрывает все сессии и браузер (при shutdown сервера).
|
|
3253
6343
|
*/
|
|
3254
6344
|
async closeAll() {
|
|
3255
6345
|
this.stopCleanup();
|
|
3256
|
-
|
|
6346
|
+
if (this.browserManager) {
|
|
3257
6347
|
try {
|
|
3258
|
-
await
|
|
6348
|
+
await this.browserManager.close();
|
|
3259
6349
|
} catch (error) {
|
|
3260
|
-
console.error("[SessionManager] Error closing browser
|
|
6350
|
+
console.error("[SessionManager] Error closing browser:", error);
|
|
3261
6351
|
}
|
|
3262
|
-
|
|
3263
|
-
|
|
6352
|
+
this.browserManager = null;
|
|
6353
|
+
}
|
|
3264
6354
|
this.sessions.clear();
|
|
3265
6355
|
}
|
|
3266
6356
|
/**
|
|
@@ -3319,7 +6409,7 @@ var SessionManager = class {
|
|
|
3319
6409
|
};
|
|
3320
6410
|
|
|
3321
6411
|
// src/version.ts
|
|
3322
|
-
var VSL_MCP_SERVER_VERSION = "1.
|
|
6412
|
+
var VSL_MCP_SERVER_VERSION = "1.3.1";
|
|
3323
6413
|
|
|
3324
6414
|
// src/index.ts
|
|
3325
6415
|
async function main() {
|
|
@@ -3368,4 +6458,52 @@ main().catch((error) => {
|
|
|
3368
6458
|
console.error("[VSL MCP Server] Fatal error:", error);
|
|
3369
6459
|
process.exit(1);
|
|
3370
6460
|
});
|
|
6461
|
+
/*! Bundled license information:
|
|
6462
|
+
|
|
6463
|
+
playwright-extra/dist/index.esm.js:
|
|
6464
|
+
(*!
|
|
6465
|
+
* playwright-extra v4.3.5 by berstend
|
|
6466
|
+
* https://github.com/berstend/puppeteer-extra/tree/master/packages/playwright-extra#readme
|
|
6467
|
+
* @license MIT
|
|
6468
|
+
*)
|
|
6469
|
+
|
|
6470
|
+
for-in/index.js:
|
|
6471
|
+
(*!
|
|
6472
|
+
* for-in <https://github.com/jonschlinkert/for-in>
|
|
6473
|
+
*
|
|
6474
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
6475
|
+
* Released under the MIT License.
|
|
6476
|
+
*)
|
|
6477
|
+
|
|
6478
|
+
for-own/index.js:
|
|
6479
|
+
(*!
|
|
6480
|
+
* for-own <https://github.com/jonschlinkert/for-own>
|
|
6481
|
+
*
|
|
6482
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
6483
|
+
* Released under the MIT License.
|
|
6484
|
+
*)
|
|
6485
|
+
|
|
6486
|
+
is-buffer/index.js:
|
|
6487
|
+
(*!
|
|
6488
|
+
* Determine if an object is a Buffer
|
|
6489
|
+
*
|
|
6490
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
6491
|
+
* @license MIT
|
|
6492
|
+
*)
|
|
6493
|
+
|
|
6494
|
+
merge-deep/index.js:
|
|
6495
|
+
(*!
|
|
6496
|
+
* merge-deep <https://github.com/jonschlinkert/merge-deep>
|
|
6497
|
+
*
|
|
6498
|
+
* Copyright (c) 2014-2015, Jon Schlinkert.
|
|
6499
|
+
* Licensed under the MIT License.
|
|
6500
|
+
*)
|
|
6501
|
+
|
|
6502
|
+
puppeteer-extra-plugin/dist/index.esm.js:
|
|
6503
|
+
(*!
|
|
6504
|
+
* puppeteer-extra-plugin v3.2.2 by berstend
|
|
6505
|
+
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin
|
|
6506
|
+
* @license MIT
|
|
6507
|
+
*)
|
|
6508
|
+
*/
|
|
3371
6509
|
//# sourceMappingURL=index.js.map
|