@thinkingos/vsl-mcp-server 1.4.1 → 1.4.3
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 +289 -70
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,40 +1,115 @@
|
|
|
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
|
+
});
|
|
6
104
|
|
|
7
105
|
// src/config/loader.ts
|
|
106
|
+
var loader_exports = {};
|
|
107
|
+
__export(loader_exports, {
|
|
108
|
+
loadConfig: () => loadConfig
|
|
109
|
+
});
|
|
8
110
|
import { readFileSync, existsSync } from "fs";
|
|
9
111
|
import { homedir } from "os";
|
|
10
112
|
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
113
|
function loadConfig() {
|
|
39
114
|
const fileConfig = loadConfigFile();
|
|
40
115
|
const apiKeys = {
|
|
@@ -57,6 +132,7 @@ function loadConfig() {
|
|
|
57
132
|
proxy: parseProxyConfig(fileConfig)
|
|
58
133
|
};
|
|
59
134
|
const humanization = parseHumanizationConfig(fileConfig);
|
|
135
|
+
const domStabilization = parseDomStabilizationConfig(fileConfig);
|
|
60
136
|
return {
|
|
61
137
|
vision: {
|
|
62
138
|
provider,
|
|
@@ -66,6 +142,7 @@ function loadConfig() {
|
|
|
66
142
|
},
|
|
67
143
|
browser,
|
|
68
144
|
humanization,
|
|
145
|
+
domStabilization,
|
|
69
146
|
apiKeys
|
|
70
147
|
};
|
|
71
148
|
}
|
|
@@ -87,6 +164,16 @@ function parseHumanizationConfig(fileConfig) {
|
|
|
87
164
|
const sites = fileHumanization?.sites ?? DEFAULT_HUMANIZATION_CONFIG.sites;
|
|
88
165
|
return { enabled, internalHosts, sites };
|
|
89
166
|
}
|
|
167
|
+
function parseDomStabilizationConfig(fileConfig) {
|
|
168
|
+
const fileDomStab = fileConfig.domStabilization;
|
|
169
|
+
const enabled = process.env.VSL_DOM_STABILIZATION_ENABLED ? process.env.VSL_DOM_STABILIZATION_ENABLED === "true" : fileDomStab?.enabled ?? DEFAULT_DOM_STABILIZATION_CONFIG.enabled;
|
|
170
|
+
const timeout = process.env.VSL_DOM_STABILIZATION_TIMEOUT ? parseInt(process.env.VSL_DOM_STABILIZATION_TIMEOUT, 10) : fileDomStab?.timeout ?? DEFAULT_DOM_STABILIZATION_CONFIG.timeout;
|
|
171
|
+
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;
|
|
172
|
+
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;
|
|
173
|
+
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;
|
|
174
|
+
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;
|
|
175
|
+
return { enabled, timeout, stablePeriod, pollInterval, waitForNetworkIdle, networkIdleTimeout };
|
|
176
|
+
}
|
|
90
177
|
function loadConfigFile() {
|
|
91
178
|
if (!existsSync(DEFAULT_CONFIG_PATH)) {
|
|
92
179
|
return {};
|
|
@@ -99,6 +186,45 @@ function loadConfigFile() {
|
|
|
99
186
|
return {};
|
|
100
187
|
}
|
|
101
188
|
}
|
|
189
|
+
var DEFAULT_CONFIG_PATH, DEFAULT_VISION_MODELS, DEFAULT_BROWSER_CONFIG, DEFAULT_HUMANIZATION_CONFIG;
|
|
190
|
+
var init_loader = __esm({
|
|
191
|
+
"src/config/loader.ts"() {
|
|
192
|
+
"use strict";
|
|
193
|
+
init_domStabilization();
|
|
194
|
+
DEFAULT_CONFIG_PATH = join(homedir(), ".vsl", "config.json");
|
|
195
|
+
DEFAULT_VISION_MODELS = {
|
|
196
|
+
openai: "gpt-6-luna",
|
|
197
|
+
anthropic: "claude-haiku-4-5",
|
|
198
|
+
custom: ""
|
|
199
|
+
// Пользователь должен указать модель для custom провайдера
|
|
200
|
+
};
|
|
201
|
+
DEFAULT_BROWSER_CONFIG = {
|
|
202
|
+
headless: true,
|
|
203
|
+
navigationTimeout: 3e4,
|
|
204
|
+
renderTimeout: 1e4,
|
|
205
|
+
downloadsPath: join(homedir(), ".vsl", "downloads"),
|
|
206
|
+
downloadTimeout: 6e4,
|
|
207
|
+
acceptDownloads: true,
|
|
208
|
+
userDataDir: void 0,
|
|
209
|
+
// Дефолт ~/.vsl/browser-profile применяется в manager.ts
|
|
210
|
+
cdpPort: 9222
|
|
211
|
+
// Дефолтный CDP port для подключения множественных агентов
|
|
212
|
+
};
|
|
213
|
+
DEFAULT_HUMANIZATION_CONFIG = {
|
|
214
|
+
enabled: true,
|
|
215
|
+
// Включено по умолчанию (решение пользователя от 2026-10-10)
|
|
216
|
+
internalHosts: [],
|
|
217
|
+
// Список внутренних хостов для автоотключения
|
|
218
|
+
sites: {}
|
|
219
|
+
// Пер-сайт переопределения
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// src/index.ts
|
|
225
|
+
init_loader();
|
|
226
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
227
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
102
228
|
|
|
103
229
|
// src/tools/index.ts
|
|
104
230
|
import {
|
|
@@ -1162,6 +1288,9 @@ async function handleClearCache(session) {
|
|
|
1162
1288
|
}
|
|
1163
1289
|
}
|
|
1164
1290
|
|
|
1291
|
+
// src/humanization/runtime.ts
|
|
1292
|
+
init_loader();
|
|
1293
|
+
|
|
1165
1294
|
// src/config/humanizationConfig.ts
|
|
1166
1295
|
var EFFECTIVE_DEFAULT = {
|
|
1167
1296
|
enabled: true,
|
|
@@ -1610,6 +1739,7 @@ async function performHumanClick(mouse, from, target, options = {}) {
|
|
|
1610
1739
|
}
|
|
1611
1740
|
|
|
1612
1741
|
// src/tools/executeAction.ts
|
|
1742
|
+
init_domStabilization();
|
|
1613
1743
|
var VALID_ACTIONS = [
|
|
1614
1744
|
"click",
|
|
1615
1745
|
"type",
|
|
@@ -1945,7 +2075,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
1945
2075
|
y: (clickViewport?.height ?? 768) * (0.3 + Math.random() * 0.4)
|
|
1946
2076
|
};
|
|
1947
2077
|
await performHumanClick(page.mouse, clickStart, pickPointInRect(clickBb), { waiter: page });
|
|
1948
|
-
await page
|
|
2078
|
+
await waitForDomStabilization(page);
|
|
1949
2079
|
break;
|
|
1950
2080
|
}
|
|
1951
2081
|
try {
|
|
@@ -1998,7 +2128,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
1998
2128
|
}
|
|
1999
2129
|
console.log(`[VSL] Positional mapping succeeded: clicked element at (${centerX}, ${centerY}) for ${args.target_id}`);
|
|
2000
2130
|
}
|
|
2001
|
-
await page
|
|
2131
|
+
await waitForDomStabilization(page);
|
|
2002
2132
|
break;
|
|
2003
2133
|
}
|
|
2004
2134
|
case "fill":
|
|
@@ -2062,7 +2192,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
2062
2192
|
await browser.evaluate(({ dx: dx2, dy: dy2 }) => {
|
|
2063
2193
|
window.scrollBy(dx2, dy2);
|
|
2064
2194
|
}, sessionId, { dx, dy });
|
|
2065
|
-
await page
|
|
2195
|
+
await waitForDomStabilization(page);
|
|
2066
2196
|
}
|
|
2067
2197
|
const prevScroll = session.getScrollContext();
|
|
2068
2198
|
let newScroll = null;
|
|
@@ -2210,7 +2340,7 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
2210
2340
|
await page.waitForTimeout(pressTiming.sampleDelayMs());
|
|
2211
2341
|
}
|
|
2212
2342
|
await page.keyboard.press(args.value, { delay: 0 });
|
|
2213
|
-
await page
|
|
2343
|
+
await waitForDomStabilization(page);
|
|
2214
2344
|
break;
|
|
2215
2345
|
}
|
|
2216
2346
|
case "download": {
|
|
@@ -2655,20 +2785,12 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
2655
2785
|
if (navigationOccurred || contextDestroyed) {
|
|
2656
2786
|
try {
|
|
2657
2787
|
await page.waitForLoadState("domcontentloaded", { timeout: 5e3 });
|
|
2658
|
-
await page
|
|
2788
|
+
await waitForDomStabilization(page, { waitForNetworkIdle: true, timeout: 2e3 });
|
|
2659
2789
|
} catch (waitError) {
|
|
2660
2790
|
console.warn("[vsl_execute_action] Navigation detected but waitForLoadState failed:", waitError);
|
|
2661
2791
|
}
|
|
2662
2792
|
} 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
|
-
}
|
|
2793
|
+
await waitForDomStabilization(page);
|
|
2672
2794
|
}
|
|
2673
2795
|
const currentUrl = urlAfterAction || urlBeforeAction;
|
|
2674
2796
|
if ((navigationOccurred || contextDestroyed) && result.data) {
|
|
@@ -2754,27 +2876,81 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2754
2876
|
}
|
|
2755
2877
|
const idMap = session?.getIdMap() ?? /* @__PURE__ */ new Map();
|
|
2756
2878
|
const resolvedId = idMap.get(args.element_id) || args.element_id;
|
|
2757
|
-
|
|
2758
|
-
let
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2879
|
+
let targetFrame = null;
|
|
2880
|
+
let selectorId = resolvedId;
|
|
2881
|
+
const frameMatch = resolvedId.match(/^iframe_(\d+):(.+)$/);
|
|
2882
|
+
if (frameMatch) {
|
|
2883
|
+
const frameIndex = parseInt(frameMatch[1], 10);
|
|
2884
|
+
const frameUrl = iframeFrameRegistry.get(frameIndex);
|
|
2885
|
+
if (!frameUrl) {
|
|
2886
|
+
return {
|
|
2887
|
+
content: [{ type: "text", text: `Error: Frame iframe_${frameIndex} not found in registry. Call vsl_get_snapshot first to populate the frame registry.` }],
|
|
2888
|
+
isError: true,
|
|
2889
|
+
possible_causes: ["vsl_get_snapshot was not called before vsl_get_visual", "Frame registry was cleared"],
|
|
2890
|
+
suggestions: ["Call vsl_get_snapshot to populate iframe registry", "Ensure the page contains iframes"]
|
|
2891
|
+
};
|
|
2892
|
+
}
|
|
2893
|
+
const frames = await browser.getFrames(sessionId);
|
|
2894
|
+
targetFrame = frames.find((f) => {
|
|
2895
|
+
const u = f.url();
|
|
2896
|
+
return u === frameUrl || u.includes(frameUrl) || frameUrl.includes(u);
|
|
2897
|
+
}) || null;
|
|
2898
|
+
if (!targetFrame) {
|
|
2899
|
+
return {
|
|
2900
|
+
content: [{ type: "text", text: `Error: Frame with URL "${frameUrl}" not found in browser. The iframe may have been removed or navigated away.` }],
|
|
2901
|
+
isError: true,
|
|
2902
|
+
possible_causes: ["Iframe was removed from DOM", "Iframe navigated to a different URL", "Cross-origin iframe blocked access"],
|
|
2903
|
+
suggestions: ["Call vsl_get_snapshot to refresh frame registry", "Verify the iframe still exists on the page"]
|
|
2904
|
+
};
|
|
2905
|
+
}
|
|
2906
|
+
const innerId = frameMatch[2];
|
|
2907
|
+
selectorId = idMap.get(innerId) || innerId;
|
|
2908
|
+
}
|
|
2909
|
+
const selector = `[data-vsl-id="${selectorId}"], #${selectorId}, [id="${selectorId}"]`;
|
|
2910
|
+
let elementExists;
|
|
2911
|
+
if (targetFrame) {
|
|
2912
|
+
elementExists = await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
2913
|
+
return document.querySelector(sel) !== null;
|
|
2914
|
+
}, sessionId, selector);
|
|
2915
|
+
} else {
|
|
2763
2916
|
elementExists = await browser.evaluate((sel) => {
|
|
2764
2917
|
return document.querySelector(sel) !== null;
|
|
2765
2918
|
}, sessionId, selector);
|
|
2766
2919
|
}
|
|
2920
|
+
if (!elementExists && args.auto_refresh && session) {
|
|
2921
|
+
await handleGetSnapshot({}, browser, session, { downloadsPath: "" }, sessionId);
|
|
2922
|
+
if (targetFrame) {
|
|
2923
|
+
elementExists = await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
2924
|
+
return document.querySelector(sel) !== null;
|
|
2925
|
+
}, sessionId, selector);
|
|
2926
|
+
} else {
|
|
2927
|
+
elementExists = await browser.evaluate((sel) => {
|
|
2928
|
+
return document.querySelector(sel) !== null;
|
|
2929
|
+
}, sessionId, selector);
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2767
2932
|
if (!elementExists) {
|
|
2768
|
-
const
|
|
2933
|
+
const isIframeElement = targetFrame !== null;
|
|
2934
|
+
const elementType = isIframeElement ? "iframe element" : "main page element";
|
|
2935
|
+
const suggestions = isIframeElement ? [
|
|
2936
|
+
"Call vsl_get_snapshot to refresh DOM IDs inside iframe",
|
|
2937
|
+
"Use auto_refresh: true parameter to automatically refresh before search",
|
|
2938
|
+
"Iframe content may have changed \u2014 elements are re-indexed after snapshot",
|
|
2939
|
+
"Verify the iframe has fully loaded before requesting visual"
|
|
2940
|
+
] : [
|
|
2769
2941
|
"Call vsl_get_snapshot to refresh DOM IDs",
|
|
2770
2942
|
"Use auto_refresh: true parameter to automatically refresh before search",
|
|
2771
2943
|
"Element may have been removed from DOM after navigation or action",
|
|
2772
2944
|
"DOM structure changed \u2014 IDs are index-based and may have shifted"
|
|
2773
2945
|
];
|
|
2774
2946
|
return {
|
|
2775
|
-
content: [{ type: "text", text: `Error:
|
|
2947
|
+
content: [{ type: "text", text: `Error: ${elementType.charAt(0).toUpperCase() + elementType.slice(1)} not found: ${args.element_id}. ${isIframeElement ? "Note: vsl_get_visual works with IDs from vsl_get_snapshot (browser DOM inside iframe)." : "Note: vsl_get_visual works with IDs from vsl_get_snapshot (browser DOM), not vsl_read_page (semantic IDs)."}` }],
|
|
2776
2948
|
isError: true,
|
|
2777
|
-
possible_causes: [
|
|
2949
|
+
possible_causes: isIframeElement ? [
|
|
2950
|
+
"Snapshot is outdated \u2014 iframe DOM changed after navigation or action",
|
|
2951
|
+
"Element was removed from iframe DOM",
|
|
2952
|
+
"Iframe has not fully loaded yet"
|
|
2953
|
+
] : [
|
|
2778
2954
|
"Snapshot is outdated \u2014 DOM changed after navigation or action",
|
|
2779
2955
|
"Element was removed from DOM",
|
|
2780
2956
|
"Using semantic ID from vsl_read_page instead of browser DOM ID from vsl_get_snapshot"
|
|
@@ -2787,7 +2963,19 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2787
2963
|
let scrolled = false;
|
|
2788
2964
|
let scrollOffset;
|
|
2789
2965
|
if (autoScroll) {
|
|
2790
|
-
const scrollResult = await browser.
|
|
2966
|
+
const scrollResult = targetFrame ? await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
2967
|
+
const el = document.querySelector(sel);
|
|
2968
|
+
if (!el) return { needsScroll: false, scrolled: false };
|
|
2969
|
+
const rect2 = el.getBoundingClientRect();
|
|
2970
|
+
const viewportWidth = window.innerWidth;
|
|
2971
|
+
const viewportHeight = window.innerHeight;
|
|
2972
|
+
const isVisible2 = rect2.top >= 0 && rect2.left >= 0 && rect2.bottom <= viewportHeight && rect2.right <= viewportWidth;
|
|
2973
|
+
if (isVisible2) {
|
|
2974
|
+
return { needsScroll: false, scrolled: false };
|
|
2975
|
+
}
|
|
2976
|
+
el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
|
|
2977
|
+
return { needsScroll: true, scrolled: true };
|
|
2978
|
+
}, sessionId, selector) : await browser.evaluate((sel) => {
|
|
2791
2979
|
const el = document.querySelector(sel);
|
|
2792
2980
|
if (!el) return { needsScroll: false, scrolled: false };
|
|
2793
2981
|
const rect2 = el.getBoundingClientRect();
|
|
@@ -2802,21 +2990,46 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2802
2990
|
}, sessionId, selector);
|
|
2803
2991
|
if (scrollResult.scrolled) {
|
|
2804
2992
|
scrolled = true;
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2993
|
+
if (targetFrame) {
|
|
2994
|
+
await browser.evaluateInFrame(targetFrame, () => {
|
|
2995
|
+
return new Promise((resolve) => {
|
|
2808
2996
|
requestAnimationFrame(() => {
|
|
2809
|
-
|
|
2997
|
+
requestAnimationFrame(() => {
|
|
2998
|
+
resolve();
|
|
2999
|
+
});
|
|
2810
3000
|
});
|
|
2811
3001
|
});
|
|
2812
|
-
});
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
}
|
|
3002
|
+
}, sessionId);
|
|
3003
|
+
scrollOffset = await browser.evaluateInFrame(targetFrame, () => {
|
|
3004
|
+
return { x: window.scrollX, y: window.scrollY };
|
|
3005
|
+
}, sessionId);
|
|
3006
|
+
} else {
|
|
3007
|
+
await browser.evaluate(() => {
|
|
3008
|
+
return new Promise((resolve) => {
|
|
3009
|
+
requestAnimationFrame(() => {
|
|
3010
|
+
requestAnimationFrame(() => {
|
|
3011
|
+
resolve();
|
|
3012
|
+
});
|
|
3013
|
+
});
|
|
3014
|
+
});
|
|
3015
|
+
}, sessionId);
|
|
3016
|
+
scrollOffset = await browser.evaluate(() => {
|
|
3017
|
+
return { x: window.scrollX, y: window.scrollY };
|
|
3018
|
+
}, sessionId);
|
|
3019
|
+
}
|
|
2817
3020
|
}
|
|
2818
3021
|
}
|
|
2819
|
-
const rect = await browser.
|
|
3022
|
+
const rect = targetFrame ? await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
3023
|
+
const el = document.querySelector(sel);
|
|
3024
|
+
if (!el) return null;
|
|
3025
|
+
const r = el.getBoundingClientRect();
|
|
3026
|
+
return {
|
|
3027
|
+
x: r.x + window.scrollX,
|
|
3028
|
+
y: r.y + window.scrollY,
|
|
3029
|
+
width: r.width,
|
|
3030
|
+
height: r.height
|
|
3031
|
+
};
|
|
3032
|
+
}, sessionId, selector) : await browser.evaluate((sel) => {
|
|
2820
3033
|
const el = document.querySelector(sel);
|
|
2821
3034
|
if (!el) return null;
|
|
2822
3035
|
const r = el.getBoundingClientRect();
|
|
@@ -2833,10 +3046,16 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2833
3046
|
isError: true
|
|
2834
3047
|
};
|
|
2835
3048
|
}
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
3049
|
+
let screenshotBuffer;
|
|
3050
|
+
if (targetFrame) {
|
|
3051
|
+
const locator = targetFrame.locator(selector);
|
|
3052
|
+
screenshotBuffer = await locator.screenshot({ type: "png" });
|
|
3053
|
+
} else {
|
|
3054
|
+
screenshotBuffer = await page.screenshot({
|
|
3055
|
+
type: "png",
|
|
3056
|
+
clip: rect
|
|
3057
|
+
});
|
|
3058
|
+
}
|
|
2840
3059
|
const base64Image = screenshotBuffer.toString("base64");
|
|
2841
3060
|
const metricsData = { type: "element", element_id: args.element_id, width: rect.width, height: rect.height };
|
|
2842
3061
|
const result = {
|
|
@@ -3719,7 +3938,7 @@ var VSL_TOOLS = [
|
|
|
3719
3938
|
},
|
|
3720
3939
|
{
|
|
3721
3940
|
name: "vsl_get_visual",
|
|
3722
|
-
description: "Get a visual fragment (screenshot) of an element in base64 WebP format. Use for elements that are hard to classify by text alone (icons, charts, custom widgets). Returns {mediaType:image/webp, data:base64data}. Example: {element_id: img_5}. Parameter auto_refresh=true automatically refreshes the snapshot before searching for the element. IMPORTANT: works only with IDs from vsl_get_snapshot (browser DOM). Does NOT work with IDs from vsl_read_page (semantic IDs) \u2014 use vsl_get_snapshot to get compatible IDs.",
|
|
3941
|
+
description: "Get a visual fragment (screenshot) of an element in base64 WebP format. Use for elements that are hard to classify by text alone (icons, charts, custom widgets). Returns {mediaType:image/webp, data:base64data}. Example: {element_id: img_5}. Supports iframe elements: use composite ID format iframe_N:element_Y (e.g. iframe_0:btn_1) to screenshot elements inside iframes. Parameter auto_refresh=true automatically refreshes the snapshot before searching for the element. IMPORTANT: works only with IDs from vsl_get_snapshot (browser DOM). Does NOT work with IDs from vsl_read_page (semantic IDs) \u2014 use vsl_get_snapshot to get compatible IDs.",
|
|
3723
3942
|
inputSchema: {
|
|
3724
3943
|
type: "object",
|
|
3725
3944
|
properties: {
|
|
@@ -4868,7 +5087,7 @@ var SessionManager = class {
|
|
|
4868
5087
|
};
|
|
4869
5088
|
|
|
4870
5089
|
// src/version.ts
|
|
4871
|
-
var VSL_MCP_SERVER_VERSION = "1.4.
|
|
5090
|
+
var VSL_MCP_SERVER_VERSION = "1.4.3";
|
|
4872
5091
|
|
|
4873
5092
|
// src/index.ts
|
|
4874
5093
|
async function main() {
|