In the Shortcuts app 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 Intro to the Run JavaScript on Webpage action in Shortcuts on Mac.
In Safari, choose your shortcut from Safari > Services.