ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. createBrowser

Function

createBrowser

ClientBrowserIdentical to MTA:SA

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.
isLocalbool
true: 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)

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