This document provides a detailed reference for the Ring WebView library API.
The WebView class is the core of the library, providing all the necessary methods to create and manage a webview window.
Creates a new WebView instance. The constructor is now parameter-less and uses a global configuration list for setup.
The WebView class relies on a global list named aWebViewConfig for its initial settings. You can modify this list before creating a WebView instance to customize its behavior.
aWebViewConfig[:debug]: (Boolean) Set totrue(default) to enable debug mode.aWebViewConfig[:window]: (Pointer) A native window handle to use as the parent. Defaults toNULL.
Note: When a
WebViewinstance is created, theinit()method is called automatically. As part of this process,bindMany(NULL)is invoked. If a global list namedaBindListexists and is a valid list, all bindings defined inaBindListwill be registered automatically during initialization.
Runs the main event loop for the webview. This is a blocking call that will not return until the webview window is closed. It also calls destroy() automatically when the loop ends.
Destroys the webview instance and frees all associated resources. After calling this, the WebView object becomes unusable.
Stops the webview event loop and closes the window. This provides a way to programmatically close the webview window from Ring code.
Sets the title of the webview window.
title: (String) The title to display.
Sets the size of the webview window.
width: (Number) The width of the window.height: (Number) The height of the window.hint: (Constant) A size hint that controls the resizing behavior. See Size Hints below.
Navigates the webview to a new URL.
url: (String) The URL to load.
Sets the HTML content of the webview directly.
html: (String) The HTML content to display.
Binds a Ring function or a Ring object's methods to JavaScript.
- Function Binding:
bind(jsName, ringFuncName)jsName(String): The name of the function to expose in JavaScript (e.g.,myFunc).ringFuncName(String | FuncPtr): The name of the Ring function or a function pointer.
- Object Method Binding:
bind(oObject, aMethods)oObject(Object): The Ring object instance whose methods will be bound.aMethods(List): A list of method pairs to bind. Each pair should be a list containing two strings:["jsFunctionName", "objectMethodName"].
Binds multiple Ring functions or object methods to JavaScript in a single call.
aList: (List, optional) A list where each item defines a binding.- For function binding, an item is a list of two elements:
["jsFunctionName", "ringFunctionName"]. - For object method binding, an item is a list containing the object and a list of method pairs:
[oObject, [["jsMethod1", "ringMethod1"], ...]]. - If
aListisNULL, it uses the globalaBindList.
- For function binding, an item is a list of two elements:
Removes a previously created JavaScript-to-Ring binding. After unbinding, calls from JavaScript to jsName will no longer invoke the Ring function.
jsName: (String) The name of the JavaScript function to unbind.
Injects and executes JavaScript code when the webview is first initialized or when a new HTML page is loaded (e.g., after setHtml() or navigate()). This is useful for setting up global JavaScript variables or functions before the page content fully loads.
js: (String) The JavaScript code to execute.
Evaluates a string of JavaScript code in the currently loaded webview content. This is typically used to manipulate the DOM or trigger JavaScript functions from Ring after the page has loaded.
js: (String) The JavaScript code to evaluate.
Dispatches a Ring code snippet to be executed on the main UI thread of the webview. This is crucial for performing UI-related operations from Ring functions that might be running on a different thread (e.g., callbacks).
cCode: (String) The Ring code to execute. This should typically be a function call (e.g.,"myFunction()") that performs UI updates.
Returns a native handle to the webview window. The type of handle returned depends on the underlying platform.
Returns a native handle of a specific kind, providing more granular access to the underlying webview components.
kind: (Constant) The type of handle to retrieve. See Native Handle Kinds below.
Returns a result back to a JavaScript function that initiated a bind() call. This allows Ring to send data or acknowledge completion to the JavaScript frontend.
id: (Number) The callback ID received from thebind()call (first argument to the Ring function).result: (Number) The status code for the operation. UseWEBVIEW_ERROR_OKfor success. OtherWEBVIEW_ERROR_constants can indicate specific issues.json: (String) A JSON string containing the data to return to JavaScript. This will be the resolved value of the JavaScriptPromise.
Checks if the webview instance has already been destroyed and its resources released.
Platform Limitations (Linux/FreeBSD with GTK4/Wayland):
setPosition(),getPosition(): Not supported (Wayland security model)setAlwaysOnTop(): Not supported (no GTK4 equivalent)setClickThrough(): Not supported (Windows only)These methods return
0(failure) on unsupported platforms. Windows and macOS support all features.
Enables or disables window decorations (title bar, borders).
decorated: (Boolean)trueto show decorations,falsefor frameless window.- Returns:
1on success,0on failure.
Sets the window transparency level.
opacity: (Number) Value between0.0(fully transparent) and1.0(fully opaque).- Returns:
1on success,0on failure.
Sets whether the window should stay above all other windows.
onTop: (Boolean)trueto keep on top,falsefor normal behavior.- Returns:
1on success,0on failure.
Minimizes the window to the taskbar/dock.
- Returns:
1on success,0on failure.
Maximizes the window to fill the screen.
- Returns:
1on success,0on failure.
Restores the window from minimized or maximized state.
- Returns:
1on success,0on failure.
Checks if the window is currently maximized.
- Returns:
1if maximized,0if not.
Initiates window dragging. Call this from a mouse-down event handler on your custom title bar.
- Returns:
1on success,0on failure.
Note: Works on all platforms (Windows, Linux/GTK4, macOS).
Moves the window to the specified screen coordinates.
x: (Number) The x-coordinate.y: (Number) The y-coordinate.- Returns:
1on success,0on failure.
Gets the current window position.
- Returns: A list
[x, y]containing the window coordinates.
Gets the current window size.
- Returns: A list
[width, height]containing the window dimensions.
Brings the window to the front and gives it focus.
- Returns:
1on success,0on failure.
Hides the window without destroying it.
- Returns:
1on success,0on failure.
Shows a previously hidden window.
- Returns:
1on success,0on failure.
Initiates window resizing from the specified edge. Call this from a mouse-down event handler on your custom resize borders.
edge: (Constant) The edge to resize from. See Edge Constants below.- Returns:
1on success,0on failure.
Note: Not supported on macOS. Works on Windows and Linux/GTK4.
Enables or disables fullscreen mode.
fullscreen: (Boolean)truefor fullscreen,falsefor windowed mode.- Returns:
1on success,0on failure.
Checks if the window is currently in fullscreen mode.
- Returns:
1if fullscreen,0if windowed.
Enables or disables window resizing by the user.
resizable: (Boolean)trueto allow resizing,falseto prevent it.- Returns:
1on success,0on failure.
Checks if the window is currently resizable.
- Returns:
1if resizable,0if not.
Sets the minimum size constraint for the window.
width: (Number) Minimum width in pixels.height: (Number) Minimum height in pixels.- Returns:
1on success,0on failure.
Sets the maximum size constraint for the window.
width: (Number) Maximum width in pixels.height: (Number) Maximum height in pixels.- Returns:
1on success,0on failure.
Sets the background color of the webview. Useful for transparent windows or matching your app's theme before content loads.
r: (Number) Red component (0-255).g: (Number) Green component (0-255).b: (Number) Blue component (0-255).a: (Number) Alpha component (0-255). 0 = transparent, 255 = opaque.- Returns:
1on success,0on failure.
Navigates back in the browsing history.
- Returns:
1on success,0on failure.
Navigates forward in the browsing history.
- Returns:
1on success,0on failure.
Reloads the current page.
- Returns:
1on success,0on failure.
Gets the URL of the currently loaded page.
- Returns: (String) The current URL, or empty string if not available.
Gets the title of the currently loaded page.
- Returns: (String) The page title, or empty string if not available.
Shows or hides the developer tools (inspector).
enabled: (Boolean)trueto show dev tools,falseto hide.- Returns:
1on success,0on failure.
Platform Notes:
- Windows: Dev tools open in a separate window.
- Linux/WebKitGTK: Dev tools open in a separate window.
- macOS: Dev tools open in a separate window (requires debug mode).
Enables or disables the default browser context menu (right-click menu).
enabled: (Boolean)trueto allow context menu,falseto suppress it.- Returns:
1on success,0on failure.
Note: When disabled, you can implement your own custom context menu via JavaScript.
Sets the window icon from a file.
iconPath: (String) Path to the icon file (PNG, ICO, etc.).- Returns:
1on success,0on failure.
Platform Notes:
- Windows: Supports .ico files.
- Linux/GTK: Supports PNG and other common image formats.
Checks if the window currently has focus.
- Returns:
1if focused,0if not.
Checks if the window is currently visible.
- Returns:
1if visible,0if hidden.
Programmatically closes the window.
- Returns:
1on success,0on failure.
Forces dark mode for the application UI.
enabled: (Boolean)trueto force dark mode,falsefor system default.- Returns:
1on success,0on failure.
Platform Notes: Currently only supported on Linux with libadwaita.
Checks if dark mode is forced.
- Returns:
1if dark mode is forced,0if not.
Gets information about all connected monitors/screens.
- Returns: A list of lists. Each inner list contains:
[1]: Screen/monitor name (String)[2]: X position (Number)[3]: Y position (Number)[4]: Width in pixels (Number)[5]: Height in pixels (Number)
Enables or disables click-through mode (mouse events pass through the window).
enabled: (Boolean)trueto enable click-through,falseto disable.- Returns:
1on success,0on failure.
Platform Notes: Currently only supported on Windows.
Checks if click-through mode is enabled.
- Returns:
1if enabled,0if not.
Event callbacks allow you to respond to various window and webview events. Pass the name of a Ring function to be called when the event occurs.
Sets a callback to be called when the window close is requested.
callback: (String) Name of the Ring function to call.- Callback signature:
func myCallback(cData)-cDatais empty string. - Returns:
1on success,0on failure.
Platform Notes: Currently implemented on Linux/FreeBSD (GTK4). Windows/macOS pending.
Sets a callback to be called when the window is resized.
callback: (String) Name of the Ring function to call.- Callback signature:
func myCallback(cData)-cDatacontains size info. - Returns:
1on success,0on failure.
Platform Notes: Currently implemented on Linux/FreeBSD (GTK4). Windows/macOS pending.
Sets a callback to be called when the window gains or loses focus.
callback: (String) Name of the Ring function to call.- Callback signature:
func myCallback(cFocused)-cFocusedis"true"or"false". - Returns:
1on success,0on failure.
Platform Notes: Currently implemented on Linux/FreeBSD (GTK4). Windows/macOS pending.
Sets a callback to be called when the DOM is ready (page finished loading).
callback: (String) Name of the Ring function to call.- Callback signature:
func myCallback(cData)-cDatais empty string. - Returns:
1on success,0on failure.
Platform Notes: Currently implemented on Linux/FreeBSD (GTK4). Windows/macOS pending.
Sets a callback to be called when a page load starts or finishes.
callback: (String) Name of the Ring function to call.- Callback signature:
func myCallback(cState)-cStateis"started"or"finished". - Returns:
1on success,0on failure.
Platform Notes: Currently implemented on Linux/FreeBSD (GTK4). Windows/macOS pending.
Sets a callback to be called when navigation occurs.
callback: (String) Name of the Ring function to call.- Callback signature:
func myCallback(cUrl)-cUrlis the new URL. - Returns:
1on success,0on failure.
Platform Notes: Currently implemented on Linux/FreeBSD (GTK4). Windows/macOS pending.
Sets a callback to be called when the page title changes.
callback: (String) Name of the Ring function to call.- Callback signature:
func myCallback(cTitle)-cTitleis the new page title. - Returns:
1on success,0on failure.
Platform Notes: Currently implemented on Linux/FreeBSD (GTK4). Windows/macOS pending.
These functions are available globally and do not require a WebView instance.
Returns a string representing the version of the underlying WebView library.
The following constants are available for use with the WebView class methods and global functions.
WEBVIEW_HINT_NONE: The window can be resized freely.WEBVIEW_HINT_MIN: The window has a minimum size, but can be enlarged.WEBVIEW_HINT_MAX: The window has a maximum size, but can be made smaller.WEBVIEW_HINT_FIXED: The window size cannot be changed by the user.
WEBVIEW_NATIVE_HANDLE_KIND_UI_WINDOW: Represents the main window handle.WEBVIEW_NATIVE_HANDLE_KIND_UI_WIDGET: Represents a widget or view handle within the window.WEBVIEW_NATIVE_HANDLE_KIND_BROWSER_CONTROLLER: Represents the underlying browser engine controller.
These constants are used as the result parameter in wreturn().
WEBVIEW_ERROR_OK: Operation completed successfully.WEBVIEW_ERROR_UNSPECIFIED: An unspecified error occurred.WEBVIEW_ERROR_INVALID_ARGUMENT: A function was called with an invalid argument.WEBVIEW_ERROR_INVALID_STATE: The webview is in an invalid state for the requested operation.WEBVIEW_ERROR_CANCELED: The operation was canceled.WEBVIEW_ERROR_MISSING_DEPENDENCY: A required dependency is missing.WEBVIEW_ERROR_DUPLICATE: An attempt was made to create a duplicate resource.WEBVIEW_ERROR_NOT_FOUND: A requested resource was not found.
WEBVIEW_VERSION_MAJOR: The major version number (e.g., 0).WEBVIEW_VERSION_MINOR: The minor version number (e.g., 12).WEBVIEW_VERSION_PATCH: The patch version number (e.g., 0).
Used with startResize(edge) to specify which edge or corner to resize from.
WEBVIEW_EDGE_TOP: Resize from top edge.WEBVIEW_EDGE_BOTTOM: Resize from bottom edge.WEBVIEW_EDGE_LEFT: Resize from left edge.WEBVIEW_EDGE_RIGHT: Resize from right edge.WEBVIEW_EDGE_TOP_LEFT: Resize from top-left corner.WEBVIEW_EDGE_TOP_RIGHT: Resize from top-right corner.WEBVIEW_EDGE_BOTTOM_LEFT: Resize from bottom-left corner.WEBVIEW_EDGE_BOTTOM_RIGHT: Resize from bottom-right corner.