Examples on the new ShouldAllowRequest?

The latest update of scriptable got me excited, I was trying out the default autocomplete code web.shouldAllowRequest = (fn(request) -> bool) => { }

but I keep getting syntax errors around the arrow functions. Am I doing something wrong?

The syntax isn’t correct around this bit of code: (fn(request) -> bool)

The correct syntax is

web.shouldAllowRequest = (request) => {
    // your code here


web.shouldAllowRequest =  function(request) {
    // your code here
PS: This wasn't in the latest update. It was already there in Scriptable 1.3 (I don't know the exact version it got added, but I have it on iOS 12 and 1.3 is the last version to support this iOS)
1 Like

Oh lol, I read about it in my change logs, never knew it existed before!

I’m having issues trying to block images in a webview, when I check my logs there only seems to be one request it has captured which is the request for the webview but doesn’t capture requests orginated from the webview. Is this an limitation?

Maybe it can only capture website navigations. Certainly it can’t capture requests from javascript in the page, but I too thought that it can capture images… @simonbs Could you please shine some light on this?

You’re right that it doesn’t catch resources (images, CSS files etc.) but it should capture requests made when navigating inside the web view, for example when clicking a link.

In case anyone sees this and is looking for an example on how to use the API. The following script just logs the requests and allows all of them.

let wv = new WebView()
wv.shouldAllowRequest = (req) => {
  return true

Is it possible to use this API in conjunction with evaluateJavascript() to inject/evaluate JavaScript while the user navigates a website?

In theory, yes, but I got some headache with that as there is no real way of debugging the injected script other than to log everything to console… and that can be really tedious.