@wtf/platform-browser
Documentation / @wtf/platform-browser
Run a program on @wtf/platform in a web page: browserPlatform({ window }) builds the page’s
platform from the window you pass in. It uses the window’s own objects where a web standard defines
the member, and a page’s versions of the other members otherwise. It also reads the environment a
page carries, and stops a program when the user leaves the page. It reads no global itself. A
page starts no process, so its platform is a Platform, with no spawn.
| Subpath | What you get |
|---|---|
. | BrowserWindow, PageEvents, EnvDocument, EnvElement: just the parts of each that it reads |
./platform | browserPlatform({ window, ...members }) |
./env | domEnv({ document, from, id, prefix }): a block of JSON or meta tags; importMetaEnv(import.meta.env) |
./dirs | browserDirs({ home, temp, cwd }): folders in the page’s own file system, with / as the working folder |
./terminal | browserTerminal({ window }): its console and prompt |
./open | windowOpen({ window, target }), locationOpen({ window }) |
./runtime | pageInterrupts({ window, hidden }): pagehide, or the page hidden, for runMain |
import type { BrowserWindow } from '@wtf/platform-browser'import { browserPlatform } from '@wtf/platform-browser/platform'
declare const window: BrowserWindow // the page's own
const platform = browserPlatform({ window })platform.console.info('Loaded at %s', platform.env.API_URL)performance, crypto, console, navigator, BroadcastChannel, MessageChannel and Worker
are the window’s own. navigator.storage.getDirectory() is the origin private file system, and its
root is the working folder: dirs.cwd is /. setTimeout, clearTimeout and fetch are called
on the window, as a browser requires. A browser’s window is a BrowserWindow as it is, which a
type test checks.
domEnv reads <script type="application/json" id="env"> and <meta name="env:NAME" content="…">.
Anyone who loads the page can read what it carries, so never put a secret there. importMetaEnv
keeps the string values of Vite’s import.meta.env. Vite gives a page only the variables that
start with its envPrefix (VITE_ by default), plus MODE and BASE_URL.
It uses only web standards, through the window you pass in, and depends on nothing but
@wtf/platform.
