Passer au contenu principal
Version: latest - a1.73.x ⚖️

🖥️ WebUI

Class for spawning a dynamic Web Browser.


💂Authority
This class can only be spawned on 🟧 Client side.
👪Inheritance
This class shares methods and events from .
🧑‍💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

tip

Our WebUI implementation is built using the last versions of Chromium Embedded Framework.

tip

To access the in-browser remote debugging head over to http://localhost:9222 when you are connected to a server.

Proprietary Codecs

Proprietary Codecs like MP3 and AAC are not supported on public CEF builds. We recommend converting your media files to WEBM or OGG.

🎒 Examples

Client/Index.lua
-- Loading a local file
local my_ui = WebUI(
"Awesome UI", -- Name
"file://UI/index.html", -- Path relative to this package (Client/)
WidgetVisibility.Visible -- Is Visible on Screen
)

-- Loading a Web URL
local my_browser = WebUI(
"Awesome Site", -- Name
"https://nanos.world", -- Web's URL
WidgetVisibility.Visible -- Is Visible on Screen
)

-- Loading a local file from other package
local my_ui = WebUI(
"Awesome Other UI", -- Name
"file://other-package/Client/UI/index.html",
WidgetVisibility.Visible -- Is Visible on Screen
)

Using a WebUI as Mesh Material

Client/Index.lua
-- Spawns a WebUI with is_visible = false, is_transparent = false, auto_resize = false and size of 500x500
local my_ui = WebUI("Awesome Site", "https://nanos.world", false, false, false, 500, 500)

-- Spawns a StaticMesh (can be any mesh)
local static_mesh = StaticMesh(Vector(0, 0, 100), Rotator(), "nanos-world::SM_Cube")

-- Sets the mesh material to use the WebUI
static_mesh:SetMaterialFromWebUI(my_ui)

Communication entre Lua et JS (WebUI)

Client/Index.lua
local my_ui = WebUI("Awesome UI", "file://UI/index.html")

local param1 = 123
local param2 = "hello"

-- Calls a JS event
my_ui:CallEvent("MyEvent", param1, param2)

-- Subscribes to receive JS events
my_ui:Subscribe("MyAnswer", function(param1)
Console.Log("Received back! %s", param1)
-- Will output 'Received back! Hey there!'
end)
script.js
// Register for "MyEvent" from Lua
Events.Subscribe("MyEvent", function(param1, param2) {
console.log("Triggered! " + param1 + " " + param2);
// Will output 'Triggered! 123 hello'

// Triggers "MyAnswer" on Lua
Events.Call("MyAnswer", "Hey there!");
});

// It is also possible to unsubscribe from an event to make it stop triggering
Events.Unsubscribe("MyEvent");

Belle barre de défilement

Since we migrated from Webkit to CEF, some scrollbars got ugly. Here's a small CSS snippet to make them almost like the Webkit ones:

::-webkit-scrollbar {
width: 6px;
}

::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #494949;
}

body {
scrollbar-gutter: stable both-edges;
}

Plus d'exemples comme celui-ci:

User Interfacecore-concepts/scripting/user-interface Basic HUD (HTML)getting-started/tutorials-and-examples/basic-hud-html
tip

You can use the output Texture from a Canvas with :SetMaterialFromWebUI() method!

📚 Libraries & Frameworks

Here a list of Community Created Libraries & Frameworks making use of WebUIs expanding it's possibilities:

🛠 Constructors

Default Constructor

No description provided

local my_webui = WebUI(name, path, visibility?, is_transparent?, auto_resize?, width?, height?)
TypeNameDefaultDescription
name Required parameter Used for debugging logs
path Required parameter Web URL or HTML File Path as file://my_file.html
visibilityWidgetVisibility.Visibleif WebUI is visible on screen
is_transparenttrueif WebUI background is transparent
auto_resizetrueif should auto resize when screen changes it's size (useful OFF when you are painting meshes with WebUI)
width0size of the WebUI width when you are not using auto_resize
height0size of the WebUI height when you are not using auto_resize

🔍 HTML Path Searchers

