A handle to a WebView2 window.
@eryx/webview Module
JSON
Summary
Classes
Functions
API Reference
Classes
WebViewHandle
Properties
WebViewHandle:postMessage
Sends data to the web content. Received via window.chrome.webview.addEventListener('message', ...) in JavaScript.
Parameters
-- The event category.
-- The data to send.
WebViewHandle:executeScript
Executes a JavaScript snippet inside the webview. Fire-and-forget; does not return a result.
Parameters
-- The JavaScript code to execute.
WebViewHandle:addInitScript
Add a JavaScript snippet to run before any page loads
Parameters
-- The JavaScript code to execute.
WebViewHandle:setTitle
Changes the window title.
Parameters
-- The new window title.
WebViewHandle:show
Shows the window (e.g. after creating with hidden = true).
WebViewHandle:hide
Hides the window without destroying it.
WebViewHandle:resize
Resizes the window.
Parameters
-- New width in pixels.
-- New height in pixels.
WebViewHandle:move
Moves the window to an absolute screen position.
Parameters
-- X coordinate in pixels.
-- Y coordinate in pixels.
WebViewHandle:center
Centers the window on the monitor it currently occupies.
WebViewHandle:onMessage
Registers a callback for messages sent from web content via window.chrome.webview.postMessage(...).
Parameters
-- 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.
Parameters
-- Called when a close is requested.
WebViewHandle:setResizable
Toggles whether the window can be resized by the user.
Parameters
-- 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).
Parameters
-- 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.
Parameters
-- true for transparent, false for opaque.
WebViewHandle:setOpacity
Sets the overall window opacity using a layered window.
Parameters
-- 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.
Functions
webview.create
⚠ Yields
Creates a new WebView2 window. Yields until the WebView2 runtime is fully initialised.
Parameters
-- Optional configuration for the window.
Returns
A handle to control the created window.
Types
WebViewOptions
Options table for creating a new WebView window.
Window title. Defaults to "WebView".
Window width in pixels. Defaults to 1200.
Window height in pixels. Defaults to 900.
Initial URL to navigate to.
If true, the window has no title bar or borders (WS_POPUP style). Defaults to false.
If false, the window cannot be resized by the user. Defaults to true.
If true, the window is not shown after creation. Call handle:show() to reveal it. Defaults to false.
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.