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.

Function called upon load of a request.

shouldAllowRequest: fn(Request) -> bool

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.

Constructs web view.

new WebView()

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

evaluateJavaScript(javaScript, useCallback)

Section titled “evaluateJavaScript(javaScript, useCallback)”

Evaluates JavaScript in the web view.

evaluateJavaScript(javaScript: string, useCallback: bool): Promise<any>

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

When passing false to the useCallback parameter, which is the default value, evaluation will terminate after evaluating the last line of the JavaScript. The value on the last line of the script will be carried by the promise returned by evaluateJavaScript.

When passing true to the useCallback parameter, evaluation will only complete after the globally available completion function is called. Any value passed to the function, will be carried by the promise returned by evaluateJavaScript.

The log is available from the evaluated JavaScript, i.e. messages passed to the globally available log and logError functions will be shown in the log.

javaScript string

JavaScript to evaluate in the web view.

useCallback bool

Optional. If true the web view waits for the globally available completion function of the web view to be called before terminating. Defaults to false.

Promise<any>

Promise that carries the result of evaluating the JavaScript.

Reads and returns HTML from the loaded website.

getHTML(): Promise<any>

Promise<any>

Promise that carries the HTML of the loaded website.

loadFile(fileURL, preferredSize, fullscreen)

Section titled “loadFile(fileURL, preferredSize, fullscreen)”

Loads a file and renders it.

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

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.

fileURL string

URL of the file to load and render.

preferredSize Size

Optional. Preferred size of the view. This size is not guaranteed to be respected and is only used when the script is run with Siri or in the Shortcuts app.

fullscreen bool

Optional. Set to true to present the web view in fullscreen. This only has an effect when used within the app. Defaults to false.

Promise

Promise that carries no value. Once the web view have been closed, the promise will complete.

Loads file in the web view.

loadFile(fileURL: string): Promise

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.

fileURL string

URL of the file to load and render.

Promise

Promise that carries no value. Once the web view has finished loading, the promise will complete.

loadHTML(html, baseURL, preferredSize, fullscreen)

Section titled “loadHTML(html, baseURL, preferredSize, fullscreen)”

Loads HTML and renders it.

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

html string

HTML to load and render.

baseURL string

Optional. Base URL used to resolve relative URLs in the HTML.

preferredSize Size

Optional. Preferred size of the view. This size is not guaranteed to be respected and is only used when the script is run with Siri or in the Shortcuts app.

fullscreen bool

Optional. Set to true to present the web view in fullscreen. This only has an effect when used within the app. Defaults to false.

Promise

Promise that carries no value. Once the web view have been closed, the promise will complete.

Loads HTML in web view.

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

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

html string

HTML to load into the web view.

baseURL string

Optional. Base URL used to resolve relative URLs in the HTML.

Promise

Promise that carries no value. Once the web view has finished loading, the promise will complete.

Loads request in web view.

loadRequest(request: Request): Promise

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.

request Request

Request to load into the web view.

Promise

Promise that carries no value. Once the web view has finished loading, the promise will complete.

Loads URL in web view and presents the web view.

static loadURL(url: string, preferredSize: Size, fullscreen: bool): Promise

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

url string

URL to load into the web view.

preferredSize Size

Optional. Preferred size of the view. This size is not guaranteed to be respected and is only used when the script is run with Siri or in the Shortcuts app.

fullscreen bool

Optional. Set to true to present the web view in fullscreen. This only has an effect when used within the app. Defaults to false.

Promise

Promise that carries no value. Once the web view have been closed, the promise will complete.

Loads URL in web view.

loadURL(url: string): Promise

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

url string

URL to load into the web view.

Promise

Promise that carries no value. Once the web view has finished loading, the promise will complete.

Presents the web view.

present(fullscreen: bool): Promise

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

fullscreen bool

Set to true to present the web view in fullscreen. Defaults to false.

Promise

Promise that is fulfilled when the presented web view is dismissed. The promise carries no value.

Waits for the web view to load.

waitForLoad(): Promise<any>

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.

Promise<any>

Promise that is fulfilled when the web view has finished the active load.