@thinkingos/vsl-mcp-server 1.4.2 → 1.4.4
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 +383 -64
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,40 +1,229 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
2
11
|
|
|
3
|
-
// src/
|
|
4
|
-
|
|
5
|
-
|
|
12
|
+
// src/utils/domStabilization.ts
|
|
13
|
+
async function waitForDomStable(target, options = {}) {
|
|
14
|
+
const opts = { ...DEFAULT_DOM_STABILIZATION_OPTIONS, ...options };
|
|
15
|
+
await target.evaluate(
|
|
16
|
+
({ stablePeriod, pollInterval, timeout }) => {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
let lastMutationTime = Date.now();
|
|
19
|
+
let isStable = false;
|
|
20
|
+
const observer = new MutationObserver(() => {
|
|
21
|
+
lastMutationTime = Date.now();
|
|
22
|
+
isStable = false;
|
|
23
|
+
});
|
|
24
|
+
observer.observe(document.body || document.documentElement, {
|
|
25
|
+
childList: true,
|
|
26
|
+
subtree: true,
|
|
27
|
+
attributes: true,
|
|
28
|
+
characterData: true
|
|
29
|
+
});
|
|
30
|
+
const checkInterval = setInterval(() => {
|
|
31
|
+
const timeSinceLastMutation = Date.now() - lastMutationTime;
|
|
32
|
+
if (timeSinceLastMutation >= stablePeriod) {
|
|
33
|
+
isStable = true;
|
|
34
|
+
clearInterval(checkInterval);
|
|
35
|
+
observer.disconnect();
|
|
36
|
+
resolve();
|
|
37
|
+
}
|
|
38
|
+
}, pollInterval);
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
if (!isStable) {
|
|
41
|
+
clearInterval(checkInterval);
|
|
42
|
+
observer.disconnect();
|
|
43
|
+
resolve();
|
|
44
|
+
}
|
|
45
|
+
}, timeout);
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
stablePeriod: opts.stablePeriod,
|
|
50
|
+
pollInterval: opts.pollInterval,
|
|
51
|
+
timeout: opts.timeout
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function configToOptions(config) {
|
|
56
|
+
return {
|
|
57
|
+
timeout: config.timeout,
|
|
58
|
+
stablePeriod: config.stablePeriod,
|
|
59
|
+
pollInterval: config.pollInterval,
|
|
60
|
+
waitForNetworkIdle: config.waitForNetworkIdle,
|
|
61
|
+
networkIdleTimeout: config.networkIdleTimeout
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async function waitForDomStabilization(target, overrides = {}) {
|
|
65
|
+
let config = DEFAULT_DOM_STABILIZATION_CONFIG;
|
|
66
|
+
try {
|
|
67
|
+
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_loader(), loader_exports));
|
|
68
|
+
const loadedConfig = loadConfig2();
|
|
69
|
+
if (loadedConfig.domStabilization) {
|
|
70
|
+
config = loadedConfig.domStabilization;
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
if (!config.enabled) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (typeof target.evaluate !== "function") {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const options = { ...configToOptions(config), ...overrides };
|
|
81
|
+
await waitForDomStable(target, options);
|
|
82
|
+
}
|
|
83
|
+
var DEFAULT_DOM_STABILIZATION_OPTIONS, DEFAULT_DOM_STABILIZATION_CONFIG;
|
|
84
|
+
var init_domStabilization = __esm({
|
|
85
|
+
"src/utils/domStabilization.ts"() {
|
|
86
|
+
"use strict";
|
|
87
|
+
DEFAULT_DOM_STABILIZATION_OPTIONS = {
|
|
88
|
+
timeout: 1e3,
|
|
89
|
+
stablePeriod: 100,
|
|
90
|
+
pollInterval: 50,
|
|
91
|
+
waitForNetworkIdle: false,
|
|
92
|
+
networkIdleTimeout: 500
|
|
93
|
+
};
|
|
94
|
+
DEFAULT_DOM_STABILIZATION_CONFIG = {
|
|
95
|
+
enabled: true,
|
|
96
|
+
timeout: 1e3,
|
|
97
|
+
stablePeriod: 100,
|
|
98
|
+
pollInterval: 50,
|
|
99
|
+
waitForNetworkIdle: false,
|
|
100
|
+
networkIdleTimeout: 500
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// src/browser/browserBinary.ts
|
|
106
|
+
import { spawn } from "child_process";
|
|
107
|
+
import { existsSync } from "fs";
|
|
108
|
+
import { createRequire } from "module";
|
|
109
|
+
import path from "path";
|
|
110
|
+
function parseMissingBrowserError(error) {
|
|
111
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
|
112
|
+
const match = EXECUTABLE_MISSING_RE.exec(message);
|
|
113
|
+
const rawPath = match?.[1];
|
|
114
|
+
if (!rawPath) return null;
|
|
115
|
+
const executablePath = rawPath.trim();
|
|
116
|
+
for (const segment of executablePath.split(/[\\/]/)) {
|
|
117
|
+
const revisionMatch = REVISION_DIR_RE.exec(segment);
|
|
118
|
+
const artifact = revisionMatch?.[1];
|
|
119
|
+
if (!artifact) continue;
|
|
120
|
+
const browser = ARTIFACT_TO_BROWSER[artifact];
|
|
121
|
+
if (!browser) continue;
|
|
122
|
+
return { executablePath, browser, revisionDir: segment };
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
function resolvePlaywrightCliPath() {
|
|
127
|
+
const resolveFromHere = createRequire(import.meta.url);
|
|
128
|
+
for (const pkg of ["playwright", "playwright-core"]) {
|
|
129
|
+
try {
|
|
130
|
+
const entry = resolveFromHere.resolve(pkg);
|
|
131
|
+
const cliPath = path.join(path.dirname(entry), "cli.js");
|
|
132
|
+
if (existsSync(cliPath)) return cliPath;
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
function formatMissingBrowserError(info, options = {}) {
|
|
139
|
+
const command = options.cliPath ? `node "${options.cliPath}" install ${info.browser}` : `npx playwright install ${info.browser}`;
|
|
140
|
+
const lines = [
|
|
141
|
+
`Playwright browser binary is missing: ${info.executablePath}`,
|
|
142
|
+
`Required revision: ${info.revisionDir}. The shared Playwright browser cache was cleared (OS cache cleanup / manual removal) or Playwright was updated.`
|
|
143
|
+
];
|
|
144
|
+
if (options.autoInstallDisabled) {
|
|
145
|
+
lines.push(
|
|
146
|
+
"Automatic download is disabled (browser.autoInstallBrowser=false / VSL_BROWSER_AUTO_INSTALL=false)."
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
if (options.reason) {
|
|
150
|
+
lines.push(`Automatic download did not help: ${options.reason}`);
|
|
151
|
+
}
|
|
152
|
+
lines.push(`Fix: ${command}`);
|
|
153
|
+
return lines.join("\n");
|
|
154
|
+
}
|
|
155
|
+
async function installBrowser(options) {
|
|
156
|
+
const { browser, cliPath, timeoutMs } = options;
|
|
157
|
+
const key = `${cliPath}::${browser}`;
|
|
158
|
+
const inFlight = inFlightInstalls.get(key);
|
|
159
|
+
if (inFlight) return inFlight;
|
|
160
|
+
const promise = runInstall(cliPath, browser, timeoutMs).finally(() => {
|
|
161
|
+
inFlightInstalls.delete(key);
|
|
162
|
+
});
|
|
163
|
+
inFlightInstalls.set(key, promise);
|
|
164
|
+
return promise;
|
|
165
|
+
}
|
|
166
|
+
function runInstall(cliPath, browser, timeoutMs) {
|
|
167
|
+
return new Promise((resolve) => {
|
|
168
|
+
const child = spawn(process.execPath, [cliPath, "install", browser], {
|
|
169
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
170
|
+
});
|
|
171
|
+
let output = "";
|
|
172
|
+
let timedOut = false;
|
|
173
|
+
const collect = (chunk) => {
|
|
174
|
+
output += chunk.toString();
|
|
175
|
+
if (output.length > MAX_INSTALL_OUTPUT) {
|
|
176
|
+
output = output.slice(-MAX_INSTALL_OUTPUT);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const timer = setTimeout(() => {
|
|
180
|
+
timedOut = true;
|
|
181
|
+
child.kill("SIGTERM");
|
|
182
|
+
}, timeoutMs);
|
|
183
|
+
child.stdout?.on("data", collect);
|
|
184
|
+
child.stderr?.on("data", collect);
|
|
185
|
+
child.on("error", (error) => {
|
|
186
|
+
clearTimeout(timer);
|
|
187
|
+
resolve({ success: false, output, error: error.message });
|
|
188
|
+
});
|
|
189
|
+
child.on("close", (code) => {
|
|
190
|
+
clearTimeout(timer);
|
|
191
|
+
if (timedOut) {
|
|
192
|
+
resolve({ success: false, output, error: `timed out after ${timeoutMs}ms` });
|
|
193
|
+
} else if (code === 0) {
|
|
194
|
+
resolve({ success: true, output });
|
|
195
|
+
} else {
|
|
196
|
+
resolve({ success: false, output, error: `install exited with code ${code}` });
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
var DEFAULT_BROWSER_INSTALL_TIMEOUT_MS, MAX_INSTALL_OUTPUT, EXECUTABLE_MISSING_RE, REVISION_DIR_RE, ARTIFACT_TO_BROWSER, inFlightInstalls;
|
|
202
|
+
var init_browserBinary = __esm({
|
|
203
|
+
"src/browser/browserBinary.ts"() {
|
|
204
|
+
"use strict";
|
|
205
|
+
DEFAULT_BROWSER_INSTALL_TIMEOUT_MS = 3e5;
|
|
206
|
+
MAX_INSTALL_OUTPUT = 8e3;
|
|
207
|
+
EXECUTABLE_MISSING_RE = /Executable doesn't exist at\s+(.+)/;
|
|
208
|
+
REVISION_DIR_RE = /^([a-z_]+)-(\d+)$/;
|
|
209
|
+
ARTIFACT_TO_BROWSER = {
|
|
210
|
+
chromium: "chromium",
|
|
211
|
+
chromium_headless_shell: "chromium",
|
|
212
|
+
firefox: "firefox",
|
|
213
|
+
webkit: "webkit"
|
|
214
|
+
};
|
|
215
|
+
inFlightInstalls = /* @__PURE__ */ new Map();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
6
218
|
|
|
7
219
|
// src/config/loader.ts
|
|
8
|
-
|
|
220
|
+
var loader_exports = {};
|
|
221
|
+
__export(loader_exports, {
|
|
222
|
+
loadConfig: () => loadConfig
|
|
223
|
+
});
|
|
224
|
+
import { readFileSync, existsSync as existsSync2 } from "fs";
|
|
9
225
|
import { homedir } from "os";
|
|
10
226
|
import { join } from "path";
|
|
11
|
-
var DEFAULT_CONFIG_PATH = join(homedir(), ".vsl", "config.json");
|
|
12
|
-
var DEFAULT_VISION_MODELS = {
|
|
13
|
-
openai: "gpt-6-luna",
|
|
14
|
-
anthropic: "claude-haiku-4-5",
|
|
15
|
-
custom: ""
|
|
16
|
-
// Пользователь должен указать модель для custom провайдера
|
|
17
|
-
};
|
|
18
|
-
var DEFAULT_BROWSER_CONFIG = {
|
|
19
|
-
headless: true,
|
|
20
|
-
navigationTimeout: 3e4,
|
|
21
|
-
renderTimeout: 1e4,
|
|
22
|
-
downloadsPath: join(homedir(), ".vsl", "downloads"),
|
|
23
|
-
downloadTimeout: 6e4,
|
|
24
|
-
acceptDownloads: true,
|
|
25
|
-
userDataDir: void 0,
|
|
26
|
-
// Дефолт ~/.vsl/browser-profile применяется в manager.ts
|
|
27
|
-
cdpPort: 9222
|
|
28
|
-
// Дефолтный CDP port для подключения множественных агентов
|
|
29
|
-
};
|
|
30
|
-
var DEFAULT_HUMANIZATION_CONFIG = {
|
|
31
|
-
enabled: true,
|
|
32
|
-
// Включено по умолчанию (решение пользователя от 2026-10-10)
|
|
33
|
-
internalHosts: [],
|
|
34
|
-
// Список внутренних хостов для автоотключения
|
|
35
|
-
sites: {}
|
|
36
|
-
// Пер-сайт переопределения
|
|
37
|
-
};
|
|
38
227
|
function loadConfig() {
|
|
39
228
|
const fileConfig = loadConfigFile();
|
|
40
229
|
const apiKeys = {
|
|
@@ -54,9 +243,12 @@ function loadConfig() {
|
|
|
54
243
|
acceptDownloads: process.env.VSL_ACCEPT_DOWNLOADS ? process.env.VSL_ACCEPT_DOWNLOADS === "true" : fileConfig.browser?.acceptDownloads ?? DEFAULT_BROWSER_CONFIG.acceptDownloads,
|
|
55
244
|
userDataDir: process.env.VSL_USER_DATA_DIR || fileConfig.browser?.userDataDir || DEFAULT_BROWSER_CONFIG.userDataDir,
|
|
56
245
|
cdpPort: process.env.VSL_CDP_PORT ? parseInt(process.env.VSL_CDP_PORT, 10) : fileConfig.browser?.cdpPort ?? DEFAULT_BROWSER_CONFIG.cdpPort,
|
|
246
|
+
autoInstallBrowser: process.env.VSL_BROWSER_AUTO_INSTALL ? process.env.VSL_BROWSER_AUTO_INSTALL === "true" : fileConfig.browser?.autoInstallBrowser ?? DEFAULT_BROWSER_CONFIG.autoInstallBrowser,
|
|
247
|
+
browserInstallTimeout: process.env.VSL_BROWSER_INSTALL_TIMEOUT ? parseInt(process.env.VSL_BROWSER_INSTALL_TIMEOUT, 10) : fileConfig.browser?.browserInstallTimeout ?? DEFAULT_BROWSER_CONFIG.browserInstallTimeout,
|
|
57
248
|
proxy: parseProxyConfig(fileConfig)
|
|
58
249
|
};
|
|
59
250
|
const humanization = parseHumanizationConfig(fileConfig);
|
|
251
|
+
const domStabilization = parseDomStabilizationConfig(fileConfig);
|
|
60
252
|
return {
|
|
61
253
|
vision: {
|
|
62
254
|
provider,
|
|
@@ -66,6 +258,7 @@ function loadConfig() {
|
|
|
66
258
|
},
|
|
67
259
|
browser,
|
|
68
260
|
humanization,
|
|
261
|
+
domStabilization,
|
|
69
262
|
apiKeys
|
|
70
263
|
};
|
|
71
264
|
}
|
|
@@ -87,8 +280,18 @@ function parseHumanizationConfig(fileConfig) {
|
|
|
87
280
|
const sites = fileHumanization?.sites ?? DEFAULT_HUMANIZATION_CONFIG.sites;
|
|
88
281
|
return { enabled, internalHosts, sites };
|
|
89
282
|
}
|
|
283
|
+
function parseDomStabilizationConfig(fileConfig) {
|
|
284
|
+
const fileDomStab = fileConfig.domStabilization;
|
|
285
|
+
const enabled = process.env.VSL_DOM_STABILIZATION_ENABLED ? process.env.VSL_DOM_STABILIZATION_ENABLED === "true" : fileDomStab?.enabled ?? DEFAULT_DOM_STABILIZATION_CONFIG.enabled;
|
|
286
|
+
const timeout = process.env.VSL_DOM_STABILIZATION_TIMEOUT ? parseInt(process.env.VSL_DOM_STABILIZATION_TIMEOUT, 10) : fileDomStab?.timeout ?? DEFAULT_DOM_STABILIZATION_CONFIG.timeout;
|
|
287
|
+
const stablePeriod = process.env.VSL_DOM_STABILIZATION_STABLE_PERIOD ? parseInt(process.env.VSL_DOM_STABILIZATION_STABLE_PERIOD, 10) : fileDomStab?.stablePeriod ?? DEFAULT_DOM_STABILIZATION_CONFIG.stablePeriod;
|
|
288
|
+
const pollInterval = process.env.VSL_DOM_STABILIZATION_POLL_INTERVAL ? parseInt(process.env.VSL_DOM_STABILIZATION_POLL_INTERVAL, 10) : fileDomStab?.pollInterval ?? DEFAULT_DOM_STABILIZATION_CONFIG.pollInterval;
|
|
289
|
+
const waitForNetworkIdle = process.env.VSL_DOM_STABILIZATION_WAIT_NETWORK_IDLE ? process.env.VSL_DOM_STABILIZATION_WAIT_NETWORK_IDLE === "true" : fileDomStab?.waitForNetworkIdle ?? DEFAULT_DOM_STABILIZATION_CONFIG.waitForNetworkIdle;
|
|
290
|
+
const networkIdleTimeout = process.env.VSL_DOM_STABILIZATION_NETWORK_IDLE_TIMEOUT ? parseInt(process.env.VSL_DOM_STABILIZATION_NETWORK_IDLE_TIMEOUT, 10) : fileDomStab?.networkIdleTimeout ?? DEFAULT_DOM_STABILIZATION_CONFIG.networkIdleTimeout;
|
|
291
|
+
return { enabled, timeout, stablePeriod, pollInterval, waitForNetworkIdle, networkIdleTimeout };
|
|
292
|
+
}
|
|
90
293
|
function loadConfigFile() {
|
|
91
|
-
if (!
|
|
294
|
+
if (!existsSync2(DEFAULT_CONFIG_PATH)) {
|
|
92
295
|
return {};
|
|
93
296
|
}
|
|
94
297
|
try {
|
|
@@ -99,6 +302,49 @@ function loadConfigFile() {
|
|
|
99
302
|
return {};
|
|
100
303
|
}
|
|
101
304
|
}
|
|
305
|
+
var DEFAULT_CONFIG_PATH, DEFAULT_VISION_MODELS, DEFAULT_BROWSER_CONFIG, DEFAULT_HUMANIZATION_CONFIG;
|
|
306
|
+
var init_loader = __esm({
|
|
307
|
+
"src/config/loader.ts"() {
|
|
308
|
+
"use strict";
|
|
309
|
+
init_domStabilization();
|
|
310
|
+
init_browserBinary();
|
|
311
|
+
DEFAULT_CONFIG_PATH = join(homedir(), ".vsl", "config.json");
|
|
312
|
+
DEFAULT_VISION_MODELS = {
|
|
313
|
+
openai: "gpt-6-luna",
|
|
314
|
+
anthropic: "claude-haiku-4-5",
|
|
315
|
+
custom: ""
|
|
316
|
+
// Пользователь должен указать модель для custom провайдера
|
|
317
|
+
};
|
|
318
|
+
DEFAULT_BROWSER_CONFIG = {
|
|
319
|
+
headless: true,
|
|
320
|
+
navigationTimeout: 3e4,
|
|
321
|
+
renderTimeout: 1e4,
|
|
322
|
+
downloadsPath: join(homedir(), ".vsl", "downloads"),
|
|
323
|
+
downloadTimeout: 6e4,
|
|
324
|
+
acceptDownloads: true,
|
|
325
|
+
userDataDir: void 0,
|
|
326
|
+
// Дефолт ~/.vsl/browser-profile применяется в manager.ts
|
|
327
|
+
cdpPort: 9222,
|
|
328
|
+
// Дефолтный CDP port для подключения множественных агентов
|
|
329
|
+
autoInstallBrowser: true,
|
|
330
|
+
// Self-heal: скачивать браузер, если кэш Playwright очищен
|
|
331
|
+
browserInstallTimeout: DEFAULT_BROWSER_INSTALL_TIMEOUT_MS
|
|
332
|
+
};
|
|
333
|
+
DEFAULT_HUMANIZATION_CONFIG = {
|
|
334
|
+
enabled: true,
|
|
335
|
+
// Включено по умолчанию (решение пользователя от 2026-10-10)
|
|
336
|
+
internalHosts: [],
|
|
337
|
+
// Список внутренних хостов для автоотключения
|
|
338
|
+
sites: {}
|
|
339
|
+
// Пер-сайт переопределения
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// src/index.ts
|
|
345
|
+
init_loader();
|
|
346
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
347
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
102
348
|
|
|
103
349
|
// src/tools/index.ts
|
|
104
350
|
import {
|
|
@@ -706,14 +952,14 @@ function extractDomTreeInBrowser() {
|
|
|
706
952
|
function collectVisibleChildren(parent, parentPath) {
|
|
707
953
|
const result = [];
|
|
708
954
|
Array.from(parent.children).forEach((child, index) => {
|
|
709
|
-
const
|
|
955
|
+
const path3 = [...parentPath, index];
|
|
710
956
|
const tag = child.tagName.toLowerCase();
|
|
711
957
|
if (NON_RENDERABLE_TAGS.has(tag) || isDisplayNone(child)) {
|
|
712
958
|
return;
|
|
713
959
|
}
|
|
714
960
|
const rect = toRect(child.getBoundingClientRect());
|
|
715
961
|
if (isVisibilityHidden(child) || hasZeroBox(rect)) {
|
|
716
|
-
result.push(...collectVisibleChildren(child,
|
|
962
|
+
result.push(...collectVisibleChildren(child, path3));
|
|
717
963
|
return;
|
|
718
964
|
}
|
|
719
965
|
const attributes = extractAttributes(child);
|
|
@@ -724,12 +970,12 @@ function extractDomTreeInBrowser() {
|
|
|
724
970
|
if (css.opacity === "0" && css.pointerEvents === "none") {
|
|
725
971
|
return;
|
|
726
972
|
}
|
|
727
|
-
const children = collectVisibleChildren(child,
|
|
728
|
-
const vslId = `${tag}_${
|
|
973
|
+
const children = collectVisibleChildren(child, path3);
|
|
974
|
+
const vslId = `${tag}_${path3.join("_")}`;
|
|
729
975
|
child.setAttribute("data-vsl-id", vslId);
|
|
730
976
|
result.push({
|
|
731
977
|
tag,
|
|
732
|
-
indexPath:
|
|
978
|
+
indexPath: path3,
|
|
733
979
|
rect,
|
|
734
980
|
text: ownText(child) || null,
|
|
735
981
|
attributes,
|
|
@@ -1162,6 +1408,9 @@ async function handleClearCache(session) {
|
|
|
1162
1408
|
}
|
|
1163
1409
|
}
|
|
1164
1410
|
|
|
1411
|
+
// src/humanization/runtime.ts
|
|
1412
|
+
init_loader();
|
|
1413
|
+
|
|
1165
1414
|
// src/config/humanizationConfig.ts
|
|
1166
1415
|
var EFFECTIVE_DEFAULT = {
|
|
1167
1416
|
enabled: true,
|
|
@@ -1610,6 +1859,7 @@ async function performHumanClick(mouse, from, target, options = {}) {
|
|
|
1610
1859
|
}
|
|
1611
1860
|
|
|
1612
1861
|
// src/tools/executeAction.ts
|
|
1862
|
+
init_domStabilization();
|
|
1613
1863
|
var VALID_ACTIONS = [
|
|
1614
1864
|
"click",
|
|
1615
1865
|
"type",
|
|
@@ -1945,7 +2195,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
1945
2195
|
y: (clickViewport?.height ?? 768) * (0.3 + Math.random() * 0.4)
|
|
1946
2196
|
};
|
|
1947
2197
|
await performHumanClick(page.mouse, clickStart, pickPointInRect(clickBb), { waiter: page });
|
|
1948
|
-
await page
|
|
2198
|
+
await waitForDomStabilization(page);
|
|
1949
2199
|
break;
|
|
1950
2200
|
}
|
|
1951
2201
|
try {
|
|
@@ -1998,7 +2248,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
1998
2248
|
}
|
|
1999
2249
|
console.log(`[VSL] Positional mapping succeeded: clicked element at (${centerX}, ${centerY}) for ${args.target_id}`);
|
|
2000
2250
|
}
|
|
2001
|
-
await page
|
|
2251
|
+
await waitForDomStabilization(page);
|
|
2002
2252
|
break;
|
|
2003
2253
|
}
|
|
2004
2254
|
case "fill":
|
|
@@ -2062,7 +2312,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
2062
2312
|
await browser.evaluate(({ dx: dx2, dy: dy2 }) => {
|
|
2063
2313
|
window.scrollBy(dx2, dy2);
|
|
2064
2314
|
}, sessionId, { dx, dy });
|
|
2065
|
-
await page
|
|
2315
|
+
await waitForDomStabilization(page);
|
|
2066
2316
|
}
|
|
2067
2317
|
const prevScroll = session.getScrollContext();
|
|
2068
2318
|
let newScroll = null;
|
|
@@ -2210,7 +2460,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
2210
2460
|
await page.waitForTimeout(pressTiming.sampleDelayMs());
|
|
2211
2461
|
}
|
|
2212
2462
|
await page.keyboard.press(args.value, { delay: 0 });
|
|
2213
|
-
await page
|
|
2463
|
+
await waitForDomStabilization(page);
|
|
2214
2464
|
break;
|
|
2215
2465
|
}
|
|
2216
2466
|
case "download": {
|
|
@@ -2655,20 +2905,12 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
2655
2905
|
if (navigationOccurred || contextDestroyed) {
|
|
2656
2906
|
try {
|
|
2657
2907
|
await page.waitForLoadState("domcontentloaded", { timeout: 5e3 });
|
|
2658
|
-
await page
|
|
2908
|
+
await waitForDomStabilization(page, { waitForNetworkIdle: true, timeout: 2e3 });
|
|
2659
2909
|
} catch (waitError) {
|
|
2660
2910
|
console.warn("[vsl_execute_action] Navigation detected but waitForLoadState failed:", waitError);
|
|
2661
2911
|
}
|
|
2662
2912
|
} else {
|
|
2663
|
-
|
|
2664
|
-
await browser.evaluate(() => {
|
|
2665
|
-
return new Promise((resolve) => {
|
|
2666
|
-
setTimeout(resolve, 100);
|
|
2667
|
-
});
|
|
2668
|
-
}, sessionId);
|
|
2669
|
-
} catch (evalError) {
|
|
2670
|
-
console.warn("[vsl_execute_action] DOM stabilization evaluate failed:", evalError);
|
|
2671
|
-
}
|
|
2913
|
+
await waitForDomStabilization(page);
|
|
2672
2914
|
}
|
|
2673
2915
|
const currentUrl = urlAfterAction || urlBeforeAction;
|
|
2674
2916
|
if ((navigationOccurred || contextDestroyed) && result.data) {
|
|
@@ -4088,7 +4330,7 @@ function registerResources(server, _config, sessionManager) {
|
|
|
4088
4330
|
}
|
|
4089
4331
|
|
|
4090
4332
|
// src/browser/manager.ts
|
|
4091
|
-
import
|
|
4333
|
+
import path2 from "path";
|
|
4092
4334
|
import os from "os";
|
|
4093
4335
|
|
|
4094
4336
|
// src/browser/challengeResolver.ts
|
|
@@ -4228,6 +4470,7 @@ async function resolveChallenge(page, targetUrl, options = {}) {
|
|
|
4228
4470
|
}
|
|
4229
4471
|
|
|
4230
4472
|
// src/browser/manager.ts
|
|
4473
|
+
init_browserBinary();
|
|
4231
4474
|
var BrowserManager = class {
|
|
4232
4475
|
browser = null;
|
|
4233
4476
|
context = null;
|
|
@@ -4313,7 +4556,7 @@ var BrowserManager = class {
|
|
|
4313
4556
|
} catch {
|
|
4314
4557
|
}
|
|
4315
4558
|
}
|
|
4316
|
-
const userDataDir = this.config.userDataDir ??
|
|
4559
|
+
const userDataDir = this.config.userDataDir ?? path2.join(os.homedir(), ".vsl", "browser-profile");
|
|
4317
4560
|
const persistentOptions = {
|
|
4318
4561
|
headless: this.config.headless,
|
|
4319
4562
|
acceptDownloads: this.config.acceptDownloads ?? true
|
|
@@ -4333,12 +4576,88 @@ var BrowserManager = class {
|
|
|
4333
4576
|
launchArgs.push(`--remote-debugging-port=${this.config.cdpPort}`);
|
|
4334
4577
|
}
|
|
4335
4578
|
persistentOptions.args = launchArgs;
|
|
4336
|
-
this.context = await
|
|
4579
|
+
this.context = await this.launchPersistentContextWithRecovery(
|
|
4580
|
+
pw,
|
|
4337
4581
|
userDataDir,
|
|
4338
4582
|
persistentOptions
|
|
4339
4583
|
);
|
|
4340
4584
|
this.browser = null;
|
|
4341
4585
|
}
|
|
4586
|
+
/**
|
|
4587
|
+
* Запускает persistent context с восстановлением отсутствующего бинарника браузера.
|
|
4588
|
+
*
|
|
4589
|
+
* Playwright сам решает, какой артефакт использовать (chromium или chromium-headless-shell
|
|
4590
|
+
* для headless), поэтому наличие бинарника не проверяется заранее по угаданному пути:
|
|
4591
|
+
* авторитетный путь берётся из ошибки Playwright, затем браузер скачивается и запуск
|
|
4592
|
+
* повторяется ровно один раз.
|
|
4593
|
+
*
|
|
4594
|
+
* @throws Error с короткой инструкцией, если восстановление отключено или не помогло
|
|
4595
|
+
*/
|
|
4596
|
+
async launchPersistentContextWithRecovery(pw, userDataDir, options) {
|
|
4597
|
+
try {
|
|
4598
|
+
return await pw.chromium.launchPersistentContext(userDataDir, options);
|
|
4599
|
+
} catch (error) {
|
|
4600
|
+
const missing = parseMissingBrowserError(error);
|
|
4601
|
+
if (!missing) throw error;
|
|
4602
|
+
await this.ensureBrowserBinary(missing);
|
|
4603
|
+
try {
|
|
4604
|
+
return await pw.chromium.launchPersistentContext(userDataDir, options);
|
|
4605
|
+
} catch (retryError) {
|
|
4606
|
+
const stillMissing = parseMissingBrowserError(retryError);
|
|
4607
|
+
if (!stillMissing) throw retryError;
|
|
4608
|
+
throw new Error(
|
|
4609
|
+
formatMissingBrowserError(stillMissing, {
|
|
4610
|
+
cliPath: resolvePlaywrightCliPath(),
|
|
4611
|
+
reason: "the binary is still missing after a successful download"
|
|
4612
|
+
})
|
|
4613
|
+
);
|
|
4614
|
+
}
|
|
4615
|
+
}
|
|
4616
|
+
}
|
|
4617
|
+
/**
|
|
4618
|
+
* Гарантирует наличие бинарника браузера: скачивает его (self-heal) либо бросает
|
|
4619
|
+
* actionable ошибку, если автоустановка отключена конфигурацией или не удалась.
|
|
4620
|
+
*/
|
|
4621
|
+
async ensureBrowserBinary(missing) {
|
|
4622
|
+
const cliPath = resolvePlaywrightCliPath();
|
|
4623
|
+
if (this.config.autoInstallBrowser === false) {
|
|
4624
|
+
throw new Error(
|
|
4625
|
+
formatMissingBrowserError(missing, { cliPath, autoInstallDisabled: true })
|
|
4626
|
+
);
|
|
4627
|
+
}
|
|
4628
|
+
console.error(
|
|
4629
|
+
`[VSL MCP Server] Playwright browser binary is missing (${missing.revisionDir}) \u2014 downloading "${missing.browser}" automatically...`
|
|
4630
|
+
);
|
|
4631
|
+
const result = await this.installBrowserBinary(missing);
|
|
4632
|
+
if (!result.success) {
|
|
4633
|
+
throw new Error(
|
|
4634
|
+
formatMissingBrowserError(missing, {
|
|
4635
|
+
cliPath,
|
|
4636
|
+
reason: result.error ?? "unknown install error"
|
|
4637
|
+
})
|
|
4638
|
+
);
|
|
4639
|
+
}
|
|
4640
|
+
console.error(`[VSL MCP Server] Browser "${missing.browser}" is ready (self-heal completed).`);
|
|
4641
|
+
}
|
|
4642
|
+
/**
|
|
4643
|
+
* Шов для автоматической загрузки браузера (self-heal).
|
|
4644
|
+
* Юнит-тесты переопределяют его через jest.spyOn, чтобы не скачивать браузеры реально.
|
|
4645
|
+
*/
|
|
4646
|
+
async installBrowserBinary(info) {
|
|
4647
|
+
const cliPath = resolvePlaywrightCliPath();
|
|
4648
|
+
if (!cliPath) {
|
|
4649
|
+
return {
|
|
4650
|
+
success: false,
|
|
4651
|
+
output: "",
|
|
4652
|
+
error: "playwright cli.js not found next to the installed playwright package"
|
|
4653
|
+
};
|
|
4654
|
+
}
|
|
4655
|
+
return installBrowser({
|
|
4656
|
+
browser: info.browser,
|
|
4657
|
+
cliPath,
|
|
4658
|
+
timeoutMs: this.config.browserInstallTimeout ?? DEFAULT_BROWSER_INSTALL_TIMEOUT_MS
|
|
4659
|
+
});
|
|
4660
|
+
}
|
|
4342
4661
|
/**
|
|
4343
4662
|
* Возвращает страницу для указанной сессии (создаёт новую из context, если нет).
|
|
4344
4663
|
* @param sessionId - ID сессии для изоляции страниц
|
|
@@ -4473,13 +4792,13 @@ var BrowserManager = class {
|
|
|
4473
4792
|
path: null
|
|
4474
4793
|
};
|
|
4475
4794
|
}
|
|
4476
|
-
const
|
|
4795
|
+
const path3 = await download.path();
|
|
4477
4796
|
return {
|
|
4478
4797
|
downloadId,
|
|
4479
4798
|
filename: download.suggestedFilename(),
|
|
4480
4799
|
url: download.url(),
|
|
4481
4800
|
status: "completed",
|
|
4482
|
-
path:
|
|
4801
|
+
path: path3
|
|
4483
4802
|
};
|
|
4484
4803
|
} catch {
|
|
4485
4804
|
return {
|
|
@@ -4516,9 +4835,9 @@ var BrowserManager = class {
|
|
|
4516
4835
|
await download.saveAs(savePath);
|
|
4517
4836
|
} else {
|
|
4518
4837
|
const downloadsPath = this.config.downloadsPath ?? os.tmpdir();
|
|
4519
|
-
const resolvedBase =
|
|
4520
|
-
const resolvedSave =
|
|
4521
|
-
if (!resolvedSave.startsWith(resolvedBase +
|
|
4838
|
+
const resolvedBase = path2.resolve(downloadsPath.replace(/^~/, os.homedir()));
|
|
4839
|
+
const resolvedSave = path2.resolve(resolvedBase, savePath);
|
|
4840
|
+
if (!resolvedSave.startsWith(resolvedBase + path2.sep) && resolvedSave !== resolvedBase) {
|
|
4522
4841
|
throw new Error(`Path traversal detected: save_path '${savePath}' escapes downloads directory '${resolvedBase}'`);
|
|
4523
4842
|
}
|
|
4524
4843
|
await download.saveAs(resolvedSave);
|
|
@@ -4559,13 +4878,13 @@ var BrowserManager = class {
|
|
|
4559
4878
|
}
|
|
4560
4879
|
const resolvedPaths = [];
|
|
4561
4880
|
for (const filePath of filePaths) {
|
|
4562
|
-
const isAbsolute =
|
|
4881
|
+
const isAbsolute = path2.isAbsolute(filePath);
|
|
4563
4882
|
if (isAbsolute) {
|
|
4564
4883
|
resolvedPaths.push(filePath);
|
|
4565
4884
|
} else {
|
|
4566
|
-
const resolved =
|
|
4567
|
-
const cwd =
|
|
4568
|
-
if (!resolved.startsWith(cwd +
|
|
4885
|
+
const resolved = path2.resolve(process.cwd(), filePath);
|
|
4886
|
+
const cwd = path2.resolve(process.cwd());
|
|
4887
|
+
if (!resolved.startsWith(cwd + path2.sep) && resolved !== cwd) {
|
|
4569
4888
|
throw new Error(`Path traversal detected: file path '${filePath}' resolves outside working directory '${cwd}'`);
|
|
4570
4889
|
}
|
|
4571
4890
|
resolvedPaths.push(resolved);
|
|
@@ -4965,7 +5284,7 @@ var SessionManager = class {
|
|
|
4965
5284
|
};
|
|
4966
5285
|
|
|
4967
5286
|
// src/version.ts
|
|
4968
|
-
var VSL_MCP_SERVER_VERSION = "1.4.
|
|
5287
|
+
var VSL_MCP_SERVER_VERSION = "1.4.4";
|
|
4969
5288
|
|
|
4970
5289
|
// src/index.ts
|
|
4971
5290
|
async function main() {
|