@thinkingos/vsl-mcp-server 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +123 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2754,27 +2754,81 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2754
2754
|
}
|
|
2755
2755
|
const idMap = session?.getIdMap() ?? /* @__PURE__ */ new Map();
|
|
2756
2756
|
const resolvedId = idMap.get(args.element_id) || args.element_id;
|
|
2757
|
-
|
|
2758
|
-
let
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2757
|
+
let targetFrame = null;
|
|
2758
|
+
let selectorId = resolvedId;
|
|
2759
|
+
const frameMatch = resolvedId.match(/^iframe_(\d+):(.+)$/);
|
|
2760
|
+
if (frameMatch) {
|
|
2761
|
+
const frameIndex = parseInt(frameMatch[1], 10);
|
|
2762
|
+
const frameUrl = iframeFrameRegistry.get(frameIndex);
|
|
2763
|
+
if (!frameUrl) {
|
|
2764
|
+
return {
|
|
2765
|
+
content: [{ type: "text", text: `Error: Frame iframe_${frameIndex} not found in registry. Call vsl_get_snapshot first to populate the frame registry.` }],
|
|
2766
|
+
isError: true,
|
|
2767
|
+
possible_causes: ["vsl_get_snapshot was not called before vsl_get_visual", "Frame registry was cleared"],
|
|
2768
|
+
suggestions: ["Call vsl_get_snapshot to populate iframe registry", "Ensure the page contains iframes"]
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
const frames = await browser.getFrames(sessionId);
|
|
2772
|
+
targetFrame = frames.find((f) => {
|
|
2773
|
+
const u = f.url();
|
|
2774
|
+
return u === frameUrl || u.includes(frameUrl) || frameUrl.includes(u);
|
|
2775
|
+
}) || null;
|
|
2776
|
+
if (!targetFrame) {
|
|
2777
|
+
return {
|
|
2778
|
+
content: [{ type: "text", text: `Error: Frame with URL "${frameUrl}" not found in browser. The iframe may have been removed or navigated away.` }],
|
|
2779
|
+
isError: true,
|
|
2780
|
+
possible_causes: ["Iframe was removed from DOM", "Iframe navigated to a different URL", "Cross-origin iframe blocked access"],
|
|
2781
|
+
suggestions: ["Call vsl_get_snapshot to refresh frame registry", "Verify the iframe still exists on the page"]
|
|
2782
|
+
};
|
|
2783
|
+
}
|
|
2784
|
+
const innerId = frameMatch[2];
|
|
2785
|
+
selectorId = idMap.get(innerId) || innerId;
|
|
2786
|
+
}
|
|
2787
|
+
const selector = `[data-vsl-id="${selectorId}"], #${selectorId}, [id="${selectorId}"]`;
|
|
2788
|
+
let elementExists;
|
|
2789
|
+
if (targetFrame) {
|
|
2790
|
+
elementExists = await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
2791
|
+
return document.querySelector(sel) !== null;
|
|
2792
|
+
}, sessionId, selector);
|
|
2793
|
+
} else {
|
|
2763
2794
|
elementExists = await browser.evaluate((sel) => {
|
|
2764
2795
|
return document.querySelector(sel) !== null;
|
|
2765
2796
|
}, sessionId, selector);
|
|
2766
2797
|
}
|
|
2798
|
+
if (!elementExists && args.auto_refresh && session) {
|
|
2799
|
+
await handleGetSnapshot({}, browser, session, { downloadsPath: "" }, sessionId);
|
|
2800
|
+
if (targetFrame) {
|
|
2801
|
+
elementExists = await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
2802
|
+
return document.querySelector(sel) !== null;
|
|
2803
|
+
}, sessionId, selector);
|
|
2804
|
+
} else {
|
|
2805
|
+
elementExists = await browser.evaluate((sel) => {
|
|
2806
|
+
return document.querySelector(sel) !== null;
|
|
2807
|
+
}, sessionId, selector);
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2767
2810
|
if (!elementExists) {
|
|
2768
|
-
const
|
|
2811
|
+
const isIframeElement = targetFrame !== null;
|
|
2812
|
+
const elementType = isIframeElement ? "iframe element" : "main page element";
|
|
2813
|
+
const suggestions = isIframeElement ? [
|
|
2814
|
+
"Call vsl_get_snapshot to refresh DOM IDs inside iframe",
|
|
2815
|
+
"Use auto_refresh: true parameter to automatically refresh before search",
|
|
2816
|
+
"Iframe content may have changed \u2014 elements are re-indexed after snapshot",
|
|
2817
|
+
"Verify the iframe has fully loaded before requesting visual"
|
|
2818
|
+
] : [
|
|
2769
2819
|
"Call vsl_get_snapshot to refresh DOM IDs",
|
|
2770
2820
|
"Use auto_refresh: true parameter to automatically refresh before search",
|
|
2771
2821
|
"Element may have been removed from DOM after navigation or action",
|
|
2772
2822
|
"DOM structure changed \u2014 IDs are index-based and may have shifted"
|
|
2773
2823
|
];
|
|
2774
2824
|
return {
|
|
2775
|
-
content: [{ type: "text", text: `Error:
|
|
2825
|
+
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
2826
|
isError: true,
|
|
2777
|
-
possible_causes: [
|
|
2827
|
+
possible_causes: isIframeElement ? [
|
|
2828
|
+
"Snapshot is outdated \u2014 iframe DOM changed after navigation or action",
|
|
2829
|
+
"Element was removed from iframe DOM",
|
|
2830
|
+
"Iframe has not fully loaded yet"
|
|
2831
|
+
] : [
|
|
2778
2832
|
"Snapshot is outdated \u2014 DOM changed after navigation or action",
|
|
2779
2833
|
"Element was removed from DOM",
|
|
2780
2834
|
"Using semantic ID from vsl_read_page instead of browser DOM ID from vsl_get_snapshot"
|
|
@@ -2787,7 +2841,19 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2787
2841
|
let scrolled = false;
|
|
2788
2842
|
let scrollOffset;
|
|
2789
2843
|
if (autoScroll) {
|
|
2790
|
-
const scrollResult = await browser.
|
|
2844
|
+
const scrollResult = targetFrame ? await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
2845
|
+
const el = document.querySelector(sel);
|
|
2846
|
+
if (!el) return { needsScroll: false, scrolled: false };
|
|
2847
|
+
const rect2 = el.getBoundingClientRect();
|
|
2848
|
+
const viewportWidth = window.innerWidth;
|
|
2849
|
+
const viewportHeight = window.innerHeight;
|
|
2850
|
+
const isVisible2 = rect2.top >= 0 && rect2.left >= 0 && rect2.bottom <= viewportHeight && rect2.right <= viewportWidth;
|
|
2851
|
+
if (isVisible2) {
|
|
2852
|
+
return { needsScroll: false, scrolled: false };
|
|
2853
|
+
}
|
|
2854
|
+
el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
|
|
2855
|
+
return { needsScroll: true, scrolled: true };
|
|
2856
|
+
}, sessionId, selector) : await browser.evaluate((sel) => {
|
|
2791
2857
|
const el = document.querySelector(sel);
|
|
2792
2858
|
if (!el) return { needsScroll: false, scrolled: false };
|
|
2793
2859
|
const rect2 = el.getBoundingClientRect();
|
|
@@ -2802,21 +2868,46 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2802
2868
|
}, sessionId, selector);
|
|
2803
2869
|
if (scrollResult.scrolled) {
|
|
2804
2870
|
scrolled = true;
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2871
|
+
if (targetFrame) {
|
|
2872
|
+
await browser.evaluateInFrame(targetFrame, () => {
|
|
2873
|
+
return new Promise((resolve) => {
|
|
2874
|
+
requestAnimationFrame(() => {
|
|
2875
|
+
requestAnimationFrame(() => {
|
|
2876
|
+
resolve();
|
|
2877
|
+
});
|
|
2878
|
+
});
|
|
2879
|
+
});
|
|
2880
|
+
}, sessionId);
|
|
2881
|
+
scrollOffset = await browser.evaluateInFrame(targetFrame, () => {
|
|
2882
|
+
return { x: window.scrollX, y: window.scrollY };
|
|
2883
|
+
}, sessionId);
|
|
2884
|
+
} else {
|
|
2885
|
+
await browser.evaluate(() => {
|
|
2886
|
+
return new Promise((resolve) => {
|
|
2808
2887
|
requestAnimationFrame(() => {
|
|
2809
|
-
|
|
2888
|
+
requestAnimationFrame(() => {
|
|
2889
|
+
resolve();
|
|
2890
|
+
});
|
|
2810
2891
|
});
|
|
2811
2892
|
});
|
|
2812
|
-
});
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
}
|
|
2893
|
+
}, sessionId);
|
|
2894
|
+
scrollOffset = await browser.evaluate(() => {
|
|
2895
|
+
return { x: window.scrollX, y: window.scrollY };
|
|
2896
|
+
}, sessionId);
|
|
2897
|
+
}
|
|
2817
2898
|
}
|
|
2818
2899
|
}
|
|
2819
|
-
const rect = await browser.
|
|
2900
|
+
const rect = targetFrame ? await browser.evaluateInFrame(targetFrame, (sel) => {
|
|
2901
|
+
const el = document.querySelector(sel);
|
|
2902
|
+
if (!el) return null;
|
|
2903
|
+
const r = el.getBoundingClientRect();
|
|
2904
|
+
return {
|
|
2905
|
+
x: r.x + window.scrollX,
|
|
2906
|
+
y: r.y + window.scrollY,
|
|
2907
|
+
width: r.width,
|
|
2908
|
+
height: r.height
|
|
2909
|
+
};
|
|
2910
|
+
}, sessionId, selector) : await browser.evaluate((sel) => {
|
|
2820
2911
|
const el = document.querySelector(sel);
|
|
2821
2912
|
if (!el) return null;
|
|
2822
2913
|
const r = el.getBoundingClientRect();
|
|
@@ -2833,10 +2924,16 @@ async function handleGetVisual(args, browser, session, sessionId) {
|
|
|
2833
2924
|
isError: true
|
|
2834
2925
|
};
|
|
2835
2926
|
}
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2927
|
+
let screenshotBuffer;
|
|
2928
|
+
if (targetFrame) {
|
|
2929
|
+
const locator = targetFrame.locator(selector);
|
|
2930
|
+
screenshotBuffer = await locator.screenshot({ type: "png" });
|
|
2931
|
+
} else {
|
|
2932
|
+
screenshotBuffer = await page.screenshot({
|
|
2933
|
+
type: "png",
|
|
2934
|
+
clip: rect
|
|
2935
|
+
});
|
|
2936
|
+
}
|
|
2840
2937
|
const base64Image = screenshotBuffer.toString("base64");
|
|
2841
2938
|
const metricsData = { type: "element", element_id: args.element_id, width: rect.width, height: rect.height };
|
|
2842
2939
|
const result = {
|
|
@@ -3719,7 +3816,7 @@ var VSL_TOOLS = [
|
|
|
3719
3816
|
},
|
|
3720
3817
|
{
|
|
3721
3818
|
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.",
|
|
3819
|
+
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
3820
|
inputSchema: {
|
|
3724
3821
|
type: "object",
|
|
3725
3822
|
properties: {
|
|
@@ -4868,7 +4965,7 @@ var SessionManager = class {
|
|
|
4868
4965
|
};
|
|
4869
4966
|
|
|
4870
4967
|
// src/version.ts
|
|
4871
|
-
var VSL_MCP_SERVER_VERSION = "1.4.
|
|
4968
|
+
var VSL_MCP_SERVER_VERSION = "1.4.2";
|
|
4872
4969
|
|
|
4873
4970
|
// src/index.ts
|
|
4874
4971
|
async function main() {
|