safari-mcp 2.5.1 → 2.5.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.
@@ -850,7 +850,7 @@ async function handleCommand(type, payload) {
850
850
  }
851
851
 
852
852
  case "type_text": {
853
- return await execInTab((text, selector) => {
853
+ const result = await execInTab((text, selector) => {
854
854
  if (selector) { const el = (window.__mcpDeepQuery || document.querySelector.bind(document))(selector); if (el) el.focus(); }
855
855
 
856
856
  // === Strategy 1: ProseMirror native API ===
@@ -943,6 +943,32 @@ async function handleCommand(type, payload) {
943
943
  }
944
944
  return "Typed " + text.length + " chars";
945
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;
946
972
  }
947
973
 
948
974
  case "press_key": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safari-mcp",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
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",
package/safari.js CHANGED
@@ -97,7 +97,7 @@ process.on("uncaughtException", (err) => { console.error("Uncaught:", err); clea
97
97
  let _activeTabIndex = null; // null = use front document (default)
98
98
  let _activeTabURL = null; // URL-based tracking (stable even when tabs shift)
99
99
  let _lastResolveTime = 0; // Cache: skip resolve if verified recently
100
- const RESOLVE_CACHE_MS = 1500; // Re-verify tab every 1.5 seconds (was 5s — too stale)
100
+ const RESOLVE_CACHE_MS = 0; // Always re-verify — cached indices go stale when tabs open/close
101
101
 
102
102
  // ========== DIAGNOSTIC LOG ==========
103
103
  // File-based log for profile/focus issues — survives MCP restart, visible to user