Native modules
Checked against c1b2fa4 on 2026-11-10. The files it covers are unchanged since.
Sometimes a page needs something only native code can do: set the volume, take a screenshot, talk to a device. A native module is that API, written in the app’s native language and imported by the page:
import { phone } from 'niso:phone';const ok = await phone.screenshot();The API is declared once in WebIDL with [NisoModule=<name>]. niso-idl
generates the page’s import (with WebIDL’s argument conversions), its
TypeScript declarations, and a native base class to implement. Promises
settle from any thread, and event handler attributes become events the
native side sends. Calls cross the core’s C ABI as value lists
(niso_dom_define_module), so a new language needs only its own generator.
Android only today: the generator writes Kotlin/Java base classes, and
the Android host passes modules to the page (Engine’s modules). Swift is
next and not built. ihatemyphone’s phone module is the example in use.
Write a native module walks through one, and Native modules is the full design.