In Shortcuts, script could not run as it took too long

I have a script that load a url to a WebView, evaluateJavaScript source, get some data out of it.

When I run this script in Shortcuts, Run Script action hangs for around 10 seconds and fails with an alert:

Could not run Run Script
The operation took too long to complete. Please try again.

The same script works totally fine if I run it within Scriptable, or if I run it in Shortcuts via x-callback-url.
It looks like Shortcuts’ Run (Scriptable) Script action has some timeout and doesn’t know Scriptable script is completed.

I do have Script.complete() call at the end of my script, so I am not sure what’s happening here.
The async operation in my script shouldn’t take more than 5 seconds. In fact, if I run it with working methods described above, it takes only 2-3 seconds to complete.

Any idea what would be blocking the operation completion?

PS: Pasteboard.pasteString() is undefined if I run script in Shortcuts as well even though it has a value if I run it in Scriptable. Is this expected?

It turned out that WebView.loadURL was the issue.
I haven’t been able to figure out why it hangs in Run Script action but x-callback-url action.

let wv = new WebView();
let html = await wv.loadURL(url);

Can you give an approximation of how long it takes to load the website when running with x-callback-url? Third-party shortcuts aren’t allowed to run for very long and therefore Scriptable may timeout when running in Siri or Shortcuts.

Depending on your use case, you may want to enable “Always Run in App” in the script settings. This will open Scriptable when running your shortcut.

As I mentioned in the original post, it usually takes only 2-3 seconds, sometimes around 5 seconds. I already tried enabling “Run in app” from Shortcuts’ Run (Scriptable) Script action with no luck.

It did jump to Scriptable but just hangs in there. I haven’t tried “Always Run in App” option from Scriptable’s script setting as I’ve already changed my code to only take x-callback-url parameters. I can test it later when I get some time, but do those options result in different environment (Run in app from Shortcuts action vs Always run in app from Scriptable script settings)? Both runs the Scriptable script in Scriptable as far as I know.