wry
stableWebView plugin for embedding a browser engine in a native window. Provides the WebView class for loading URLs or HTML, evaluating JavaScript, handling IPC messages, and controlling the view.
use plugin wry::{WebView.new, WebView._attach, WebView.pump, …} Functions (18)
- WebView.new Create a WebView in a native window
- WebView._attach Attach a pre-staged WebView to the plugin
- WebView.pump Drain pending GTK events (Linux only)
- load_url Navigate to a URL
- load_html Load HTML content directly
- url Get the current URL
- evaluate_script Execute JavaScript in the WebView
- set_visible Show or hide the WebView
- zoom Set the zoom level
- open_devtools Open the developer tools panel
- close_devtools Close the developer tools panel
- is_devtools_open Check if devtools are open
- print Print the current page
- set_bounds Set the WebView position and size
- set_background_color Set the background color
- focus Give focus to the WebView
- poll_ipc Drain pending IPC messages from JavaScript
- close Close and destroy the WebView
Create a WebView in a native window
Creates a WebView embedded in a native window. The config table must contain either window (a window.native_handle() table from the winit plugin) or hwnd (a Win32 HWND integer, Windows-only legacy). Optionally include url or html to load initial content.
use plugin winit::{Window, EventLoop}
use plugin wry::{WebView}
let win = Window.new(#{"title": "Browser", "width": 1024, "height": 768})
let el = EventLoop.new()
el.run(fn(event) {
if event["event"] == "window_created" {
let wv = WebView.new(#{"window": win.native_handle(), "url": "https://example.com"})
}
if event["event"] == "redraw_requested" {
WebView.pump()
}
})
Attach a pre-staged WebView to the plugin
Attaches a WebView that was staged by the host application using stage_webview(). Pass the integer stage ID returned by the host. Used for advanced integration where the host builds the WebView before Zolo code runs.
Drain pending GTK events (Linux only)
On Linux, drains pending GTK events so the webkit2gtk WebView can render and respond to input. Should be called on every redraw_requested event. Safe to call on all platforms — no-op on Windows and macOS.
use plugin wry::{WebView}
// Inside the EventLoop callback:
if event["event"] == "redraw_requested" {
WebView.pump()
}
Navigate to a URL
Navigates the WebView to the specified URL.
use plugin wry::{WebView}
let wv = WebView.new(#{"window": win.native_handle(), "url": "about:blank"})
wv.load_url("https://zoloist.dev")
Load HTML content directly
Loads an HTML string directly into the WebView, replacing any currently loaded page.
use plugin wry::{WebView}
let html = "<h1>Hello from Zolo</h1><script>window.ipc.postMessage('ready')</script>"
wv.load_html(html)
Get the current URL
Returns the current URL of the WebView.
Execute JavaScript in the WebView
Executes a JavaScript string in the WebView's main frame. Results are not returned synchronously; use IPC (postMessage) for bidirectional communication.
use plugin wry::{WebView}
wv.evaluate_script("document.body.style.background = '#ff0'")
wv.evaluate_script("window.ipc.postMessage(JSON.stringify({event: 'ready'}))")
Show or hide the WebView
Shows (true) or hides (false) the WebView.
Set the zoom level
Sets the zoom level. 1.0 is normal size, 2.0 doubles the content, 0.5 halves it.
Open the developer tools panel
Opens the browser developer tools panel for this WebView.
Close the developer tools panel
Closes the developer tools panel.
Check if devtools are open
Returns true if the developer tools panel is currently open.
Print the current page
Opens the print dialog for the current page.
Set the WebView position and size
Sets the position and size of the WebView within its parent window. Config table: {x, y, width, height} in logical pixels.
use plugin wry::{WebView}
wv.set_bounds(#{"x": 0, "y": 0, "width": 800, "height": 600})
Set the background color
Sets the WebView background color. Config table: {r, g, b, a} as integers 0–255.
use plugin wry::{WebView}
wv.set_background_color(#{"r": 30, "g": 30, "b": 30, "a": 255})
Give focus to the WebView
Gives keyboard focus to the WebView.
Drain pending IPC messages from JavaScript
Drains and returns all pending IPC messages sent from JavaScript via window.ipc.postMessage(msg). Returns a 1-indexed table of strings.
use plugin wry::{WebView}
// Inside the EventLoop callback on redraw_requested:
let messages = wv.poll_ipc()
print("messages: {#messages}")
Close and destroy the WebView
Destroys the WebView and frees all associated resources. Subsequent method calls on the handle will error.