An OBS overlay on your own domain

A custom overlay is a small web page that OBS shows as a browser source. This guide builds an alert overlay with a small server that takes alerts from your bot and sends them live to OBS, without libraries and on your own domain.

Updated 9 minute read

How it is built

The overlay has two parts in one service:

  • The page (public/index.html) that OBS loads as a browser source. It keeps a connection to the server open and shows every alert for five seconds, one after the other.
  • The server (server.js) that serves the page, keeps the connections from OBS open and accepts new alerts. Your bot sends an alert with a secret key, so not just anyone can trigger alerts.

No libraries, just Node.js. Create a folder and in it a package.json with {"type": "module"}.

The page

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
  html, body { margin: 0; background: transparent; overflow: hidden; }
  #alert {
    position: absolute; left: 50%; top: 80px; transform: translateX(-50%);
    padding: 20px 32px; border-radius: 12px; background: rgba(20, 20, 24, 0.9);
    color: #fff; font: 700 36px system-ui, sans-serif; opacity: 0; transition: opacity 0.3s;
  }
  #alert.show { opacity: 1; }
</style>
</head>
<body>
<div id="alert"></div>
<script>
  const box = document.getElementById('alert');
  const queue = [];
  let busy = false;

  function next() {
    if (busy || queue.length === 0) return;
    busy = true;
    const { name, text } = queue.shift();
    box.textContent = `${name} ${text}`;
    box.classList.add('show');
    setTimeout(() => {
      box.classList.remove('show');
      setTimeout(() => { busy = false; next(); }, 400);
    }, 5000);
  }

  // EventSource reconnects by itself after a drop.
  const events = new EventSource('/events');
  events.onmessage = (e) => { queue.push(JSON.parse(e.data)); next(); };
</script>
</body>
</html>

Two things matter for OBS: the background is transparent, so only the alert sits on top of your scene. And EventSource reconnects by itself when the connection drops, for example on a new version of the server.

The server

// server.js: serves the overlay and sends alerts live to OBS.
import http from 'node:http';
import { readFile } from 'node:fs/promises';

const KEY = process.env.OVERLAY_KEY;      // key for new alerts
const clients = new Set();                // open connections from OBS

function send(event) {
  const line = `data: ${JSON.stringify(event)}\n\n`;
  for (const res of clients) res.write(line);
}

// A sign of life every 25 seconds, so no connection goes stale.
setInterval(() => { for (const res of clients) res.write(': ping\n\n'); }, 25_000);

const server = http.createServer(async (req, res) => {
  const url = new URL(req.url, 'http://localhost');

  if (req.method === 'GET' && url.pathname === '/events') {
    res.writeHead(200, {
      'Content-Type': 'text/event-stream',
      'Cache-Control': 'no-cache',
      Connection: 'keep-alive',
    });
    res.write(': connected\n\n');
    clients.add(res);
    req.on('close', () => clients.delete(res));
    return;
  }

  if (req.method === 'POST' && url.pathname === '/alert') {
    if (!KEY || req.headers.authorization !== `Bearer ${KEY}`) {
      res.writeHead(401).end();
      return;
    }
    let body = '';
    for await (const chunk of req) {
      body += chunk;
      if (body.length > 10_000) { res.writeHead(413).end(); return; }
    }
    try {
      const { name, text } = JSON.parse(body);
      send({ name: String(name).slice(0, 50), text: String(text).slice(0, 200) });
      res.writeHead(204).end();
    } catch {
      res.writeHead(400).end();
    }
    return;
  }

  if (req.method === 'GET' && url.pathname === '/') {
    const html = await readFile(new URL('./public/index.html', import.meta.url));
    res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }).end(html);
    return;
  }

  res.writeHead(404).end();
});

server.listen(Number(process.env.PORT) || 8000);
process.on('SIGTERM', () => server.close(() => process.exit(0)));

What the server guards against:

  • Only with the key. Without the right OVERLAY_KEY there is no alert.
  • Limited size. Requests over 10,000 characters are refused, names and texts are shortened.
  • Signs of life. Every 25 seconds an empty line goes to every connection, so no proxy along the way closes it.
  • Clean shutdown on a SIGTERM.

The server listens on the port in the PORT variable. On EStage we set it and put HTTPS on your domain in front.

The Dockerfile

FROM node:24-slim
WORKDIR /app
COPY . .
USER node
CMD ["node", "server.js"]

Bringing it online on EStage

  1. Push, and name the service overlay, for example.
  2. Create a secret: OVERLAY_KEY with a long, random value.
  3. Enter a domain, such as overlay.yourchannel.tv, and confirm it. We fetch the certificate.
  4. Assign memory: 128 MB is plenty.

Adding it to OBS

  1. Add a new browser source to your scene.
  2. Enter https://overlay.yourchannel.tv as the URL.
  3. Set width and height to the size of your scene, usually 1920 and 1080.
  4. Leave the custom CSS field as it is, or empty. The background is already transparent.

After a new version, reload the browser source; its properties have a button for that. Or switch on the option there that reloads the browser whenever the scene becomes active.

Triggering an alert

To test from your PC:

curl -X POST https://overlay.yourchannel.tv/alert \
  -H "Authorization: Bearer your-overlay-key" \
  -H "Content-Type: application/json" \
  -d '{"name": "Lena", "text": "is now following!"}'

From your bot, if it runs in the same EStage account, you reach the overlay on the private network by the service’s name and port, without a detour through the internet:

await fetch('http://overlay:8000/alert', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.OVERLAY_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: user.displayName, text: 'is now following!' }),
});

Where the events for follows, subs and raids come from is shown in the guide Twitch EventSub with webhooks.

Going further

  • Sounds: an <audio> element with a file from public/. For the sound to show up in the OBS mixer, switch on the option in the browser source’s properties that lets OBS control the audio.
  • Several overlays: more pages such as /goal or /chat in the same server, each with its own browser source.
  • Data from the database: the server reads a donation goal or a leaderboard from your account’s database and sends changes over the same connection.

Common questions

Why server-sent events and not WebSocket?

For an overlay, data flows one way only, from the server to OBS. Server-sent events are simpler for that: the browser reconnects by itself after a drop, and no library is needed. WebSocket works just the same on EStage if you want to send data both ways.

My overlay shows a black or white background in OBS.

Set the background of html and body to transparent in your CSS, and check whether the browser source's custom CSS field says something else. OBS then shows everything the page does not paint itself as see-through.

How do I test an alert without being live?

Send an alert by hand with curl to /alert, as shown below. The overlay reacts exactly as it would to a real one.

Ready when you are

EStage launches in early 2027. Tell us what you want to run, and we will set up the first channels together.

Early access See pricing