Skip to main content

Web Platform APIs

txiki.js implements a number of Web Platform APIs to provide a familiar environment for JavaScript developers.

Supported APIs

APINotes
Console
CryptoNo subtle support
Direct Sockets
Encoding API
EventTarget
fetch
Import attributesJSON, text, and bytes
Navigator.userAgentData
Performance
setTimeout, setInterval
Storage API
Streams API
URL
URLPattern
URLSearchParams
WebAssemblyInterpreter-based (WAMR); some limitations
WebSocketExtensions
WebSocketStreamExtensions
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 the compileStreaming() / instantiateStreaming() variants.
  • Module (including Module.exports() and Module.imports()), Instance, Memory, Table, Global, and the CompileError / LinkError / RuntimeError types.
  • Function, global, and memory imports.
  • The reference-types, SIMD, and bulk-memory proposals. externref / funcref work for exported functions, globals, and tables.

The following are not currently supported:

  • Table imports — a Table cannot be supplied through the import object. Table exports work.
  • Reference types in imported functionsexternref / funcref as parameters or results of JS-backed imported functions.
  • Multi-value returns from imported functions — multi-value returns from exported functions work.
  • Re-instantiating a Module with different imports — imports are resolved at the module level, so passing a new import object to a second new WebAssembly.Instance(module, ...) reuses the first set. Use WebAssembly.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.