bkr

reference

Web-standard globals

Installed on globalThis in both the main thread and module workers.

Fetch and HTTP

fetch(input, init?) -> Promise<Response>

HTTP/1.1 client built on net. Requires --allow-net for the target host and port.

  • Follows up to 20 redirects, re-checking --allow-net on each hop and stripping Authorization and Cookie across origins.
  • Verifies TLS certificates and hostnames on https: requests and decodes gzip and deflate response bodies.
  • Unread response bodies do not keep the event loop alive.

Request · Response

Standard Fetch classes with body (ReadableStream), bodyUsed, text(), bytes(), json(), arrayBuffer(), blob(), and clone(). Response also provides Response.json(data, init?), Response.redirect(url, status = 302), and Response.error().

Headers

Case-insensitive header map. Preserves multiple Set-Cookie values via getSetCookie().

URL · URLSearchParams

WHATWG URL (including URL.canParse and URL.parse) with a native fast path for plain http: and https: URLs, plus URLSearchParams.

Blob · File

In-memory binary blobs with size, type, slice(), text(), bytes(), arrayBuffer(), and stream(). File adds name and lastModified.

WebSockets

new WebSocket(url, protocols?)

WebSocket client (and the same class returned by upgradeWebSocket on the server). Client connections run over net on ws: or wss:, support messages up to 64 MiB, and require --allow-net.

  • Members: url, readyState, protocol, bufferedAmount, binaryType ("blob" or "arraybuffer"), send(data), close(code?, reason?), and open, message, error, and close events.

CloseEvent

Dispatched on WebSocket close with code, reason, and wasClean.

Streams and compression

ReadableStream · ReadableStreamDefaultReader

Default-controller readable streams with getReader(), pipeTo(), pipeThrough(), tee(), values(), [Symbol.asyncIterator](), and ReadableStream.from(iterable).

WritableStream · WritableStreamDefaultWriter

Writable stream and default writer with ready, closed, write(), close(), and abort().

TransformStream

{ readable, writable } transform pair.

TextEncoderStream · TextDecoderStream

Streaming UTF-8 encoder and decoder transforms; handles multi-byte sequences split across chunk boundaries.

new CompressionStream(format) · new DecompressionStream(format)

Streaming compression and decompression over system zlib. format is "gzip", "deflate", or "deflate-raw".

Web Crypto

crypto.getRandomValues(typedArray) · crypto.randomUUID()

Fill an integer TypedArray (up to 65,536 bytes) with system randomness, or generate a v4 UUID string.

crypto.subtle

Lazily initialized SubtleCrypto running on the native thread pool via OpenSSL 3.

  • digest: SHA-1, SHA-256, SHA-384, SHA-512
  • sign / verify: HMAC
  • encrypt / decrypt: AES-GCM, AES-CBC, AES-CTR
  • deriveBits / deriveKey: PBKDF2 (up to 20M iterations), HKDF
  • generateKey / importKey / exportKey: raw and jwk (oct) secret keys

Workers and structured cloning

new Worker(url, { type = "module", name = "" }?)

Spawn an isolated module worker thread (up to 64 live workers per process). Requires --allow-read for the target module path. Exposes postMessage(value, transferOrOptions?), terminate(), and message, error, and close events.

self · name · postMessage(value, transferOrOptions?) · close()

Globals inside a worker thread, alongside all built-in modules and the parent's permissions (with prompting disabled).

structuredClone(value, { transfer }?)

Deep-clone primitives, plain objects, arrays, Map, Set, Date, RegExp, standard Error types, ArrayBuffer (including resizable and immutable), and TypedArrays/DataViews while preserving cycles and shared references.

  • Transferables: Listed ArrayBuffers are copied and detached on the sender (not zero-copy).
  • Limits: 16 MiB binary data per clone/message, 64 MiB queued per worker direction, and 32,768 graph nodes or entries.

Timers, events, and encoding

setTimeout · clearTimeout · setInterval · clearInterval · setImmediate · clearImmediate · queueMicrotask

Timers backed by nanosecond native deadlines on kqueue/epoll (1 ms minimum JS delay), next-turn immediates, and microtask scheduling.

performance: { now(), timeOrigin }

Monotonic high-resolution millisecond clock.

Event · EventTarget · MessageEvent · ErrorEvent · PromiseRejectionEvent · AbortController · AbortSignal

Standard event classes, global addEventListener / removeEventListener / dispatchEvent, and AbortSignal.abort(), AbortSignal.timeout(ms), and AbortSignal.any(signals).

TextEncoder · TextDecoder · btoa(str) · atob(b64)

Native UTF-8 encoding and decoding (with encodeInto, fatal, and ignoreBOM) plus Base64 helpers.

DOMException · SystemError · onunhandledrejection

Failed system and permission calls throw or reject with a SystemError carrying an errno or runtime code (for example "ENOENT", or "PERMISSION_DENIED" where err.name is "PermissionDenied").

Unhandled promise rejections dispatch a cancelable unhandledrejection event on globalThis and exit with status 1 unless event.preventDefault() is called.