(I’m cross-posting this from r/Scriptable, since I didn’t get any replies.)
I’m trying to create an iOS Shortcut that accepts a URL and retrieves the contents of the <title>
tag from that webpage. This would be simple, except I want it to work with Twitter permalinks – Twitter updates the page contents, including the title, using Javascript after the initial load. After a fair bit of trial and error, this is as close as I’ve been able to get: https://www.icloud.com/shortcuts/49440b20f68e45d3a96b2a3735a8b453
This works fine for most websites, but not for Twitter. I get the following error:
Could Not Run Run Inline Script
Script completed without presenting UI, triggering a text to speak or outputting a value. If this is intentional, you can manually call Script.complete() to gracefully complete the script.
Curiously, if I copy the in-line code from that Shortcut (below for reference), and paste it into a new script in Scritpable, it works fine for Twitter only in that case (fetching the title for the hard-coded test URL).
Any suggestions? Perhaps it’s an issue with memory, or how I’m passing the data back? I’m new to Shortcuts and Scriptable, and have only limited Javascript experience, so I might be missing something small…
Thanks!
const url = args.plainTexts && args.plainTexts[0] ? args.plainTexts[0] : "https://twitter.com/lehrblogger/status/391287397457330177";
const interval = 300;
const webView = new WebView();
await webView.loadURL(url);
async function getTitle() {
const title = await webView.evaluateJavaScript("document.title");
// Twitter URL pages start with no title, and then are progressively updated
log(title);
if (title && title != "Twitter" && title != "Tweet / Twitter") {
Script.setShortcutOutput(title);
Script.complete();
} else {
Timer.schedule(interval, false, getTitle);
}
};
Timer.schedule(interval, false, getTitle);