safari-mcp 2.6.0 → 2.6.1

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.
Files changed (2) hide show
  1. package/index.js +17 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -68,10 +68,11 @@ const _ownedTabURLs = new Set();
68
68
  function _isURLOwned(url) {
69
69
  if (!url) return false;
70
70
  if (_ownedTabURLs.has(url)) return true;
71
- // Match ignoring query params / fragments (URL may change slightly after load)
72
- const urlBase = url.split('?')[0].split('#')[0];
71
+ // Match ignoring query params / fragments / trailing slashes (URL may change slightly after load)
72
+ const normalize = (u) => u.split('?')[0].split('#')[0].replace(/\/+$/, '');
73
+ const urlBase = normalize(url);
73
74
  for (const owned of _ownedTabURLs) {
74
- const ownedBase = owned.split('?')[0].split('#')[0];
75
+ const ownedBase = normalize(owned);
75
76
  if (urlBase === ownedBase) return true;
76
77
  }
77
78
  return false;
@@ -1116,21 +1117,29 @@ server.tool(
1116
1117
  }
1117
1118
  }
1118
1119
 
1119
- const result = await extensionOrFallback(
1120
+ const rawResult = await extensionOrFallback(
1120
1121
  "new_tab", { url },
1121
1122
  () => safari.newTab(url)
1122
1123
  );
1124
+ // AppleScript fallback returns a JSON string; extension returns an object — normalize
1125
+ let result = rawResult;
1126
+ if (typeof rawResult === 'string') {
1127
+ try { result = JSON.parse(rawResult); } catch {}
1128
+ }
1123
1129
  // Sync safari.js tracking when extension handled new_tab
1124
1130
  if (result?.tabIndex) {
1125
1131
  safari.setActiveTabIndex(result.tabIndex);
1126
1132
  _trackTab(result.tabIndex, url);
1127
1133
  }
1128
- if (result?.url) {
1129
- safari.setActiveTabURL(result.url);
1134
+ if (result?.url || url) {
1135
+ // Prefer requested URL over about:blank for tracking (page hasn't loaded yet)
1136
+ const trackUrl = (!result?.url || result.url === 'about:blank') && url ? url : result.url;
1137
+ safari.setActiveTabURL(trackUrl);
1130
1138
  // Also register actual URL (may differ from requested due to redirects)
1131
- _addOwnedURL(result.url);
1139
+ _addOwnedURL(trackUrl);
1140
+ if (url && url !== trackUrl) _addOwnedURL(url); // also own the requested URL (handles www redirects)
1132
1141
  }
1133
- return { content: [{ type: "text", text: typeof result === 'string' ? result : JSON.stringify(result) }] };
1142
+ return { content: [{ type: "text", text: typeof rawResult === 'string' ? rawResult : JSON.stringify(result) }] };
1134
1143
  }
1135
1144
  );
1136
1145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safari-mcp",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
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",