Skip to content

doceazedo/godot_wry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

68 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Godot WRY

WRY is a cross-platform webview rendering library. This extension allows you to use the native webview in Godot to build browsers and GUIs with HTML, CSS and JavaScript.

Warning

This extension is a work in progress! Expect bugs, report issues, and feel free to contribute.

✨ Features

  • πŸƒ Use the native system native webview (no extra dependencies!)
  • 🌎 Load website URLs and local res:// files
  • 🧩 JavaScript ⇔ GDScript code integration
  • πŸš₯ Mouse/keyboard input events forwarding

⛹️ Demo

Demo game UI available at "examples/character_creator_ui_demo".

πŸ“Έ Other screenshots

πŸ’Ύ Downloading

Asset Library

You can download the extension directly on the Godot Asset Library or by navigating to the "AssetLib" tab in the editor and searching for "wry".

Releases

Alternatively, you can go to the Releases page, download the latest ZIP (not the source code) and import it manually into your project.

🎯 Supported platforms

Platform Support Web engine
Windows (10, 11) βœ… Supported WebView2 (Chromium)
Mac (Apple Silicon) βœ… Supported WebKit
Linux 🚧 Work in progress WebKitGTK
Android ⏳ Planned Android WebView (Chromium)
iOS ⏳ Planned WebKit
Browser/HTML5 ⏳ Planned β€”

Linux

WebKitGTK is required for WRY to function on Linux. The package name may differ based on the operating system and Linux distribution.

Android/iOS

WRY itself already has mobile support. Contributions to add Android/iOS support in this extension are welcome!

πŸš€ Getting started

After installing the extension, you will now be able to see the WebView node inside Node β†’ CanvasItem β†’ Control when creating a new node. You can edit it's properties and layout as you wish.

"Create new node" window

WebView inspector

⚑ API usage

Interop between Webview and Godot

Godot and the webview can exchange messages with each other. This is useful for updating the UI data, or triggering game actions when interacting with the UI.

πŸ’‘ Example: you can send a play message on a HTML button click, then Godot can listen for that message and start the game.

Sending messages from Godot to the webview:

$WebView.post_message("Hello from Godot!")

Sending messages from JavaScript to Godot:

window.ipc.postMessage("Hello from JavaScript!");

Receiving messages in Godot using the ipc_message signal:

func _on_web_view_ipc_message(message):
	print("Just got a message from the webview: %s" % message)

Receiving messages in JavaScript using an event listener:

document.addEventListener("message", (event) => {
  console.log("Just got a message from Godot:", event.detail);
});

Evaluate JavaScript

You can also evaluate a JS script by using the eval API:

# Log to the webview devtools
$WebView.eval("console.log(Math.PI)");

By using the interoperability API, you could even process asynchronous tasks with JavaScript, then get the result in GDScript later:

func _on_button_pressed():
	$WebView.eval("
		const resp = await fetch('https://httpbin.org/ip');
		const data = await resp.json();
		ipc.postMessage(JSON.stringify(data));
	")

func _on_web_view_ipc_message(message):
	var data = JSON.parse_string(message)
	print("Your IP address is: %s" % data.origin)

❌ Caveats

  • The webview is rendered directly within the window. This prevents rendering on 3D meshes and is always rendered on top of the game.
  • Using the system's native webview can lead to platform inconsistencies, like how a site behaves differently in Chrome vs. Safari.
  • This extension doesn't check dependencies, so it's up to you to ensure they're installed and handle the missing libraries.

🀝 Contribute

Your help is most welcome regardless of form! Check out the CONTRIBUTING.md file for all ways you can contribute to the project. For example, suggest a new feature, report a problem/bug, submit a pull request, or simply use the project and comment your experience.

See the ROADMAP.md file for an idea of how the project should evolve.

🎫 License

The Godot WRY extension is licensed under MIT. WRY is licensed under Apache-2.0/MIT.

πŸ§ͺ Similar projects

Below is a list of interesting similar projects:

  • gdcef β€” Open-source, powered by Chromium
  • Godot-HTML β€” Open-source, powered by Ultralight (WebKit)
  • godot-webview β€” Commercial, powered by QT (Chromium)