demo · v131

Direct Sockets API

TCPSocket and UDPSocket from JavaScript - bypassing the HTTP layer entirely. Restricted to secure Isolated Web Apps with the direct-sockets permissions-policy gate. This page probes the origin, policy, and constructors before trying to open a connection so you can see which precondition failed.

scope Outside an Isolated Web App these constructors are either undefined or throw on open(). The probe + try-it buttons below show exactly what your browser exposes here.

precondition gates

error-name map

errorlikely gatewhat to check next
ReferenceError / constructor undefinedAPI not exposedCheck Chrome version, flag state, IWA install state, and isolated-app: origin.
SecurityErrorOrigin or isolation gateCheck secure context, cross-origin isolation, IWA scheme, and manifest permissions.
NotAllowedErrorPermissions-policy gateCheck direct-sockets, local/loopback/private network policy, and enterprise/user policy.
NetworkError / AbortErrorEndpoint or transport failureCheck DNS, port reachability, firewall, private-network target gates, and protocol handshake.

try it

the api

const tcp = new TCPSocket("example.com", 443);
const { readable, writable } = await tcp.opened;
// stream bytes either way
const w = writable.getWriter();
await w.write(new TextEncoder().encode("GET / HTTP/1.0\r\n\r\n"));

see also