Running script in shortcuts

Hi, I am new to Scriptable and I wrote a script to open a webpage. Basically it first sends a POST request to get a token and cookies, then opens the webpage with the token and cookies.

let req = new Request(url)
req.method = 'POST'
req.headers = headers
req.body = body

let res = await req.loadJSON()
let token = res.token
let cookies = []
for (item of req.response.cookies) {
    cookies.push(item.name + '=' + item.value)
}


req = new Request(another-url + token)
req.method = 'GET'
req.headers = { 'Cookie': cookies.join('; ') }

let wv = new WebView()
await wv.loadRequest(req)
await wv.waitForLoad()
await wv.present()
Script.complete()

When I run the script inside the app, it works fine. However, when trying to run it via shortcuts, I get an error saying Presenting a configured web view is not supported. Take a look at the static WebView.loadURL() or WebView.loadFile() instead.

The problem is it seems not able to set cookies by loadURL(). Any solutions to solve this?

Looks like you’re out of luck, sorry.

There might be a workaround though. You could run the script in Scriptable via x-callback-url and then continue in shortcuts via the x-success URL that was provided as parameter in the x-callback-url. If you need further help with those, just ask!

Thanks for the hint! I tried to use x-callback-url to run script in Scriptable and it worked, but how do I set the x-success URL so it can return to the same shortcut?

There is an Open X-Callback URL action in Shortcuts which adds this parameter and waits for the callback.

Though if you wait too long to return, iOS might freeze the Shortcuts app and then it won’t continue anymore. This depends on your device.