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.

new WebView()

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


+loadHTML

Loads HTML and renders it.

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

Parameters

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.

Return value

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


+loadFile

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.

Parameters

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.

Return value

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


+loadURL

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.

Parameters

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.

Return value

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


-loadURL

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.

Parameters

url
string
URL to load into the web view.

Return value

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


-loadRequest

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.

Parameters

request
Request
Request to load into the web view.

Return value

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


-loadHTML

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.

Parameters

html
string
HTML to load into the web view.

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

Return value

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


-loadFile

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.

Parameters

fileURL
string
URL of the file to load and render.

Return value

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


-evaluateJavaScript

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.

Parameters

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.

Return value

Promise
Promise that carries the result of evaluating the JavaScript.


-getHTML

Reads and returns HTML from the loaded website.

getHTML(): Promise<any>

Return value

Promise
Promise that carries the HTML of the loaded website.


-present

Presents the web view.

present(fullscreen: bool): Promise

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

Parameters

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

Return value

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


-waitForLoad

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.

Return value

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