Repository navigation
Web Mode
New in v0.3.0.
Your application, unchanged, in a web browser: app --web 127.0.0.1:9090 --res 120x60. The page is a terminal
(xterm.js, shipped in the package) and each browser tab runs your application's own process, exactly as it runs in
a terminal. There is no second UI to write or keep in step: what the terminal shows, the browser shows.

The server needs the web extra (aiohttp >=3.9.5,<4):
pip install "turboframe[web] @ git+https://github.com/divengine/turboframe@v0.3.0"The launcher (turboframe.web) needs no extra, so your application can call it always. Without the extra,
--web ends the program with a message that says what to install.
Call web.launch() first thing in your main:
from turboframe import web
def main() -> None:
if web.launch(title="My app"): # --web given: the browser runs the app until the server stops
return
MyApp().run()Without --web, launch() returns False and your application runs in its terminal as always. With it,
launch() serves the application and returns True once the server stops (Ctrl+C). Each tab starts your
application again, with the same interpreter, script and arguments less --web and --res.
If your main takes its arguments as a list, pass them with a program name first, as the workbench example does:
def main(argv: list[str] | None = None) -> None:
args_in = sys.argv[1:] if argv is None else list(argv)
if web.launch(["workbench", *args_in], title="Workbench"):
return
...python examples/workbench/workbench.py FOLDER --web # 127.0.0.1:8000, the window's size
python examples/workbench/workbench.py FOLDER --web 127.0.0.1:9090 --res 120x60
python examples/workbench/workbench.py FOLDER --web :9090 --res autoThe terminal prints the address to open, with a secret token in it, and how long it lasts:
Serving Workbench at http://127.0.0.1:9090/?token=...
The address opens once, within 10 minutes; then that browser stays in for 12 hours. Restarting the server gives a new address and shuts every browser out.
Terminal size: 120x60. Press Ctrl+C to stop.
Open it in your browser. The token leaves the address bar at once (a cookie takes its place). Every tab is an independent session of the application, up to 4 per server. Closing or reloading a tab ends its session (the browser asks first). Alt+X in the application ends its session too, and the page says so. Ctrl+C on the server ends every session, then the server.
--web takes HOST:PORT, HOST, :PORT or [IPv6]:PORT. --web=ADDRESS is never ambiguous; after a bare
--web, the next argument is taken as the address only when it looks like one, so app --web folder keeps
folder for your application.
-
--res COLSxROWS(from 20x10 to 500x300) fixes the terminal at that many cells, whatever the browser's size. The page fits it to the window by its font size, so the cells stay sharp; resizing the window changes the font, never the columns and rows your application sees. -
--res auto(the default) follows the browser window, as a terminal window does.


