WebView evaluateJavaScript to manipulate webpage

Hi

Extremely new, and javascript illiterate unfortunately. I’ve had a mate help me thus far but the solution was with jQuery rather than JavaScript which I believe Scriptable requires.

I have a webpage that looks like this,

The relevant source code is this…

<tr><td colspan="5" class="ris_save_buttons_container"><a href="package.php?ac=0xxxx00000000100d028f&amp;id=7483869,7483870,7483871,7483872,7483876,7483875,7483874,7483873&amp;file=6637533,6637534,6637535,6637536,6637540,6637539,6637538,6637537&amp;action=PRINTALL&amp;openwith=GOODREADER" class="ris_button" target="_self">
Open in GoodReader
</a>
<a href="package.php?ac=0xxxx00000000100d028f&amp;id=7483869,7483870,7483871,7483872,7483876,7483875,7483874,7483873&amp;file=6637533,6637534,6637535,6637536,6637540,6637539,6637538,6637537&amp;action=PRINTALL&amp;openwith=BROWSER" class="ris_button" target="_self">
Open in Browser

The jQuery solution for selecting the “open in browser” link was

url = $('a.ris_button:nth-child(2)').attr('href');
window.open(url)

I am trying to write a Scriptable code that will pass back the value of the link behind the “Open with browser” link… I have the below code but I am getting an error - “Error: Expected value of type string but got value of type {any: any}.”

Is anyone able to steer me in the right direction?

Cheers

K

var url = args.shortcutParameter

const webview = new WebView();

await webview.loadURL(url);

var getData = 
  function runit() {
    const url2 = document.querySelector('a.ris_button:nth-child(2)').attr('href');
    return (url2);
  }

let link = await webview.evaluateJavaScript(getData, false);

Script.setShortcutOutput(link);

Script.complete();

Nevermind, found another not so elegant solution.

var url = args.shortcutParameter

const webview = new WebView();

await webview.loadURL(url);

let response = await webview.getHTML();

//console.log(response)

Script.setShortcutOutput(response);

Script.complete();

This gives me an output of the html source code. I was then able to extract the text i needed through shortcuts “Match Text” and the command

(?<=WORD1).*(?=WORD2)

from here -https://www.reddit.com/r/shortcuts/comments/b5labq/match_text_examples_for_the_beginner_a_regex/