I’m using Scriptable to get a Siri shortcut which loads a radio news website and uses evaluateJavaScript to press the play button, which will have the effect of playing the latest news whenever I launch the shortcut.
Although it looks like the button gets pressed as expected, no sounds play on the iphone. I’ve tested this site using Safari on the phone and it plays as expected. I’m sure I’m missing something, but I don’t know what. Here’s my code:
let url = “https://kan.org.il/radio/hourlynews.aspx”
let wv = new WebView()
await wv.loadURL(url)
let js = ‘document.querySelector(\’#play_last\‘).click();’
wv.evaluateJavaScript(js, false)
await wv.present()
Did you copy the source directly from your script into your post here? If yes, then the problem may be the quotes. You’re using “ ” ‘ ’ instead of " and '.
If this does not fix it, then another problem might be that the play button doesn’t exist when your script wants to click it.
And as i can remember. I were read from MDN. When a webpage want to play audio. The web page must be interacted by user (clicking, swipe or something).
I dont know how Scriptable work behind the scenes, but using JS to automation will must be follow that rules, i think. And you using Webview actually Safari module.
If you need more information about autoplaying in browser. " Autoplay guide for media and Web Audio APIs" is the keyword. You can google and should look for MDN’s posts first.
p/s : Just a new comer with Scriptable and just first post also.