Constructor options for the Bun.WebSocket client
Search the reference...
/
type
Options for the TLS connection.
Supports full TLS configuration including custom CA certificates, client certificates, and other TLS settings (same as fetch).
// Using BunFile for certificates
const ws = new WebSocket("wss:http://example.com", {
tls: {
ca: Bun.file("./ca.pem")
}
});
// Using Buffer
const ws = new WebSocket("wss:http://example.com", {
tls: {
ca: fs.readFileSync("./ca.pem")
}
});
Headers to send to the server
HTTP proxy to use for the WebSocket connection.
Can be a string URL or an object with url and optional headers.
// String format
const ws = new WebSocket("wss:http://example.com", {
proxy: "http://proxy.example.com:8080"
});
// With credentials
const ws = new WebSocket("wss:http://example.com", {
proxy: "http://user:pass@proxy.example.com:8080"
});
// Object format with custom headers
const ws = new WebSocket("wss:http://example.com", {
proxy: {
url: "http://proxy.example.com:8080",
headers: {
"Proxy-Authorization": "Bearer token"
}
}
});
Whether to offer the permessage-deflate extension in the WebSocket upgrade request. Pass false to suppress the Sec-WebSocket-Extensions header entirely — matching the ws package's perMessageDeflate: false option.
Defaults to true (the upgrade request advertises permessage-deflate; client_max_window_bits). Any falsy value (false, null, 0, "", explicit undefined) disables the offer.
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →Bun.WebSocketOptions TypeScript type alias | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- Constructor options for the `Bun.WebSocket` client