safari-mcp 2.21.2 → 2.21.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.
@@ -2761,7 +2761,16 @@ async function handleCommand(type, payload) {
2761
2761
  if (mainResult && JSON.parse(mainResult).length > 0) return mainResult;
2762
2762
  } catch { return mainResult; }
2763
2763
  const frameResult = await execAcrossFrames(queryFn, [payload.selector, payload.limit || 20], tabId);
2764
- return frameResult || mainResult;
2764
+ if (!frameResult) return mainResult;
2765
+ // Reaching here means the main frame matched nothing, so every element below came
2766
+ // from a child frame and its x/y are that frame's viewport coordinates. Say so in
2767
+ // the payload: the caller is an agent reading this JSON, and the click tools take
2768
+ // page coordinates — a comment in this file never reaches it.
2769
+ try {
2770
+ return JSON.stringify(JSON.parse(frameResult).map((el) => ({ ...el, frameRelative: true })));
2771
+ } catch {
2772
+ return frameResult;
2773
+ }
2765
2774
  }
2766
2775
 
2767
2776
  default:
@@ -2,7 +2,7 @@
2
2
  "manifest_version": 3,
3
3
  "name": "Safari MCP Bridge",
4
4
  "description": "Connects AI agents to Safari — fast JS execution, screenshots, clicks with your real cookies/logins",
5
- "version": "2.10.11",
5
+ "version": "2.10.12",
6
6
  "icons": {
7
7
  "48": "images/icon-48.png",
8
8
  "96": "images/icon-96.png",
package/index.js CHANGED
@@ -3014,7 +3014,7 @@ server.tool(
3014
3014
 
3015
3015
  server.tool(
3016
3016
  "safari_query_all",
3017
- "Find all elements matching a CSS selector (returns tag, text, href, value)",
3017
+ "Find all elements matching a CSS selector (returns tag, text, href, value). x/y are relative to each element's own frame viewport — for matches inside an iframe, click by selector or snapshot ref, not by these coordinates",
3018
3018
  {
3019
3019
  selector: z.string().describe("CSS selector"),
3020
3020
  limit: z.coerce.number().optional().describe("Max results (default: 20)"),
@@ -3025,6 +3025,15 @@ server.tool(
3025
3025
  "query_all", { selector: args.selector, limit: args.limit, ..._explicitReceipt(args) },
3026
3026
  () => safari.querySelectorAll(args)
3027
3027
  );
3028
+ // The matches live inside a child frame, so their x/y are that frame's viewport
3029
+ // coordinates while safari_click and friends take page coordinates. Warn in the
3030
+ // result text, which is the only part of this an agent actually reads.
3031
+ if (typeof result === "string" && result.includes('"frameRelative":true')) {
3032
+ return textResult(
3033
+ result +
3034
+ "\n\nNote: these matches are inside a child frame. Their x/y are relative to that frame's viewport (see \"frame\"), not to the page — click them by selector or by a safari_snapshot ref; passing these coordinates to safari_click lands somewhere else."
3035
+ );
3036
+ }
3028
3037
  return textResult(result);
3029
3038
  }
3030
3039
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safari-mcp",
3
- "version": "2.21.2",
3
+ "version": "2.21.3",
4
4
  "mcpName": "io.github.achiya-automation/safari-mcp",
5
5
  "description": "Safari browser automation for AI agents — native macOS, zero Chrome overhead. 97 tools via AppleScript + JavaScript.",
6
6
  "type": "module",