Core concepts
Capabilities
Detect available APIs without assuming that a runtime implements them.
Capabilities
Why capabilities matter
Different versions of the same runtime may expose different APIs. Edge platforms and build tools can also add or remove globals. Asking “is Fetch available?” is therefore safer than asking only “am I running on Node.js?”
From the adapter
const runtime = createRuntimeAdapter()
if (runtime.capabilities.webSocket) {
// WebSocket is available, or workerd provides its WebSocket model.
}
The map is frozen and cannot be modified.
Independent detection
import { detectRuntimeCapabilities, hasRuntimeCapability } from 'oruntime'
const capabilities = detectRuntimeCapabilities()
const canFetch = hasRuntimeCapability('fetch', capabilities)
Without a second argument, hasRuntimeCapability() performs a new detection.
Known capabilities
| Capability | Detection rule |
|---|---|
environmentVariables | Runtime provides an environment API |
commandLineArguments | Runtime provides user arguments |
currentWorkingDirectory | Runtime provides a current-directory API |
fileSystem | Runtime family provides server-side file access |
subprocess | Runtime family supports subprocesses |
signals | Runtime family supports process signals |
timers | setTimeout and clearTimeout are functions |
url | URL is a constructor |
fetch | fetch and AbortController are functions |
webSocket | WebSocket exists or the runtime is workerd |
webStreams | ReadableStream and WritableStream exist |
Capabilities versus permissions
A capability says that an API exists in this runtime family or context. It does not guarantee that one specific call is authorized:
if (runtime.capabilities.environmentVariables) {
// Deno may still deny access.
const token = runtime.getEnv('TOKEN')
}
Test injection
const capabilities = detectRuntimeCapabilities({
runtime: 'node',
globals: {
fetch: () => {},
AbortController,
setTimeout,
clearTimeout,
URL
}
})
Injection tests behavior without changing globalThis.