Santa & Christmas Edition36 maps, limited runlimited runShop the drop
Chapter 06 of 8The Loading Screens Handbook for FiveM

NUI: messages, callbacks, focus and the limits of the in-game browser

In short

Once the loading screen closes, every HUD, menu and phone is NUI: a page in the in-game browser that talks to Lua. That browser is Chromium with a few gaps, and knowing them saves days of “works in Chrome, broken in game”.

DirectionLuaPage
Lua → pageSendNUIMessage({ action = 'open', data = … })window.addEventListener('message', e => e.data)
Page → LuaRegisterNuiCallback('name', function(data, cb) cb({ ok = true }) end)fetch(https://${GetParentResourceName()}/name, …)
InputSetNuiFocus(true, true) / SetNuiFocus(false, false)Close on Escape and tell Lua
Filesui_page + filesRelative paths; https://cfx-nui-<resource>/… for other resources
  • Call cb in every NUI callback, error paths included. Without it the page’s fetch never resolves.
  • Release focus on each way the UI can close, and again when the resource stops.
  • Match the case of file names exactly, because Linux servers are case-sensitive.
  • In React, useNuiEvent, fetchNui, mocked debugData and isEnvBrowser() let most of the work happen in a normal browser.

The callback side is covered in more depth in NUI callbacks and fetch. The table below lists what the in-game browser does not do, and what to use in its place.

LimitationWorkaround
backdrop-filter unreliableSolid semi-transparent colors
H.264 not dependableWebM video
Links and window.open do nothingwindow.invokeNative('openUrl', url)
alert and native dialogs uselessYour own modal
Async clipboard often failsShow the text to copy manually
  • To debug, open http://localhost:13172/ in a Chromium browser while the game is running, or run nui_devTools in F8 (developer mode).
  • Send a message only when a value changes, and throttle speed and fuel to a few updates per second.
  • Animate transform and opacity only, and hide a closed UI with display: none.
  • For a HUD, show what matters at that moment, anchor it to the minimap, respect GetSafeZoneSize() and hide it while IsPauseMenuActive() is true.
  • Route everything through one notification resource, so that ESX, QBCore and ox_lib toasts look alike.

The Loading Screens Handbook for FiveM

This chapter is one of 8. The handbook also carries the manifest, message, server list and NUI cheat sheets, a glossary and the official references every chapter is checked against.

Open the handbook