SixL client API / browser / BrowserMp
Interface: BrowserMp
A page drawn over the game: created with mp.browsers.new(url).
Remarks
The page is drawn over the game with a transparent background: what the page does not paint shows the game. Pages stack in the order they were created. package:// addresses load from the server's client resources (a relative link inside such a page loads from the same folder). https:// addresses load from the internet; the host of such a page then sees the player's IP address. Other address schemes do not load.
Example
const hud = mp.browsers.new('package://ui/index.html');
hud.active = false;
Properties
active
active: boolean
Whether the page is shown and takes input. true when the browser is created.
Remarks
A hidden page is not drawn and takes no mouse or keyboard input, but it keeps running and keeps its state.
Example
hud.active = false; // hide it, keep it
id
readonlyid:number
The browser's number: 1, 2, ... in the order of creation. A restarted client starts again from 1.
Example
mp.console.logInfo('page ' + hud.id);
orderId
orderId: number
The page's place among the pages: the later made, the higher (on top).
Remarks
Partial: the pages stack in the order they were made; setting it changes nothing (no reordering).
Example
const top = mp.browsers.toArray().sort((a, b) => b.orderId - a.orderId)[0];
type
readonlytype:string
Always 'browser'.
Example
mp.console.logInfo(hud.type);
url
url: string
The page's address. Assigning a new address loads it in this browser.
Remarks
Only package://, https:// and about:blank addresses load; other schemes are refused. Assigning to a destroyed browser does nothing.
Example
hud.url = 'package://ui/settings.html';
Methods
call()
call(name, ...args):void
Calls the handlers that the page registered with its mp.events.add under a name.
Parameters
name
string
The event name the page listens to.
args
...unknown[]
Values passed to the handlers. They are sent as JSON, so they must be JSON-serializable.
Returns
void
Remarks
A value that cannot be turned into JSON (a cycle, a BigInt) makes the call throw a TypeError and nothing is sent. A destroyed browser does nothing.
Example
hud.call('setHealth', 85, 100);
destroy()
destroy(): void
Removes the page. The browser is no longer in mp.browsers, and calling its methods does nothing.
Returns
void
Example
hud.destroy();
execute()
execute(code):void
Runs JavaScript code in the page, as a script of the page.
Parameters
code
string
The source text, in the page's own scope.
Returns
void
Remarks
The result of the code is not returned to the client. A destroyed browser does nothing.
Example
hud.execute("document.title = 'Map';");
executeCached()
executeCached(code):void
Runs JavaScript in the page, as execute does.
Parameters
code
string
The code.
Returns
void
Remarks
Partial: the code runs each time; the page's engine keeps no script cache for it.
Example
browser.executeCached('render()');
markAsChat()
markAsChat(): void
Makes this browser the chat's page: the built-in chat page is hidden and the chat goes here.
Returns
void
Remarks
Partial. While a browser is marked, the built-in chat page is hidden and the chat (new messages, the show and activate calls, the input) goes to the marked browser instead, which receives them as browser.call('sixl:chat', message) and answers with mp.trigger('sixl:chat', message). Destroying the marked browser brings the built-in page back. RAGE MP's own per-method event names for a custom chat page are not reproduced.
Example
chat.markAsChat();
reload()
reload(ignoreCache?):void
Reloads the page.
Parameters
ignoreCache?
boolean
true reloads without the browser's cache; false (the default) reloads normally.
Returns
void
Example
hud.reload(true);