Inject JavaScript into web page using Scriptable

shortcuts

#1

I’m developing a shortcut to open a list of Instagram profiles one after the other, to open the last post and click on the Like button.
The shortcut works and here it is

Imgur

Imgur

Imgur

Imgur

Imgur

If I want to get the last post from the profile and click on the Like button, I have to use JavaScript.
I already have JavaScript scripts available.
I’ve been working on Scriptable for a while but I need help.
How can I insert JavaScript in the newly opened web page?
This is my script at the moment

(https://imgur.com/xfN1sZZ)

Opens a page, whose URL is generated by the Shortcut app.
When the page is open, I want to inject javascript to perform some actions.


#2

For that you have to use WebView:

let wv = new WebView();
await wv.loadURL(url);
await wv.evaluateJavaScript("your script here as string");

The first line creates the WebView instance, the second line loads your website and waits until it has finished and the third line executes your javascript.