Why did't the webView. evaluateJavaScript is work?

  const webView = new WebView();
  await webView.loadURL("www.google.com");
  const js = "console.log(2222);";
  webView.evaluateJavaScript(js);
  webView.present(true);
  Script.complete();

I’m not exactly sure why it doesn’t work when your URL doesn’t have the proper https scheme, but it hangs on loading. Perhaps it doesn’t handle the redirection to HTTPS correctly?

Try adding https:// before www in the page URL. That works for me.

const webView = new WebView();
async function injectEventhandler() {
  const js = `
     console.log(1111);
  `;
  return webView.evaluateJavaScript(js);
}

const present = async (b) => {
  await webView.loadURL("http://scriptablejs.gitee.io/store/#/menu?scriptable=1&t=1631935322061");
  injectEventhandler();
  return webView.present(true);
};
await present();
Script.complete();

You can Try this.It dosen’t work!I running IOS15.

IMG_3709
The evaluateJavaScript didn’t to work

What iOS version and Scriptable version are you using? I’m on iOS 14.8 with Scriptable 1.6.5, and the exact code you have there works fine for me. It logs “2222” to the console as expected.

The Scriptable version is the same as yours,but IOS version on IOS15.So it could be the ios version.Just now,i downgraded the IOS version.It logs “2222” to the console as expected.

1 Like

It happended to me in iOS 15 too.

Please fix it.

tweet from the developer

There are some issues with the -evaluateJavaScript() API in WebView on devices running iOS 15. I’m working on a fix for this but it’s likely to require some larger changes that I don’t want to rush. – @scriptableapp

1 Like