Local HTML file request

Please, I would like to know if it is possible to do a html request(url) on a local or iCloud web page in Scriptable.
Thanks in advance for your help

You can’t make a request for a non-hosted page. There’s nothing to serve the request from.

You can read HTML content from a file though and you can load HTML into a webview if that helps?

Thanks a lot for your help.
My need is to get the result of the local html page after the JavaScript processing of this page. Is there a way to get it ?

Not sure what you mean by result. If you need to render some HTML, use a webview. You can query content from a webview too.

To illustrate :

Here is my local html file :

This page uses a web js library
I would to request this page to get the « output » variable

Thanks for your help

Yes. You would apply the approach described in the previous response. In particular the evaluation Simon describes in the referenced thread to get the value from the DOM.

Thanks for your answer
Sorry but i didn’t understand all I have to do
I create a web view , load my local page but how can I process the JavaScript of this page ?
Thanks for your help

The JS on the page is processed by the WebView. However, your approach here is a bit … outdated. Instead of document.write() you might want to do something like

let b = document.getElementsByTagName('body')[0];
let p = b.appendElement('p');
p.id = "myText";
p.textContent = output;

Then in your Scriptable script, you’d use JS to access the value of the p element like so:

txt = document.getElementById('MyText').textContent;

I’d suggest this slightly more convoluted approach because I’m not sure

  • where the text produced by document.write() goes in the DOM tree
  • and consequently, how to get at it with the JS DOM methods
1 Like

Here is Simon’s example of the JavaScript evaluation straight out of the thread I linked to.

let url = "https://scriptable.app"
let wv = new WebView()
await wv.loadURL(url)
let js = `
let link = await wv.evaluateJavaScript(js)
log("Download Scriptable at " + link)

Note how it is used to get processed content from the webview back into Scriptable.

When you load your HTML, and I fully support the suggestion from @chrillek around your output, you use the evaluation, as above, to get the result into Scriptable for further processing.

Make sense?

Thanks For your help and your patience :slight_smile:
Yes it’s less obscur for me.
I have always a problem to load (loadURL) the webpage located on iCloud, i get a error message that it isn’t a correct url

Just some pointers on that then.

  • Is the URL valid in structure?
  • Does it require authentication to access?
  • What is the error exactly?

So you store an HTML file in your iCloud drive? In that case, you can’t use an http URL, I’d think: http requires a web server to deliver the content.
There’s a short example here:

I’d assumed that @Sthuv was trying something different as I covered that very point in the first reply :thinking:

If it is just an iCloud file, Scriptable can getthe file content and load the HTML into the WebView : use loadHTML() or loadFile() (for info, Simon published an example with loadFile() a few years back).

If it is a file hosted on a web server, then you would pass the URL to the WebView to load: use loadURL().

These functions are covered in the WebView documentation


I finally managed to do what I wanted by storing the source of my html page in a String variable for which I then applied the loadHTML
Thank you all again for the precious help you gave me