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
await WebView.loadURL("https://example.com");let html = "<h1>Hello World</h1>";
await WebView.loadHTML(html);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.
webView.shouldAllowRequest = (url) => !url.includes("ads")Methods
loadURLInstance
Load a URL (instance method)
loadURLInstance(): voidExample:
await webView.loadURL("https://example.com")loadRequestInstance
Load a Request object (instance method)
loadRequestInstance(): voidExample:
await webView.loadRequest(request)loadHTMLInstance
Load HTML content (instance method)
loadHTMLInstance(): voidExample:
await webView.loadHTML(html, baseURL)loadFileInstance
Load a local file (instance method)
loadFileInstance(): voidExample:
await webView.loadFile(path)evaluateJavaScript
Execute JavaScript in the web view
evaluateJavaScript(javaScript, useCallback, callback): voidjavaScript- JavaScript code to executeuseCallback- Whether to use completion callback modecallback- Result callback
Returns: Result of the JavaScript execution
Example:
let result = await webView.evaluateJavaScript("document.title")getHTML
Get the current HTML content
Returns the full HTML of the current page.
getHTML(): voidExample:
let html = await webView.getHTML()present
Present the web view
present(fullscreen): voidfullscreen- Whether to present fullscreen
Example:
await webView.present(true)waitForLoad
Wait for page load to complete
waitForLoad(): voidExample:
await webView.waitForLoad()loadHTML
Load and present HTML content
static loadHTML(html, baseURL, preferredSize, fullscreen, callback): voidhtml- HTML string to displaybaseURL- Optional base URL for relative resourcespreferredSize- Optional preferred sizefullscreen- Whether to present fullscreencallback- Completion callback
Example:
await WebView.loadHTML(html, baseURL, size, fullscreen)loadFile
Load and present a local file
static loadFile(fileURL, preferredSize, fullscreen, callback): voidfileURL- Path to local HTML filepreferredSize- Optional preferred sizefullscreen- Whether to present fullscreencallback- Completion callback
Example:
await WebView.loadFile(path, size, fullscreen)loadURL
Load and present a URL
static loadURL(url, preferredSize, fullscreen, callback): voidurl- URL to loadpreferredSize- Optional preferred sizefullscreen- Whether to present fullscreencallback- Completion callback
Example:
await WebView.loadURL("https://example.com")