Skip to content

Quick Start

NeekoGta edited this page Jun 17, 2026 · 2 revisions

Quick Start

This guide creates a minimal Overlay2D browser from Pawn.

1. Create a resource

Create:

scriptfiles/cef/hello/index.html
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>omp-cef hello</title>
    <style>
        html, body {
            margin: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
            background: transparent;
            font-family: Arial, sans-serif;
        }

        .panel {
            position: absolute;
            left: 32px;
            top: 32px;
            padding: 18px 22px;
            color: white;
            background: rgba(0, 0, 0, .75);
            border: 1px solid rgba(255, 255, 255, .35);
            border-radius: 8px;
        }
    </style>
</head>
<body>
    <div class="panel">
        <h1>omp-cef</h1>
        <p>Hello from <code>http://cef/hello/index.html</code></p>
    </div>
</body>
</html>

2. Register the resource

public OnGameModeInit()
{
    CEF_AddResource("hello");
    return 1;
}

3. Wait for CEF

new bool:gCefReady[MAX_PLAYERS];

public OnCefInitialize(playerid, bool:success, E_CEF_INIT_REASON:reason, const message[])
{
    gCefReady[playerid] = success;

    if (success)
        SendClientMessage(playerid, -1, "CEF ready. Use /hellocef.");
    else
        SendClientMessage(playerid, -1, "CEF failed to initialize.");

    return 1;
}

4. Create a browser

#define HELLO_BROWSER_ID 1000

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/hellocef", true))
    {
        if (!gCefReady[playerid])
        {
            SendClientMessage(playerid, -1, "CEF is not ready yet.");
            return 1;
        }

        CEF_CreateBrowser(
            playerid,
            HELLO_BROWSER_ID,
            "http://cef/hello/index.html",
            false,
            true,
            0.0,
            0.0
        );

        return 1;
    }

    if (!strcmp(cmdtext, "/hidecef", true))
    {
        CEF_SetBrowserVisible(playerid, HELLO_BROWSER_ID, false);
        return 1;
    }

    if (!strcmp(cmdtext, "/showcef", true))
    {
        CEF_SetBrowserVisible(playerid, HELLO_BROWSER_ID, true);
        return 1;
    }

    if (!strcmp(cmdtext, "/destroycef", true))
    {
        CEF_DestroyBrowser(playerid, HELLO_BROWSER_ID);
        return 1;
    }

    return 0;
}

5. Expected result

After connecting:

  1. Wait for CEF ready;
  2. type /hellocef;
  3. The browser panel appears at the top-left of the screen.

Next steps

Clone this wiki locally