How are you interacting with the WebView?


#1

With 1.1 you can access the WebView. However, you can’t return HTMLNodes. This is the pattern I came up to return data from a DOM selector.

w = new WebView();
await w.loadURL("https://apple.com");

var getData = `
  function runit() {
    var p = document.querySelectorAll('p');
    var res = p.forEach(item => { res.push(item.innerHTML); });
    return res;
  }

runit();
`
let response = await w.evaluateJavaScript(getData);

Does anyone have an alternate way of returning DOM data from the WebView?


#2

Hi Scott,

I have taken your code and made a bit of change. Now it will get “the word of today” (in Danish) and return it into response- hope you can use it.


const webview = new WebView();
await webview.loadURL("https://ordnet.dk/ddo/forside");

var getData = `
  function runit() {
    const ord = document.querySelector('.dagensord .match').innerText;
    const lemklas = document.querySelector('.dagensord .lemklas').innerText;
    const definition = document.querySelector('.dagensord .definition').innerText;
    return (ord + ' (' + lemklas + ') \\n' + definition);
  }

  runit();
`

let response = await webview.evaluateJavaScript(getData, false);
console.log(response)```

split this topic #3

4 posts were split to a new topic: User Input (to function parameters)


#4

Does anybody know, wheter it is possible to display app content with webview or not? Im thinking of using the x-callback-url action as input url. But then I’m stuck b/c its obviously not an html…:exploding_head:


#5

I’m sorry, I don’t understand.Do you mean to display content from another app in the WebView? you can launch Scriptable with an url scheme and pass data that way, but it has to be encoded.

If you wanted to load the url in the WebView, you’re out of luck, because that won’t work.