Skip to content

WebView

Presents websites and evaluates JavaScript on websites.

Supports rendering HTML as well as loading a file and rendering it. A file can be of various types. It could for example be an HTML file or an image.

The web view also supports evaluating JavaScript on a website.

shouldAllowRequest

Function called upon load of a request.

When the web view performs a request to load a resource, the function can determine whether or not to allow the request. Disallowing request can speed up the time it takes to load the website.

By default all requests are allowed.

shouldAllowRequest: fn(Request) -> bool

-new WebView

Constructs web view.

Constructs a new web view. Use a web view to evaluate JavaScript on websites.

new WebView()

+loadHTML

Loads HTML and renders it.

static loadHTML(html: string, baseURL: string, preferredSize: Size): Promise

+loadFile

Loads a file and renders it.

Files can be of various types, including HTML files and images.

The supplied HTML file can reference files and nested directories in the same directory as the HTML file resides.

The optional preferredSize parameter is ignored unless the script is run in a Siri Shortcut.

If you are displaying large images in a memory constrained envrionment, for example in a Siri Shortcut, you should use the WebView bridge instead of the QuickLook bridge. The technical reason for this is that a Siri Shortcut and other app extension processes have very limited memory and loading a very large image will cause the app extension to be terminated. However, the web view will run in a different process meaning that it is not affected by the same memory constraints.

static loadFile(fileURL: string, preferredSize: Size): Promise

-loadURL

Loads URL in web view.

Loads the URL in the web view. The returned promise will complete once the web view have finished loading.

loadURL(url: string): Promise

-loadRequest

Loads request in web view.

When loading a request into the web view, the HTTP method, body and headers of the request will be respected. The onRedirect function on the request will not be invoked.

loadRequest(request: Request): Promise

-loadHTML

Loads HTML in web view.

Loads the HTML into the web view. The returned promise will complete once the web view have finished loading.

loadHTML(html: string, baseURL: string): Promise

-evaluateJavaScript

Evaluates JavaScript in the web view.

Evaluates JavaScript in the current context of the web view. The returned promise carries the result of evaluating the JavaScript.

evaluateJavaScript(javaScript: string): Promise<any>

-getHTML

Reads and returns HTML from the loaded website.

getHTML(): Promise<any>

-present

Presents the web view.

The web view is presented with the content that has been loaded into it.

present(): Promise

-waitForLoad

Waits for the web view to load.

The returned promise will be fulfilled when the web view finishes loading. If the load fails, the promise will be fulfilled with an error. Use this with caution. If the web view is not loading a new page or is not about to load a new page, the returned promise will never be fulfilled. This limitation exists because Scriptable cannot determine if a web view is about to load a page in cases where evaluating JavaScript in the web view causes a new page to load.

Generally this should only be used when loading causing a new page to load from evaluateJavaScript. In other cases, e.g. when loading a URL using loadURL, the returned promise will be fulfilled when the page have been loaded.

waitForLoad(): Promise<any>