Screenshots from Chromium, served from the workbench example.
- Ctrl+P, the F-keys (F5 included: it does not reload the page), Alt+letters and the mouse reach the application.
- A browser keeps some keys for itself: Chromium does not give a page Ctrl+W, Ctrl+T, Ctrl+N or Ctrl+Tab, among others, and the operating system keeps its own. Give your commands other keys if they must work in a browser.
-
Copying from the application reaches the system clipboard. Textual's
copy_to_clipboard()(the editor's Ctrl+C, for one) writes an OSC 52 sequence, and the page passes it to the browser's clipboard API (navigator.clipboard.writeText). The browser allows it on a secure context, whichlocalhostand127.0.0.1are. - Reading the clipboard is never allowed to the application: a request to read it gets no answer.
- Pasting is the browser's: what it pastes into the terminal reaches the application as typed text.
Any page in your browser can talk to any port of your machine, so the server treats the browser as the way in:
-
This machine only. Only loopback addresses are served (127.0.0.0/8,
::1,localhost).--web 0.0.0.0is refused with a message. There is no supported way to serve to a network. - The address opens once. The token in the printed address opens the page once, within 10 minutes. Unused, it expires; used, it opens nothing for anyone else ("opened already"). Until it is used, treat it as a password: whoever opens it first gets in.
- A cookie for 12 hours. Opening the address gives that browser a cookie (HttpOnly, SameSite=Strict) that lets it in, new tabs and reloads included, for 12 hours; the server checks the time itself. The cookie is not extended while in use. Another browser, another profile or a private window has no cookie and needs a new address.
- Expiry stops new sessions, not open ones. When the cookie expires, reloads and new tabs are refused, but a session already open is not cut: it lasts until its tab closes, as a terminal does. To end open sessions, close their tabs, or stop or restart the server.
-
One cookie per port. The cookie is named
turboframe_session_<port>. Browsers send a host's cookies to every port of it, so this lets two servers on one machine (two applications, or one at two sizes) work side by side in one browser. - Restart to revoke. Restarting the server makes new secrets: every old address and cookie stops working.
-
No other names, no other sites. Every request must name the address served (or
localhost), which stops DNS rebinding; the WebSocket only accepts the page's own origin; the page loads nothing from outside (Content-Security-Policy). - Nothing the browser sends becomes a command. A session's command is your application's, fixed when the server started, and no shell is involved.
- No logs of the token. The server keeps no access log: the token appears only on the terminal that started it. If you redirect that output to a file, keep the file private.
TLS is not used: the traffic stays on your machine.
Serve on loopback and forward the port over SSH. On the machine with the browser:
ssh -N -L 9090:127.0.0.1:9090 user@serverThen open the printed address there, with the same port (http://127.0.0.1:9090/?token=..., or localhost
instead of 127.0.0.1). Keep the port the same at both ends: the server checks the host and port the browser asks
for, and refuses another one (421).
A frozen executable serves too: each session starts the executable itself. It must carry TurboFrame's web files and Textual's web driver, which Textual imports by name, so PyInstaller does not find it alone:
pyinstaller --onedir --name workbench --collect-data turboframe --collect-data textual \
--collect-submodules textual.drivers examples/workbench/workbench.py
dist/workbench/workbench FOLDER --web 127.0.0.1:9393 --res 100x30--collect-data turboframe also brings TurboFrame's translations. collect_all works as well, in one file or a
folder:
pyinstaller --onefile --name app --collect-all turboframe --collect-all textual --collect-all textual_vision app.pyTurboFrame's CI builds its test application that way on Linux and Windows and serves it to Chromium on every
pull request: the page comes from the executable, each session is the executable, and stopping the server leaves
no process. The build environment needs the web extra. See Packaging.
- Downloads, uploads, reconnecting to a session after a reload, several users and a reverse proxy are not part of the web mode.
- The keys a browser keeps (above).
- A session's process is your application started again: it reads its settings and arguments as it does in a terminal.
| What you see | Why | What to do |
|---|---|---|
Forbidden: open the address the terminal printed. |
the page was opened without the token, with a wrong one, or without the cookie (another browser or profile, a private window, the cookie expired) | open the printed address; if it was used or expired, restart the server for a new one |
This address was opened already, and works once. |
another browser, profile or private window spent the token (in the browser that opened it, the same address still gets in, by its cookie) | use the browser that opened it, or restart the server for a new address |
This address has expired. |
the address was not opened within 10 minutes | restart the server and open the new address soon |
Misdirected request (421) |
the browser asked for another host name or port than the one served: a different port through a tunnel, a name of your own pointing at 127.0.0.1 | use 127.0.0.1 or localhost with the same port the server prints |
Too many sessions: close another tab first. (429) |
4 tabs already run sessions on this server | close a tab |
cannot serve on ... and exit status 2 |
the port is taken (another server, a previous run still alive) | choose another port, or stop what holds it |
--web needs the web extra: pip install "turboframe[web]" |
aiohttp is not installed | install the web extra |
--web ...: only this machine's addresses are served |
a network address was given | serve on loopback and use SSH (above) |
| Copying does not reach the clipboard | the browser refused it (not a secure context, or no recent key or click) | open the page as http://localhost:PORT or http://127.0.0.1:PORT
|
| A key does nothing | the browser or the operating system keeps it | use another key or the menu |
How it is built and why: docs/web.md. The
reference: turboframe.web and turboframe.web.server.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links