@eryx/webview Module

JSON

Summary

Classes

WebViewHandle:navigate(url: string)()
WebViewHandle:navigateToString(html: string)()
WebViewHandle:postMessage(event: string, data: { [any]: any })()
WebViewHandle:executeScript(script: string)()
WebViewHandle:addInitScript(script: string)()
WebViewHandle:setTitle(title: string)()
WebViewHandle:resize(width: number, height: number)()
WebViewHandle:move(x: number, y: number)()
WebViewHandle:onMessage(callback: ((event: string, data: { [any]: any }) → ()))()
WebViewHandle:onClose(callback: (() → ()))()
WebViewHandle:setResizable(resizable: boolean)()
WebViewHandle:setBorderless(borderless: boolean)()
WebViewHandle:setTransparent(transparent: boolean)()
WebViewHandle:setOpacity(alpha: number)()

Functions

API Reference

Classes

WebViewHandle

A handle to a WebView2 window.

Properties

WebViewHandle:navigate

Navigates the webview to a URL.

WebViewHandle:navigate(url: string)()

Parameters

url: string

-- The URL to navigate to.

WebViewHandle:navigateToString

Renders raw HTML content in the webview.

WebViewHandle:navigateToString(html: string)()

Parameters

html: string

-- The HTML string to display.

WebViewHandle:postMessage

Sends data to the web content. Received via window.chrome.webview.addEventListener('message', ...) in JavaScript.

WebViewHandle:postMessage(event: string, data: { [any]: any })()

Parameters

event: string

-- The event category.

data: { [any]: any }

-- The data to send.

WebViewHandle:executeScript

Executes a JavaScript snippet inside the webview. Fire-and-forget; does not return a result.

WebViewHandle:executeScript(script: string)()

Parameters

script: string

-- The JavaScript code to execute.

WebViewHandle:addInitScript

Add a JavaScript snippet to run before any page loads

WebViewHandle:addInitScript(script: string)()

Parameters

script: string

-- The JavaScript code to execute.

WebViewHandle:setTitle

Changes the window title.

WebViewHandle:setTitle(title: string)()

Parameters

title: string

-- The new window title.

WebViewHandle:show

Shows the window (e.g. after creating with hidden = true).

WebViewHandle:show()()

WebViewHandle:hide

Hides the window without destroying it.

WebViewHandle:hide()()

WebViewHandle:resize

Resizes the window.

WebViewHandle:resize(width: number, height: number)()

Parameters

width: number

-- New width in pixels.

height: number

-- New height in pixels.

WebViewHandle:move

Moves the window to an absolute screen position.

WebViewHandle:move(x: number, y: number)()

Parameters

x: number

-- X coordinate in pixels.

y: number

-- Y coordinate in pixels.

WebViewHandle:center

Centers the window on the monitor it currently occupies.

WebViewHandle:center()()

WebViewHandle:onMessage

Registers a callback for messages sent from web content via window.chrome.webview.postMessage(...).

WebViewHandle:onMessage(callback: ((event: string, data: { [any]: any }) → ()))()

Parameters

callback: ((event: string, data: { [any]: any }) → ())

-- Called with the message string each time a message is received.

WebViewHandle:onClose

Registers a callback invoked when the user attempts to close the window (e.g. clicks the X button). While a callback is set, the default close is suppressed; call handle:destroy() from the callback to actually close the window.

WebViewHandle:onClose(callback: (() → ()))()

Parameters

callback: (() → ())

-- Called when a close is requested.

WebViewHandle:setResizable

Toggles whether the window can be resized by the user.

WebViewHandle:setResizable(resizable: boolean)()

Parameters

resizable: boolean

-- true to allow resizing, false to prevent it.

WebViewHandle:setBorderless

Toggles borderless mode. When borderless, the window has no title bar or borders (WS_POPUP style).

WebViewHandle:setBorderless(borderless: boolean)()

Parameters

borderless: boolean

-- true for borderless, false to restore the standard window frame.

WebViewHandle:setTransparent

Toggles per-pixel window transparency at runtime. When enabled, any area without a CSS background (or with a semi-transparent one) will show through to windows beneath.

WebViewHandle:setTransparent(transparent: boolean)()

Parameters

transparent: boolean

-- true for transparent, false for opaque.

WebViewHandle:setOpacity

Sets the overall window opacity using a layered window.

WebViewHandle:setOpacity(alpha: number)()

Parameters

alpha: number

-- Opacity from 0.0 (fully transparent) to 1.0 (fully opaque).

WebViewHandle:destroy

Destroys the window and releases all resources. The handle becomes invalid after this call.

WebViewHandle:destroy()()

Functions

webview.create

⚠ Yields

Creates a new WebView2 window. Yields until the WebView2 runtime is fully initialised.

webview.create(options: WebViewOptions?)WebViewHandle

Parameters

options: WebViewOptions?

-- Optional configuration for the window.

Returns

A handle to control the created window.

Types

WebViewOptions

Options table for creating a new WebView window.

title: string?

Window title. Defaults to "WebView".

width: number?

Window width in pixels. Defaults to 1200.

height: number?

Window height in pixels. Defaults to 900.

url: string?

Initial URL to navigate to.

borderless: boolean?

If true, the window has no title bar or borders (WS_POPUP style). Defaults to false.

resizable: boolean?

If false, the window cannot be resized by the user. Defaults to true.

hidden: boolean?

If true, the window is not shown after creation. Call handle:show() to reveal it. Defaults to false.

transparent: boolean?

If true, enables per-pixel window transparency. Areas with no CSS background (or semi-transparent backgrounds) will show through to whatever is underneath. Automatically implies borderless = true (the DWM title bar is always opaque). Defaults to false.