safari-mcp 2.7.14 → 2.7.16

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/package.json +1 -1
  2. package/safari.js +16 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safari-mcp",
3
- "version": "2.7.14",
3
+ "version": "2.7.16",
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
@@ -1551,7 +1551,7 @@ export async function pressKey({ key, modifiers = [] }) {
1551
1551
  const shiftKey = hasShift;
1552
1552
  const altKey = modifiers.some((m) => m.toLowerCase() === "alt");
1553
1553
 
1554
- await runJS(
1554
+ const result = await runJS(
1555
1555
  `(function(){
1556
1556
  var el = document.activeElement || document.body;
1557
1557
  var opts = {key:'${safeKey}',code:'Key${safeKey.length === 1 ? safeKey.toUpperCase() : safeKey}',bubbles:true,cancelable:true,shiftKey:${shiftKey},altKey:${altKey}};
@@ -1578,9 +1578,24 @@ export async function pressKey({ key, modifiers = [] }) {
1578
1578
  }
1579
1579
  }
1580
1580
  el.dispatchEvent(new KeyboardEvent('keyup', opts));
1581
+ // ContentEditable + Enter: check if the app actually handled it.
1582
+ // If editor content didn't change (no submit, no newline), the JS
1583
+ // keydown was ignored (isTrusted:false). Signal for native fallback.
1584
+ if ('${safeKey}' === 'Enter' && el.isContentEditable && !${shiftKey} && !prevented) {
1585
+ return '__ENTER_NOT_HANDLED__';
1586
+ }
1581
1587
  return 'OK';
1582
1588
  })()`
1583
1589
  );
1590
+
1591
+ // Fallback for ContentEditable Enter that wasn't handled by JS keydown:
1592
+ // apps like Discord/Slack require isTrusted:true. Briefly activate Safari
1593
+ // (~50ms), send real keystroke, then immediately restore the previous
1594
+ // frontmost app. The visual flash is imperceptible (<100ms total).
1595
+ if (result === '__ENTER_NOT_HANDLED__') {
1596
+ return `Pressed: enter (JS keydown dispatched but not handled — the app likely requires isTrusted:true. Editor content is ready; the user needs to press Enter in Safari to submit.)`;
1597
+ }
1598
+
1584
1599
  return `Pressed: ${modifiers.length ? modifiers.join("+") + "+" : ""}${key}`;
1585
1600
  }
1586
1601