Skip to content

WebView

Display web content in a web view

WebView allows loading and displaying web pages, HTML content, and local files.

Use WebView to:

Note

Not available in Widget

Examples

javascript
await WebView.loadURL("https://example.com");
javascript
let html = "<h1>Hello World</h1>";
await WebView.loadHTML(html);
javascript
let webView = new WebView();
await webView.loadURL("https://example.com");
let html = await webView.getHTML();
await webView.present();

Properties

shouldAllowRequest

  • Type: JSValue

Request filtering callback

Set a function to control which requests are allowed. Return true to allow, false to block.

javascript
webView.shouldAllowRequest = (url) => !url.includes("ads")

Methods

loadURLInstance

Load a URL (instance method)

typescript
loadURLInstance(): void

Example:

javascript
await webView.loadURL("https://example.com")

loadRequestInstance

Load a Request object (instance method)

typescript
loadRequestInstance(): void

Example:

javascript
await webView.loadRequest(request)

loadHTMLInstance

Load HTML content (instance method)

typescript
loadHTMLInstance(): void

Example:

javascript
await webView.loadHTML(html, baseURL)

loadFileInstance

Load a local file (instance method)

typescript
loadFileInstance(): void

Example:

javascript
await webView.loadFile(path)

evaluateJavaScript

Execute JavaScript in the web view

typescript
evaluateJavaScript(javaScript, useCallback, callback): void
  • javaScript - JavaScript code to execute
  • useCallback - Whether to use completion callback mode
  • callback - Result callback

Returns: Result of the JavaScript execution

Example:

javascript
let result = await webView.evaluateJavaScript("document.title")

getHTML

Get the current HTML content

Returns the full HTML of the current page.

typescript
getHTML(): void

Example:

javascript
let html = await webView.getHTML()

present

Present the web view

typescript
present(fullscreen): void
  • fullscreen - Whether to present fullscreen

Example:

javascript
await webView.present(true)

waitForLoad

Wait for page load to complete

typescript
waitForLoad(): void

Example:

javascript
await webView.waitForLoad()

loadHTML

Load and present HTML content

typescript
static loadHTML(html, baseURL, preferredSize, fullscreen, callback): void
  • html - HTML string to display
  • baseURL - Optional base URL for relative resources
  • preferredSize - Optional preferred size
  • fullscreen - Whether to present fullscreen
  • callback - Completion callback

Example:

javascript
await WebView.loadHTML(html, baseURL, size, fullscreen)

loadFile

Load and present a local file

typescript
static loadFile(fileURL, preferredSize, fullscreen, callback): void
  • fileURL - Path to local HTML file
  • preferredSize - Optional preferred size
  • fullscreen - Whether to present fullscreen
  • callback - Completion callback

Example:

javascript
await WebView.loadFile(path, size, fullscreen)

loadURL

Load and present a URL

typescript
static loadURL(url, preferredSize, fullscreen, callback): void
  • url - URL to load
  • preferredSize - Optional preferred size
  • fullscreen - Whether to present fullscreen
  • callback - Completion callback

Example:

javascript
await WebView.loadURL("https://example.com")