Web Platform APIs
txiki.js implements a number of Web Platform APIs to provide a familiar environment for JavaScript developers.
Supported APIs
| API | Notes |
|---|---|
| Console | |
| Crypto | No subtle support |
| Direct Sockets | |
| Encoding API | |
| EventTarget | |
| fetch | |
| Import attributes | JSON, text, and bytes |
| Navigator.userAgentData | |
| Performance | |
| setTimeout, setInterval | |
| Storage API | |
| Streams API | |
| URL | |
| URLPattern | |
| URLSearchParams | |
| WebAssembly | Interpreter-based (WAMR); some limitations |
| WebSocket | Extensions |
| WebSocketStream | Extensions |
| Web Workers |
Extensions
WebSocket / WebSocketStream headers
Both WebSocket and WebSocketStream support setting custom HTTP headers on the client handshake request. This is a non-standard extension useful for authentication, API keys, and other scenarios where you need to send headers during the WebSocket upgrade.
Certain headers related to the WebSocket handshake itself (e.g. Connection, Upgrade, Sec-WebSocket-*) are forbidden and will throw a TypeError.
WebSocket
Instead of passing protocols as the second argument, pass an options object with headers (and optionally protocols):
const ws = new WebSocket('wss://example.com/ws', {
protocols: ['chat'],
headers: {
'Authorization': 'Bearer my-token',
'X-Custom-Header': 'value',
},
});
The headers option accepts a plain object, a Headers instance, or an array of [name, value] pairs.
WebSocketStream
Pass headers in the options object:
const wss = new WebSocketStream('wss://example.com/ws', {
protocols: ['chat'],
headers: {
'Authorization': 'Bearer my-token',
},
});
const { readable, writable } = await wss.opened;
WebAssembly
WebAssembly is powered by the WAMR interpreter. Most of the JavaScript API is implemented:
WebAssembly.validate(),compile(),instantiate(), and thecompileStreaming()/instantiateStreaming()variants.Module(includingModule.exports()andModule.imports()),Instance,Memory,Table,Global, and theCompileError/LinkError/RuntimeErrortypes.- Function, global, and memory imports.
- The reference-types, SIMD, and bulk-memory proposals.
externref/funcrefwork for exported functions, globals, and tables.
The following are not currently supported:
- Table imports — a
Tablecannot be supplied through the import object. Table exports work. - Reference types in imported functions —
externref/funcrefas parameters or results of JS-backed imported functions. - Multi-value returns from imported functions — multi-value returns from exported functions work.
- Re-instantiating a
Modulewith different imports — imports are resolved at the module level, so passing a new import object to a secondnew WebAssembly.Instance(module, ...)reuses the first set. UseWebAssembly.instantiate(bytes, importObject)to get independent instances.
To run WASI modules, see tjs:wasi.
WinterTC compliance
txiki.js aims to be WinterTC compliant. You can track the progress here.