Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright BinaryPipeTransport

From Leeroopedia

Template:Implementation Page

Overview

BinaryPipeTransport implements a length-prefixed binary pipe transport for communicating with browser processes, using a 4-byte header to frame messages over stdin/stdout.

Description

The PipeTransport class (in the utils directory, distinct from the server-level PipeTransport) provides binary-framed communication over Node.js streams. Unlike the JSON-newline delimited server PipeTransport, this version:

  • Uses a 4-byte length prefix (configurable endianness) before each message
  • Handles message fragmentation and reassembly from the stream
  • Supports both big-endian and little-endian byte orders
  • Uses string-based messages rather than parsed JSON objects
  • Provides an optional ClosableStream for explicit close support

Usage

Used for binary protocol communication with browser processes that use length-prefixed framing.

Code Reference

Source Location

packages/playwright-core/src/server/utils/pipeTransport.ts (104 lines)

Class Signature

export class PipeTransport {
  onmessage?: (message: string) => void;
  onclose?: () => void;
  constructor(pipeWrite: WritableStream, pipeRead: ReadableStream, closeable?: ClosableStream, endian?: 'be' | 'le')
  send(message: string): void
  close(): void
}

Import

import { PipeTransport } from './server/utils/pipeTransport';

I/O Contract

Inputs

  • pipeWrite: WritableStream -- writable stream for outgoing messages
  • pipeRead: ReadableStream -- readable stream for incoming messages
  • endian: 'be' | 'le' -- byte order for length prefix (default: 'le')

Outputs

  • Dispatches complete string messages via onmessage
  • Fires onclose when the stream closes

Protocol

  • 4-byte length header followed by UTF-8 encoded message body

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment