> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lokutor.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Games in a web browser

> A Godot voice game exported for the web: what the browser needs (renderer, audio, microphone), keys and tickets, the key-less demo on lokutor.com and its limits, telling the page what happened, and keeping the download small

A Godot game with Lokutor characters runs in a web browser: the engine is WebAssembly, the microphone is the browser's, and the characters talk to the same API. [Most Suspicious and Not Amused are playable on lokutor.com](https://lokutor.com/games), made exactly as this page says.

> [!NOTE]
>
> The game runs in the player's browser. Lokutor runs the voices: recognition, the language model, speech and lip sync are on our servers, so the browser only plays sound and sends the microphone.

## Export it

1. Install the **export templates** of your Godot version (**Editor > Manage Export Templates**).
2. **Project > Export > Add > Web**. Leave **Thread Support** off: the game then needs no special headers on the site and runs inside an iframe.
3. In **Project Settings**:

| Setting | Value | Why |
| :- | :- | :- |
| **Audio > General > Default Playback Type** (`.web` override) | `Stream` | The web's default (Sample) plays without audio bus effects and without generators; voices need both. |
| **Rendering > Textures > VRAM Compression > Import ETC2 ASTC** | On | Phones' browsers read ETC2 and ASTC, not the desktop formats. Tick **For Mobile** in the export preset too. |
| **Audio > Driver > Enable Input** | On | The microphone. The plugin turns it on. |

Godot draws with WebGL 2 in a browser (the Compatibility renderer), whatever the project uses on the desktop. Check your shaders and lights in a web build early; soft shadows and MSAA cost more there than on a desktop.

4. Serve the folder over **HTTPS** (or `http://localhost` while you develop): browsers give the microphone only to secure pages. The browser asks the player for it the first time it starts. Start the conversation after a click or a tap, as browsers only play sound after the page has been touched.

## Keys: none in the build

Whatever is in a web build can be read by anyone who opens the page. Never put a key in it:

* **On your site**, have your server trade the key for a ticket and give the game a `ticket_provider`, exactly as in a [shipped game](https://docs.lokutor.com/sdks/godot/introduction.md#shipping). Limit tickets per player on your server.
* **On lokutor.com**, a game needs nothing: in a browser the SDK may open a session with no key at all (`Lokutor.keyless_allowed()`), and the server gives a page of lokutor.com its demo, with its limits. Any other site that tries the same is refused with `auth.missing_key`.

With no key, every `LokutorVoice` of the game speaks through one shared connection, so a game takes few of the demo's sessions.

## The demo's limits

The demo on lokutor.com is bounded: each conversation lasts a few minutes, each visitor has a few minutes a day, and only a few sessions run at once for everyone. The SDK says which limit was reached:

```gdscript theme={null}
func _ready() -> void:
    agent.session_limit.connect(func(seconds, _reason): $Clock.start(seconds))
    agent.demo_limit.connect(_on_demo_limit)

func _on_demo_limit(limit: String, message: String) -> void:
    match limit:
        "call": $Hud.say("That conversation is over. Start another!")
        "daily": $Hud.say("That's today's demo. Create a free account to keep playing.")
        "busy": $Hud.say("The demo is full right now. Try again in a minute.")
```

`LokutorVoice` has the same `demo_limit` signal. The conversation also ends with `error_occurred("auth.time_limited", message)`; the details are in [`LokutorError.demo_limit`](https://docs.lokutor.com/sdks/godot/reference#lokutorerror-methods).

## Tell the page

A game is usually inside a page that has its own buttons and text. In a browser the SDK tells that page what happened, as a `message` event: `session_limit` (`{seconds, reason}`) when a conversation starts, and `demo_limit` (`{limit, message}`) when the demo stops one. Your game can send its own with `Lokutor.tell_page(type, data)`.

```js theme={null}
// The page around the game's iframe
window.addEventListener("message", (e) => {
  if (e.data?.source !== "lokutor") return;
  if (e.data.type === "session_limit") startClock(e.data.seconds);
  if (e.data.type === "demo_limit") showSignUp(e.data.limit);
});
```

A web build has no command line. `Lokutor.page_args()` reads the parameters of the page's address instead (`game.html?lang=es&level=1` is `{"lang": "es", "level": "1"}`), so the page can say which language to start in.

## Echo

A laptop's or a phone's speakers are a few centimetres from its microphone. In a browser the SDK waits longer for the room's echo to fade (`LokutorVoicePlayer.echo_tail_ms()`, 700 ms instead of 250), and the character's own words coming back are recognised as its echo and not taken for the player's (`guard_against_echo`). Keep `mute_mic_while_speaking` on unless the player says they wear headphones.

## Keep the download small

Players wait for all of the game before the first frame. What usually makes a voice game big is its characters' faces: a blend shape stores every vertex of the mesh, so fifteen visemes and a dozen expressions on a character whose clothes, hat and shoes are in the same mesh multiply all of them.

* **Cut each character in parts** that carry only the shapes that move them: the face, and the rest with none. `LokutorLipSync` drives any number of meshes (`faces`). The [game kit](https://docs.lokutor.com/guides/game-asset-pipeline.md) does it by itself in its web builds, and its characters weigh a fifth.
* **Leave out what the web version does not need**: fewer characters, fewer places, music at a lower rate.
* **Drop tangents** if your shaders do not use normal maps.
* **Serve compressed**: the engine's `.wasm` shrinks to a quarter with gzip or Brotli. Two games can share one engine file.

The two sample games download 60 and 90 MB the first time, a 40 MB engine included (about 25 and 50 MB compressed), against several hundred MB on the desktop. A browser keeps them in its cache for the next visit.

## Next

* [Godot SDK](https://docs.lokutor.com/sdks/godot/introduction.md): characters, actions, lip sync.
* [Sample game: Most Suspicious](https://docs.lokutor.com/guides/sample-game-most-suspicious.md) and [Not Amused](https://docs.lokutor.com/guides/sample-game-not-amused.md): how they are built.
* [Secure browser setup](https://docs.lokutor.com/guides/secure-browser-setup.md): tickets from your server.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.