Debugging stuck callback URL

I’m trying to write a script to share todo tasks from 2Do and copy them into another app, Sorted, that helps timeblock tasks. This is my first Scriptable and I basically have never programmed JavaScript so hopefully, I’ve just done something stupid, but, right now, the script just gets stuck with a spinning wheel. Any advice on how to debug this?

Here’s the script:


console.logError("DEBUG: lines")
console.logError(lines)

var unique = lines.filter(function(elem, index, self) {
    return index === self.indexOf(elem);
})
    
console.logError("DEBUG: unique...")
console.logError(unique)

let baseURL = 'sorted://x-callback-url/add'
let reTasks = /(- (\[ \] ){0,1})(.+)/g
// TODO: Add Logic for - [ ]
// TODO: Group expression to filter out - ([ ])

tasks = []

while ((match = reTasks.exec(unique)) != null) {
    let url = new CallbackURL(baseURL);
    url.addParameter('title', match[3]);
    console.logError("DEBUG: URL: " + url.getURL());
    var success = await url.open();
    console.logError("DEBUG: success: " + success)
}

Here’s a picture of the share sheet output and log:

It appears that you are running this from an share sheet, is that correct? If that’s the case, there’s a bug in the current build where URLs aren’t properly opened. This should be fixed in the next build. Sorry for the inconvenience.

Yes, this is from a share sheet. That’s good to hear. Eagerly awaiting the next build. I’m already loving Scriptable as I’m doing things that I couldn’t figure out how to with Workflow.

So I’ve tried this in 1.0.2 and the first callback URL sort of works, going into the target app and doing the right operation. However, after completion, presumably successfully, the constructed callback URL says go back to Scriptable. This then cancels the share sheet script as can be seen from the error below. How can I get a successful callback to go back to the share sheet in the original app (in this case, 2Do)?

2018-10-07 23:02:29: DEBUG: URL: sorted://x-callback-url/add?title=clean%20out%20the%20fridge%20and%20freezer&x-source=Scriptable&x-success=scriptable://x-callback-url/success&x-error=scriptable://x-callback-url/error&x-cancel=scriptable://x-callback-url/cancel

2018-10-07 23:03:03: Error: The x-callback-url operation was cancelled because you returned to Scriptable.