What are Extensions?
Extensions (located inext/) are modules that:
- Implement web platform standards (Fetch, WebSocket, Web Crypto, etc.)
- Provide system access through Rust operations (“ops”)
- Include both Rust and JavaScript code
- Are registered with the JavaScript runtime at initialization
Architecture
Each extension consists of:- Rust code (
lib.rs,*.rs) - Implements the low-level operations (ops) that JavaScript can call - JavaScript code (
*.js) - Provides the high-level APIs that users interact with - Extension definition - Declares ops, ESM modules, and dependencies
Core Extensions
Web Platform APIs
Web Extension
Core web APIs including streams, encoding, blobs, and events
Fetch
HTTP client implementation following the Fetch API standard
WebSocket
WebSocket client and server implementation
Web Crypto
Cryptographic operations following the Web Crypto API
Server APIs
HTTP Server
High-performance HTTP/1.1 and HTTP/2 server
Web Storage
localStorage and sessionStorage implementation
BroadcastChannel
Cross-context message broadcasting
Graphics and Compute
WebGPU
GPU access for graphics and compute operations
Extension Dependencies
Extensions can depend on other extensions. Common dependencies include:deno_webidl- WebIDL type conversionsdeno_web- Core web platform types and utilitiesdeno_fetch- HTTP client functionality
How Extensions Work
Operations (Ops)
Ops are Rust functions exposed to JavaScript:Deno.core.ops object.
Resources
Extensions manage resources (files, sockets, etc.) through resource IDs:Building Custom Extensions
To add a new extension:- Create a directory in
ext/ - Implement Rust ops in
lib.rs - Add JavaScript API in
.jsfiles - Register the extension in
runtime/worker.rs - Add tests
Performance Considerations
- Extensions use
#[op2(fast)]for optimized hot paths - Zero-copy operations with
#[buffer]and#[arraybuffer] - Async operations return futures that integrate with Tokio
- Resource pooling and caching where appropriate