How to Build Multi-Step Safari Workflows in Apple Shortcuts

This article provides a direct guide to building multi-step automation workflows for the Safari web browser using the Apple Shortcuts app. You will learn how to capture active browser data using the Get Current Web Page action, manipulate webpage elements dynamically with the Run JavaScript on Web Page action, and chain these tools together with other apps. By mastering these built-in actions, you can automate complex browsing tasks, extract web data effortlessly, and streamline your daily digital routines on iOS, iPadOS, and macOS.

Capturing Data with "Get Current Web Page"

The foundation of many Safari workflows is getting the active webpage into the Shortcuts app so other actions can process it.

To build a workflow that extracts and saves information from your active Safari tab, follow these steps:

  1. Open the Shortcuts app and create a new shortcut.
  2. In the action library, search for and add the Get Current Web Page from Safari action. (Note: On iOS and iPadOS, it is often easier to trigger the shortcut from the Safari Share Sheet. To do this, tap the "i" icon at the bottom of the screen, toggle on Show in Share Sheet, and set the input type to Safari web pages).
  3. Add the Get Details of Safari Web Page action right below your first action.
  4. Tap the Detail parameter in this second action to choose what you want to extract. You can select Page Contents (which grabs the main body text), Page Selection (only text you have highlighted), URL, or Name (the page title).
  5. Chain this output to another action. For example, add the Create Note action to automatically save the extracted Page Contents into Apple Notes, or add the Make PDF action followed by the Save File action to archive the webpage directly to your iCloud Drive.

Manipulating Pages with "Run JavaScript on Web Page"

For tasks that require custom data extraction or altering how a webpage looks, the Run JavaScript on Web Page action is required. It allows you to inject custom code into the active Safari tab and pass the results to the next step in your shortcut.

Prerequisites for JavaScript Actions

Before building this workflow, you must enable scripting permissions:

  • In Shortcuts: Go to Settings (or Preferences on Mac), select the Advanced tab, and check Allow Running Scripts.
  • In Safari (macOS): Enable the Develop menu in Safari Settings > Advanced, then go to the Develop menu in the top bar and select Allow JavaScript from Apple Events.

Building a JavaScript Workflow

When using JavaScript in Shortcuts, your code must always end with the completion() function. Whatever variable you place inside the parentheses of completion() is passed on as the output to the next action in your workflow.

Here is how to build a multi-step workflow that extracts all hyperlinks from a webpage and copies them to your clipboard:

  1. Create a new shortcut enabled for the Share Sheet (accepting Safari web pages), or start with the Get Current Web Page from Safari action.
  2. Add the Run JavaScript on Web Page action.
  3. Replace the default code in the action with the following script:
var links = [];
var elements = document.querySelectorAll('a');
for (var i = 0; i < elements.length; i++) {
    if (elements[i].href) {
        links.push(elements[i].href);
    }
}
completion(links);
  1. Add the Combine Text action. It will automatically take the links array from the JavaScript output. Set it to combine the text with New Lines.
  2. Add the Copy to Clipboard action at the end.

When you run this shortcut, it will scan the active Safari page, gather every URL, format them into a clean list, and place them on your clipboard ready to be pasted elsewhere.

Combining Actions for Advanced Automation

The true power of Shortcuts lies in mixing native actions with JavaScript. You can run a script to gather data, use native Shortcuts actions to filter that data, and then send it to another application.

For example, to build a workflow that grabs the webpage title, current URL, and highlighted text to create a formatted citation in a document:

  1. Highlight text on a Safari webpage.
  2. Trigger a Share Sheet shortcut that starts with the Accepts Safari web pages input.
  3. Add Get Details of Safari Web Page and select Name.
  4. Add a second Get Details of Safari Web Page, select URL, and make sure its input is linked back to the original Shortcut Input (not the Name action above it).
  5. Add a third Get Details of Safari Web Page, select Page Selection, and link it to the Shortcut Input.
  6. Add a Text action. Inside the text box, use the variables generated by the previous three steps to format your citation (e.g., "Page Selection" - Name (URL)).
  7. Add the Append to Note or Add Reminder action to save your formatted citation to the productivity app of your choice.