某些 Web API 在像 Bun 這樣的伺服器優先執行環境中並不相關,例如 DOM API 或 History API。 然而,許多其他的 Web API 在瀏覽器環境之外也廣泛適用;在可能的情況下,Bun 實作了這些 Web 標準 API,而不是引入新的 API。
以下 Web API 得到部分或完整支援。
HTTP | fetch Response Request Headers AbortController AbortSignal |
URL | URL URLSearchParams |
Web Worker | Worker self.postMessage structuredClone MessagePort MessageChannel BroadcastChannel . |
Stream | ReadableStream WritableStream TransformStream ByteLengthQueuingStrategy CountQueuingStrategy 以及相關類別 |
Blob | Blob |
WebSocket | WebSocket |
編碼和解碼 | atob btoa TextEncoder TextDecoder |
JSON | JSON |
超時 | setTimeout clearTimeout |
間隔 | setInterval clearInterval |
加密 | crypto SubtleCrypto CryptoKey |
除錯 | |
微任務 | queueMicrotask |
錯誤 | reportError |
使用者互動 | alert confirm prompt (適用於互動式 CLI) |
Realm | ShadowRealm |
事件 | EventTarget Event ErrorEvent CloseEvent MessageEvent |