![](https://help.apple.com/assets/645D5D228BE0233D28263F4B/645D5D248BE0233D28263F53/en_US/fbd8d40651fff19a46e7aaedd4cb1b09.png)
Use the Run JavaScript on Webpage action in Shortcuts on Mac
Use the Run JavaScript on Webpage action to retrieve specific data from a website, or to modify the contents of a webpage.
![The Run JavaScript on Webpage action in the shortcut editor.](https://help.apple.com/assets/645D5D228BE0233D28263F4B/645D5D248BE0233D28263F53/en_US/23b5723ffef17fe59b6d640be612a554.png)
The Run JavaScript on Webpage action contains a text field where you write your own script. You run the shortcut from the Safari app. Before you can run JavaScript from a shortcut you must turn on Allow Running Scripts. See Advanced Privacy and security settings in Shortcuts on Mac.
Note: You can also use the Run JavaScript on Webpage action in SFSafariViewController. For more information, see https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller.
Create a JavaScript shortcut
In the Shortcuts app
on your Mac, double-click a shortcut.
In the shortcut editor, click
at the top of the action list, begin typing “Run JavaScript…” in the search field, then double-click the Run JavaScript on Active Safari Tab action to add it to the shortcut editor.
Write your script in the text field in the Run JavaScript on Active Safari Tab action.
Important: In your script, make sure you call the completion handler. For more information, see Run JavaScript on Webpage action output.
Add any other actions you want to include in the shortcut.
Tip: To use multiple Run JavaScript on Webpage actions in the same shortcut, make sure each instance of the action has the Safari webpage as its input.
Click
to open Details, then select Services Menu.
A new action appears. To ensure that the shortcut appears only in Safari, deselect all input types except “Safari webpages.”
For more information, see Understanding input types in Shortcuts on Mac.
For more information about working with JavaScript in Shortcuts, see Intro to the Run JavaScript on Webpage action in Shortcuts on Mac.
Run the JavaScript shortcut on a webpage
In Safari, choose your shortcut from Safari > Services.