Implementation:Microsoft Playwright PipeTransport
Overview
PipeTransport implements the ConnectionTransport interface over stdio pipes, enabling JSON-based protocol communication with browser processes via stdin/stdout.
Description
The PipeTransport class provides a newline-delimited JSON transport over Node.js readable/writable streams. It reads incoming data from the pipe, buffers it, and splits on null bytes (\0) to extract complete JSON messages. Each message is parsed and dispatched via the onmessage callback. Outgoing messages are serialized to JSON with a null byte delimiter.
The class uses makeWaitForNextTask to defer message processing to the next microtask, preventing stack overflow with deeply nested message chains.
Usage
Used internally to communicate with browser processes launched with pipe-based stdio transport instead of WebSocket.
Code Reference
Source Location
packages/playwright-core/src/server/pipeTransport.ts (94 lines)
Class Signature
export class PipeTransport implements ConnectionTransport {
onmessage?: (message: ProtocolResponse) => void;
constructor(pipeWrite: NodeJS.WritableStream, pipeRead: NodeJS.ReadableStream)
send(message: ProtocolRequest): void
close(): void
}
Import
import { PipeTransport } from './server/pipeTransport';
I/O Contract
Inputs
pipeWrite: NodeJS.WritableStream-- writable pipe (browser's stdin)pipeRead: NodeJS.ReadableStream-- readable pipe (browser's stdout)
Outputs
- Dispatches parsed
ProtocolResponseobjects viaonmessage - Fires
onclosewhen the pipe stream closes
Protocol
- Messages are JSON-encoded with null byte (
\0) as delimiter
Related Pages
- Microsoft_Playwright_WebSocketTransport -- WebSocket-based alternative transport
- Microsoft_Playwright_BinaryPipeTransport -- Binary length-prefixed pipe transport
- Microsoft_Playwright_FfConnection -- Firefox connection using transport