Skip to content

wry

stable

WebView 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, …}
18 functions Web
/ filter jk navigate Esc clear
Functions (18)
  1. WebView.new Create a WebView in a native window
  2. WebView._attach Attach a pre-staged WebView to the plugin
  3. WebView.pump Drain pending GTK events (Linux only)
  4. load_url Navigate to a URL
  5. load_html Load HTML content directly
  6. url Get the current URL
  7. evaluate_script Execute JavaScript in the WebView
  8. set_visible Show or hide the WebView
  9. zoom Set the zoom level
  10. open_devtools Open the developer tools panel
  11. close_devtools Close the developer tools panel
  12. is_devtools_open Check if devtools are open
  13. print Print the current page
  14. set_bounds Set the WebView position and size
  15. set_background_color Set the background color
  16. focus Give focus to the WebView
  17. poll_ipc Drain pending IPC messages from JavaScript
  18. 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.

enespt-br