- Documentation
- Client functions
- createBrowser
Function
createBrowser
Creates a browser: an HTML page rendered into a texture. Draw it with dxDrawImage and load the address only in the onClientBrowserCreated event.
Syntax
browser createBrowser(int width, int height, bool isLocal [, bool transparent = false])Arguments
widthint- Page width in pixels.
heightint- Page height in pixels.
isLocalbooltrue: pages from resource files (http://trilogy/local/...),false: web pages from domains allowed by the server and the player.transparentbool, optional = false- Whether the page's transparent background stays transparent in the game.
Returns
A browser element or false.
Example
A full-screen HTML interface that sends an event to Lua.
local sw, sh = guiGetScreenSize()
local browser = createBrowser(sw, sh, true, true)
addEventHandler("onClientBrowserCreated", browser, function()
loadBrowserURL(browser, "http://trilogy/local/html/index.html")
end)
addEventHandler("onClientRender", root, function()
dxDrawImage(0, 0, sw, sh, browser)
end)
setBrowserFunction(browser, "login", function(login, password)
triggerServerEvent("tryLogin", localPlayer, login, password)
end)
<meta>
<script src="client.lua" type="client" />
<file src="html/index.html" protected="true" />
<file src="html/app.js" protected="true" />
<file src="html/logo.png" />
</meta>
Notes
Does not wait for the browser. createBrowser returns the element right away, even when the browser process is still starting (the first call after joining a server). Settings and an address given earlier reach the page once the process is up, and onClientBrowserCreated reports that it is ready. You can create it in onClientResourceStart.
A separate process. Pages are rendered by a separate Chromium process. If a page crashes the game keeps running and the browser comes back with its last address.
Encrypted pages. <file src="html/index.html" protected="true" /> stores a page file (.html .htm .js .mjs .cjs .css .json .svg) encrypted in the player's cache, just like client scripts. Only the resource's browser gets its content; fileOpen and fileCopy will not open such a file. The page still has to receive plain code, so it can be viewed in developer tools.
See also
loadBrowserURLLoads an address in the browser. A local browser opens resource files, a remote one opens pages from allowed domains.onClientBrowserCreatedThe browser is ready (the page process started) and you can load an address in it.guiCreateBrowserCreates a browser as a GUI control. Mouse, wheel and keyboard go to the page by themselves. Get the browser element forloadBrowserURLwithguiGetBrowser.dxDrawImageDraws an image (a resource PNG/JPG file, a texture, a render target, a browser or a camera) in a screen rectangle, with optional rotation and tint.