TCP and UDP Raw Sockets: Direct Sockets, Manifest Permissions, and Multicast
When and how web apps use raw TCP and UDP, from manifest socket rules to Direct Sockets, servers, multicast, and verification in DevTools.
Most of this page follows Chrome platform documentation for low-level network access: the deprecated Chrome Apps model (chrome.sockets.tcp, chrome.sockets.udp, chrome.sockets.tcpServer) and the newer Direct Sockets API for Isolated Web Apps (IWAs). Ordinary web pages are still limited to HTTP, WebSocket, and WebRTC; raw sockets are an exception path with strict packaging and policy.
Why raw TCP and UDP instead of HTTP or WebSocket?
Section titled “Why raw TCP and UDP instead of HTTP or WebSocket?”Standard web applications are built around HTTP and higher-level APIs that are deliberately constrained. They cannot open arbitrary raw TCP or UDP connections, which blocks talking to legacy mail servers, printers, IoT firmware, or custom binary protocols without a native helper or browser plugin.
Standard web applications are typically restricted to specific communication protocols like HTTP and APIs like WebSocket and WebRTC. While these are powerful, they are designed to be tightly constrained to prevent abuse. They cannot establish raw TCP or UDP connections, which limits the ability of web apps to communicate with legacy systems or hardware devices that use their own non-web protocols.
— Google Chrome, Direct Sockets
The Direct Sockets documentation lists typical needs: IoT devices, SMTP/IMAP/IRC, SSH/Telnet/RDP-style clients, P2P overlays, UDP broadcast or multicast (for example coordinated playback), and apps that listen for inbound TCP or UDP. Chrome’s Isolated Web Apps developer policy narrows allowed motives to custom protocols with no higher-level Web API, fixed backend endpoints, or local-network discovery of hardware that is essential to the app.
Common conclusion: use raw sockets only when no suitable web-standard API exists, and expect stronger review and policy than for fetch or WebSocket.
Two platform paths: Chrome Apps sockets vs Direct Sockets
Section titled “Two platform paths: Chrome Apps sockets vs Direct Sockets”| Aspect | Chrome Apps (chrome.sockets.*) |
Isolated Web Apps (Direct Sockets) |
|---|---|---|
| Status | Chrome Apps support is being removed platform-wide | Intended for installed IWAs with cross-origin isolation |
| API style | Callbacks, numeric socketId |
TCPSocket, TCPServerSocket, UDPSocket + Streams |
| Permissions | Manifest sockets host patterns |
permissions_policy: direct-sockets, optional multicast/private |
| Socket ID scope | IDs not shared across socket API families | Separate object model per connection |
Important: Chrome will be removing support for Chrome Apps on all platforms. Chrome browser and the Chrome Web Store will continue to support extensions.
— Google Chrome, Network Communications
The Direct Sockets API addresses this limitation by enabling Isolated Web Apps (IWAs) to establish direct TCP and UDP connections without a relay server. With IWAs, thanks to additional security measures—such as strict Content Security Policy (CSP) and cross-origin isolation— this API can be safely exposed.
— Google Chrome, Direct Sockets
The legacy unified API is explicitly deprecated in favor of split APIs:
Starting with Chrome 33, this API is deprecated in favor of the sockets.udp, sockets.tcp and sockets.tcpServer APIs.
— Google Chrome, chrome.socket
New work should target Direct Sockets inside an IWA, not new Chrome Apps socket code.
Manifest sockets permissions: which hosts and ports Chrome Apps may use
Section titled “Manifest sockets permissions: which hosts and ports Chrome Apps may use”Chrome Apps that call chrome.sockets.tcp, chrome.sockets.udp, or chrome.sockets.tcpServer must declare the manifest sockets key (not merely a generic socket permission on the old API). The sockets manifest key defines which operations are allowed:
| Manifest branch | Operations governed |
|---|---|
sockets.udp.send |
Destination patterns for send |
sockets.udp.bind |
Local bind patterns |
sockets.udp.multicastMembership |
Multicast join patterns |
sockets.tcp.connect |
Outbound TCP connect targets |
sockets.tcpServer.listen |
Listen addresses and ports |
Host patterns use host, optional port, wildcards, and forms such as *:23, www.example.com:23, or empty string for broad connect rules. See Network Communications for grammar and examples—for instance { "tcp": { "connect" : "*:23" } } for Telnet-wide connect permission, or { "tcpServer": { "listen" : ":8080" } } for local TCP listen on port 8080.
Direct Sockets permissions_policy: enabling TCPSocket and UDPSocket in an IWA
Section titled “Direct Sockets permissions_policy: enabling TCPSocket and UDPSocket in an IWA”For IWAs, raw access is gated in the app manifest’s permissions_policy, not the Chrome Apps sockets table.
To use Direct Sockets, you must configure the permissions_policy object in your IWA manifest. You need to add the direct-sockets key to explicitly enable the API. Additionally, you must include the cross-origin-isolated key.
— Google Chrome, Direct Sockets
The direct-sockets key determines whether calls to new TCPSocket(…), new TCPServerSocket(…) or new UDPSocket(…) are allowed. If this policy is not set, these constructors will immediately reject with a NotAllowedError.
— Google Chrome, Direct Sockets
Multicast and local-network scenarios need extra keys:
{ "permissions_policy": { "direct-sockets": ["self"], "direct-sockets-multicast": ["self"], "direct-sockets-private": ["self"], "cross-origin-isolated": ["self"] }}That pattern is documented in Direct Sockets under multicast permissions. Policy text in Developer policy and security guidelines states that Direct Sockets grants raw TCP and UDP, including multicast and local network access—align your stated use case with the Allowed list there before shipping.
TCP client connections: connect, send, and receive data
Section titled “TCP client connections: connect, send, and receive data”Chrome Apps: chrome.sockets.tcp.connect and ArrayBuffer I/O
Section titled “Chrome Apps: chrome.sockets.tcp.connect and ArrayBuffer I/O”Network Communications describes the client flow: chrome.sockets.tcp.create, then connect with IP and port, keep socketId, then send and onReceive with ArrayBuffer payloads.
Receiving from (sockets.tcp.onReceive) and sending to a socket uses ArrayBuffer objects.
— Google Chrome, Network Communications
chrome.sockets.tcp documents connection state (connected, peerAddress, peerPort), default receive bufferSize 4096, paused (flow control via setPaused), and persistent sockets that survive event page unload when configured.
Socket IDs are not interchangeable across API families:
Note that socket IDs created from this API are not compatible with socket IDs created from other APIs, such as the deprecated socket API.
— Google Chrome, chrome.sockets.tcp
Direct Sockets: new TCPSocket(...) for outbound TCP
Section titled “Direct Sockets: new TCPSocket(...) for outbound TCP”Direct Sockets states that applications request TCP by constructing TCPSocket. Traffic is integrated with the Streams model rather than callback listeners.
Server-side TCP in Workers (not the browser)
Section titled “Server-side TCP in Workers (not the browser)”Cloudflare Workers TCP sockets expose TCP from the edge runtime (for example secureTransport and allowHalfOpen), which solves backend-to-origin connectivity—not in-page raw sockets. The Workers Binding API connects to destinations such as host:port from server code. Do not confuse that with IWA Direct Sockets or Chrome Apps client APIs.
TCP server and onAccept: listening sockets and paused client sockets
Section titled “TCP server and onAccept: listening sockets and paused client sockets”Chrome Apps act as TCP servers via chrome.sockets.tcpServer: create, listen, then onAccept with a client socket id used only with chrome.sockets.tcp.
When a new connection is established, onAccept is invoked with the clientSocketId of the new TCP connection. The client socket ID must be used with the sockets.tcp API. The socket of the new connection is paused by default. Un-pause it with sockets.tcp.setPaused to start receiving data.
— Google Chrome, Network Communications
The same paused-by-default rule appears on RFCOMM-style Bluetooth accept paths:
Accepted sockets are initially paused, set the onReceive listener first.
— Google Chrome, Bluetooth
For IWAs, Direct Sockets documents TCPServerSocket: bind (for example to ::), read accepted connections from a ReadableStream, each yielding a TCPSocket for bidirectional I/O—mirroring the Apps pattern but with streams instead of onAccept callbacks.
On listening Chrome App server sockets, paused controls whether accepts are dispatched immediately or held in the backlog queue (chrome.sockets.tcpServer).
UDP send, bind, and buffer limits: datagram behavior
Section titled “UDP send, bind, and buffer limits: datagram behavior”Chrome Apps UDP
Section titled “Chrome Apps UDP”Network Communications shows chrome.sockets.udp.create, bind on 0.0.0.0, onReceive, and send to a host and port. chrome.sockets.udp notes that received data is truncated to bufferSize, with default 4096—and packets larger than the buffer are lost:
If the buffer is too small to receive the UDP packet, data is lost. The default value is 4096.
— Google Chrome, chrome.sockets.udp
Direct Sockets UDP: connected mode vs bound mode
Section titled “Direct Sockets UDP: connected mode vs bound mode”Connected mode targets one remote host (client-style):
let udpSocket = new UDPSocket({ remoteAddress: 'example.com', remotePort: 7 });
let { readable, writable } = await udpSocket.opened;Bound mode binds locally and can exchange with arbitrary peers—typical for discovery:
let udpSocket = new UDPSocket({ localAddress: '::'});
let { readable, writable, localPort } = await udpSocket.opened;Both patterns are documented in Direct Sockets.
Multicast UDP: permissions, send, and joinGroup for discovery
Section titled “Multicast UDP: permissions, send, and joinGroup for discovery”Multicast is called out for kiosk sync and mDNS-like discovery in Direct Sockets. Sending uses a group address with optional multicastTimeToLive and multicastLoopback. Receiving requires bound mode, multicastAllowAddressSharing when multiple apps share a port, MulticastController.joinGroup, then reading the readable stream; leaveGroup when done.
Chrome Apps declare multicast capability separately via sockets.udp.multicastMembership patterns in the sockets manifest key. Service discovery on the local network also has chrome.mdns (“discover services over mDNS”), which is a related but distinct API from raw UDP multicast.
Common mistakes when using raw browser sockets
Section titled “Common mistakes when using raw browser sockets”- Mixing socket IDs between chrome.socket, chrome.sockets.tcp, chrome.bluetoothSocket, and other families—each namespace owns its identifiers.
- Forgetting to unpause accepted TCP (or Bluetooth) sockets before expecting
onReceivedata. - Assuming
connectedmeans the peer is still there on TCP in the legacy chrome.socket model—reads or writes may error after remote disconnect. - UDP receive buffer too small, silently dropping datagrams (chrome.sockets.udp).
- Building new Chrome Apps socket features while Network Communications and the sockets manifest document platform removal—plan IWA Direct Sockets instead.
- Omitting
direct-sockets-multicastordirect-sockets-privatewhen implementing local multicast discovery in an IWA (Direct Sockets). - Treating negative
resultCodeas success on Chrome Apps socket callbacks (chrome.sockets.tcp send/receive paths).
How to check this on your site
Section titled “How to check this on your site”-
Confirm which path you use: Chrome Apps manifest
socketsrules (sockets manifest key) or IWApermissions_policyfor Direct Sockets, includingcross-origin-isolatedand multicast keys if needed. -
For an IWA using Direct Sockets, open Chrome DevTools Network, select the socket entry, and use the Messages tab to inspect sent and received payloads (hex view)—as described in Direct Sockets (Chrome 138+).
-
For Chrome Apps UDP, verify
bindresultCodeand increasebufferSizeif large datagrams are truncated per chrome.sockets.udp. -
For TCP servers, confirm
listensucceeds (resultCodenot negative) and thatsetPaused(false)runs on each accepted client before relying on receive handlers (Network Communications). -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about, and we will correct or clarify it.