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 | No tables, globals or memory support |
| 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;
WinterTC compliance
txiki.js aims to be WinterTC compliant. You can track the progress here.