Loading a .html file supports the following searchers, which are looked in the following order:

  1. Relative to current-file-path/
  2. Relative to current-package/Client/
  3. Relative to current-package/
  4. Relative to Packages/

🗿 Static Functions

Inherited Entity Static Functions
WebUI inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/Entity
ReturnsNameDescription
of Returns a table containing all Entities of the class this is called on
Returns a specific Entity of this class at an index
Returns how many Entities of this class exist
of Gets a list of all directly inherited classes from this Class created with the Inheriting System
Returns an iterator with all Entities of this class to be used with pairs()
or Gets the parent class if this Class was created with the Inheriting System
Inherits this class with the Inheriting System
Gets if this Class is child of another class if this Class was created with the Inheriting System
Subscribes to an Event for all entities of this Class
Subscribes to a custom event called from server
Unsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed

This class doesn't have own static functions.

🦠 Functions

Inherited Entity Functions
WebUI inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/Entity
ReturnsNameDescription
Calls a custom remote event directly on this entity to all Players
Calls a custom remote event directly on this entity to a specific Player
Calls a custom remote event directly on this entity
Destroys this Entity
of Gets a list of all values keys
Gets the class of this entity
Gets the universal network ID of this Entity (same on both client and server)
Gets a Value stored on this Entity at the given key
Recursively checks if this entity is inherited from a Class
Returns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
Sets a Value in this Entity
Subscribes to an Event on this specific entity
Subscribes to a custom event called from server on this specific entity
Unsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
ReturnsNameDescription
Puts this WebUI in the front of all WebUIs and Widgets
Calls an Event on the Browser's JavaScript
Executes a JavaScript code in the Browser
Gets this WebUI name
Vector2DGets the current size of this WebUI
Returns the current WebUI visibility
Returns if this WebUI is currently frozen
Loads a pure HTML in this Browser
Loads a new File/URL in this Browser
Removes the focus from this WebUI (and sets it back to game viewport)
Sends a Key Event into the WebUI programatically
Sends a Mouse Click into the WebUI programatically
Sends a Mouse Move Event into the WebUI programatically
Sends a Mouse Event into the WebUI programatically
Enables the focus on this browser (i.e. can receive Keyboard input and will trigger input events)
Freezes the WebUI Rendering to the surface (it will still execute the JS under the hood)
Sets the Layout as Canvas on Screen
Sets the visibility in screen
SoundSpawns a Sound entity to plays this WebUI sound

BringToFront

Puts this WebUI in the front of all WebUIs and Widgets

my_webui:BringToFront()

CallEvent

Calls an Event on the Browser's JavaScript

my_webui:CallEvent(event_name, args...)
TypeParameterDefaultDescription
event_name Required parameter The Event Name to trigger the event
args... Required parameter Arguments to pass to the event

ExecuteJavaScript

Executes a JavaScript code in the Browser
Note: This method is experimental and should be used cautiously. Events are still the preferred way of communicating between Packages and WebUI.

my_webui:ExecuteJavaScript(javascript_code)
TypeParameterDefaultDescription
javascript_code Required parameter No description provided

GetName

Gets this WebUI name

— Returns .

local ret = my_webui:GetName()

GetSize

Gets the current size of this WebUI

— Returns Vector2D.

local ret = my_webui:GetSize()

GetVisibility

Returns the current WebUI visibility

— Returns .

local ret = my_webui:GetVisibility()

See also SetVisibility.


IsFrozen

Returns if this WebUI is currently frozen

— Returns .

local ret = my_webui:IsFrozen()

LoadHTML

Loads a pure HTML in this Browser

my_webui:LoadHTML(html)
TypeParameterDefaultDescription
html Required parameter No description provided

LoadURL

Loads a new File/URL in this Browser

my_webui:LoadURL(url)
TypeParameterDefaultDescription
url Required parameter No description provided

RemoveFocus

Removes the focus from this WebUI (and sets it back to game viewport)
You MUST call this after you don't need keyboard input anymore

my_webui:RemoveFocus()

SendKeyEvent

Sends a Key Event into the WebUI programatically

