safari-mcp 2.5.0 → 2.5.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/extension/background.js +58 -2
- package/package.json +1 -1
package/extension/background.js
CHANGED
|
@@ -405,7 +405,7 @@ async function handleCommand(type, payload) {
|
|
|
405
405
|
|
|
406
406
|
// --- Click & Input ---
|
|
407
407
|
case "click": {
|
|
408
|
-
|
|
408
|
+
const result = await execInTab((selector, text, x, y, ref) => {
|
|
409
409
|
// Use shared deep query (defined by ensureHelpers / _deepQueryScript)
|
|
410
410
|
const dq = window.__mcpDeepQuery || document.querySelector.bind(document);
|
|
411
411
|
|
|
@@ -633,6 +633,36 @@ async function handleCommand(type, payload) {
|
|
|
633
633
|
|
|
634
634
|
return "Clicked: " + el.tagName + (el.textContent ? ' "' + el.textContent.trim().substring(0, 50) + '"' : "");
|
|
635
635
|
}, [payload.selector, payload.text, payload.x, payload.y, payload.ref], tabId);
|
|
636
|
+
|
|
637
|
+
// Fallback: if element not found in main frame, try all frames (cross-origin iframes)
|
|
638
|
+
if (result && (result.startsWith("Element not found") || result === "No click target")) {
|
|
639
|
+
const iframeResult = await execInAllFrames((selector, text) => {
|
|
640
|
+
let el = null;
|
|
641
|
+
if (selector) {
|
|
642
|
+
el = document.querySelector(selector);
|
|
643
|
+
} else if (text) {
|
|
644
|
+
// Search interactive elements by text
|
|
645
|
+
const candidates = document.querySelectorAll("button, a, [role='button'], input[type='submit']");
|
|
646
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
647
|
+
const t = (candidates[i].innerText || candidates[i].textContent || "").trim();
|
|
648
|
+
if (t === text) { el = candidates[i]; break; }
|
|
649
|
+
}
|
|
650
|
+
// Fuzzy: contains match
|
|
651
|
+
if (!el) {
|
|
652
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
653
|
+
const t = (candidates[i].innerText || candidates[i].textContent || "").trim();
|
|
654
|
+
if (t.includes(text) || text.includes(t)) { el = candidates[i]; break; }
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (!el) return null;
|
|
659
|
+
el.scrollIntoView({ block: "center", behavior: "instant" });
|
|
660
|
+
el.click();
|
|
661
|
+
return "Clicked (iframe): " + el.tagName + (el.textContent ? ' "' + el.textContent.trim().substring(0, 50) + '"' : "");
|
|
662
|
+
}, [payload.selector, payload.text], tabId);
|
|
663
|
+
if (iframeResult) return iframeResult;
|
|
664
|
+
}
|
|
665
|
+
return result;
|
|
636
666
|
}
|
|
637
667
|
|
|
638
668
|
// --- Click + Read (combo — saves 1 full MCP round-trip) ---
|
|
@@ -820,7 +850,7 @@ async function handleCommand(type, payload) {
|
|
|
820
850
|
}
|
|
821
851
|
|
|
822
852
|
case "type_text": {
|
|
823
|
-
|
|
853
|
+
const result = await execInTab((text, selector) => {
|
|
824
854
|
if (selector) { const el = (window.__mcpDeepQuery || document.querySelector.bind(document))(selector); if (el) el.focus(); }
|
|
825
855
|
|
|
826
856
|
// === Strategy 1: ProseMirror native API ===
|
|
@@ -913,6 +943,32 @@ async function handleCommand(type, payload) {
|
|
|
913
943
|
}
|
|
914
944
|
return "Typed " + text.length + " chars";
|
|
915
945
|
}, [payload.text, payload.selector], tabId);
|
|
946
|
+
|
|
947
|
+
// Fallback: if typing failed in main frame, try all frames (cross-origin iframes)
|
|
948
|
+
if (result === "Typed 0 chars" || !result) {
|
|
949
|
+
const iframeResult = await execInAllFrames((text) => {
|
|
950
|
+
const el = document.activeElement;
|
|
951
|
+
if (!el || el === document.body) return null;
|
|
952
|
+
// Try execCommand insert
|
|
953
|
+
const ok = document.execCommand("insertText", false, text);
|
|
954
|
+
if (ok) return "Typed " + text.length + " chars (iframe execCommand)";
|
|
955
|
+
// Fallback: contenteditable or input
|
|
956
|
+
if (el.isContentEditable) {
|
|
957
|
+
el.textContent = text;
|
|
958
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
959
|
+
return "Typed " + text.length + " chars (iframe contenteditable)";
|
|
960
|
+
}
|
|
961
|
+
if ("value" in el) {
|
|
962
|
+
el.value = text;
|
|
963
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
964
|
+
el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
965
|
+
return "Typed " + text.length + " chars (iframe input)";
|
|
966
|
+
}
|
|
967
|
+
return null;
|
|
968
|
+
}, [payload.text], tabId);
|
|
969
|
+
if (iframeResult) return iframeResult;
|
|
970
|
+
}
|
|
971
|
+
return result;
|
|
916
972
|
}
|
|
917
973
|
|
|
918
974
|
case "press_key": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "safari-mcp",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"mcpName": "io.github.achiya-automation/safari-mcp",
|
|
5
5
|
"description": "Safari browser automation for AI agents — native macOS, zero Chrome overhead. 80 tools via AppleScript + JavaScript.",
|
|
6
6
|
"type": "module",
|