MacOS shortcut for running Javascript on a Safari page fails

I'm trying to run a MacOS shortcut using the "Run JavaScript on Active Safari Tab" action. I consistently get the error "Make sure that 'Allow JavaScript from Apple Events' is enabled in the Develop menu in Safari." The Develop menu in Safari does not contain this switch (in Tahoe 26.5.1), but if you go to Developer Settings... a dialog opens that includes the required switch. I've ensured that the switch is set on, but I continue to get the runtime error in the shortcut JavaScript. What am I missing?

Answered by DTS Engineer in 897722022

I built a small shortcut with a Run AppleScript action that runs do JavaScript on the front Safari tab. On macOS 26.5.1 with Safari 26.5, I can both reproduce your error and clear it. With "Allow JavaScript from Apple Events" turned off I get the same message you quote. With it turned on, the script returns its result. So that message is Safari's gate for running JavaScript through Apple Events, which is the path a Run AppleScript action's do JavaScript takes.

Since you have enabled that setting and still see the error, two things are worth checking:

  1. That the setting has actually taken effect. On Tahoe it lives in Settings > Developer. After you enable it, fully quit and relaunch Safari so the change takes hold, and confirm you enabled it in Safari itself rather than Safari Technology Preview.
  2. Automation permission for the app that runs the script. For a shortcut with a Run AppleScript action, that app is Shortcuts. Open System Settings > Privacy & Security > Automation, find Shortcuts, and turn on Safari beneath it. The first run may also show a one-time prompt to allow controlling Safari.

Those two settings are the levers here; there is nothing to change on the shortcut itself. An entitlement only comes into it if you build your own sandboxed app to run this.

If that does not sort it, let me know how you are running the JavaScript and I can narrow it down further.

I built a small shortcut with a Run AppleScript action that runs do JavaScript on the front Safari tab. On macOS 26.5.1 with Safari 26.5, I can both reproduce your error and clear it. With "Allow JavaScript from Apple Events" turned off I get the same message you quote. With it turned on, the script returns its result. So that message is Safari's gate for running JavaScript through Apple Events, which is the path a Run AppleScript action's do JavaScript takes.

Since you have enabled that setting and still see the error, two things are worth checking:

  1. That the setting has actually taken effect. On Tahoe it lives in Settings > Developer. After you enable it, fully quit and relaunch Safari so the change takes hold, and confirm you enabled it in Safari itself rather than Safari Technology Preview.
  2. Automation permission for the app that runs the script. For a shortcut with a Run AppleScript action, that app is Shortcuts. Open System Settings > Privacy & Security > Automation, find Shortcuts, and turn on Safari beneath it. The first run may also show a one-time prompt to allow controlling Safari.

Those two settings are the levers here; there is nothing to change on the shortcut itself. An entitlement only comes into it if you build your own sandboxed app to run this.

If that does not sort it, let me know how you are running the JavaScript and I can narrow it down further.

MacOS shortcut for running Javascript on a Safari page fails
 
 
Q