my_webui:SendKeyEvent(key_type, key_code, modifiers?)
TypeParameterDefaultDescription
key_type Required parameter No description provided
key_code Required parameter No description provided
modifiers?WebUIModifier.NoneSupports several modifiers separating by | (using bit-wise operations)

SendMouseClickEvent

You must send both Down and Up to make it work properly

my_webui:SendMouseClickEvent(mouse_x, mouse_y, mouse_type, is_mouse_up, modifiers?, click_count?)
TypeParameterDefaultDescription
mouse_x Required parameter Position X of the mouse
mouse_y Required parameter Position Y of the mouse
mouse_type Required parameter Which mouse button
is_mouse_up Required parameter Whether the event was up or down
modifiers?WebUIModifier.NoneSupports several modifiers separating by | (using bit-wise operations)
click_count?1Use 2 for double click event

SendMouseMoveEvent

Sends a Mouse Move Event into the WebUI programatically

my_webui:SendMouseMoveEvent(mouse_x, mouse_y, modifiers?, mouse_leave?)
TypeParameterDefaultDescription
mouse_x Required parameter Position X of the mouse
mouse_y Required parameter Position Y of the mouse
modifiers?WebUIModifier.NoneSupports several modifiers separating by | (using bit-wise operations)
mouse_leave?falseNo description provided

SendMouseWheelEvent

Sends a Mouse Event into the WebUI programatically

my_webui:SendMouseWheelEvent(mouse_x, mouse_y, delta_x, delta_y)
TypeParameterDefaultDescription
mouse_x Required parameter Position X of the mouse
mouse_y Required parameter Position Y of the mouse
delta_x Required parameter No description provided
delta_y Required parameter No description provided

SetFocus

Enables the focus on this browser (i.e. can receive Keyboard input and will trigger input events
Note: Only one browser can have focus per time.

my_webui:SetFocus()

SetFreeze

Freezes the WebUI Rendering to the surface (it will still execute the JS under the hood)

my_webui:SetFreeze(freeze)
TypeParameterDefaultDescription
freeze Required parameter No description provided

SetLayout

Sets the Layout as Canvas on Screen. Anchors:

my_webui:SetLayout(screen_location/offset_left_top?, size/offset_right_bottom?, anchors_min?, anchors_max?, alignment?)
TypeParameterDefaultDescription
Vector2Dscreen_location/offset_left_top?Vector(0, 0)No description provided
Vector2Dsize/offset_right_bottom?Vector(0, 0)No description provided
Vector2Danchors_min?Vector(0, 0)No description provided
Vector2Danchors_max?Vector(1, 1)No description provided
Vector2Dalignment?Vector(0.5, 0.5)No description provided

SetVisibility

Sets the visibility in screen

my_webui:SetVisibility(visibility)
TypeParameterDefaultDescription
visibility Required parameter No description provided

See also GetVisibility.


SpawnSound

Spawns a Sound entity to plays this WebUI sound

— Returns Sound.

local ret = my_webui:SpawnSound(location?, is_2d?, volume?, inner_radius?, falloff_distance?, attenuation_function?)
TypeParameterDefaultDescription
Vectorlocation?Vector(0, 0, 0)No description provided
is_2d?trueNo description provided
volume?1.0No description provided
inner_radius?400No description provided
falloff_distance?3600No description provided
attenuation_function?AttenuationFunction.LinearNo description provided

🚀 Events

Inherited Entity Events
WebUI inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/Entity
NameDescription
Triggered when a new Class is registered with the Inheriting System
Triggered when an Entity is destroyed
Triggered when an Entity is spawned/created
Triggered when an Entity has a value changed with :SetValue()
NameDescription
Triggered when this page fails to load
Triggered when this page is fully loaded

Fail

Triggered when this page fails to load
WebUI.Subscribe("Fail", function(error_code, message)
-- Fail was called
end)
TypeArgumentDescription
error_codeNo description provided
messageNo description provided

Ready

Triggered when this page is fully loaded
WebUI.Subscribe("Ready", function()
-- Ready was called
end)