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:Puppeteer Puppeteer PipeTransport

From Leeroopedia
Property Value
sources packages/puppeteer-core/src/node/PipeTransport.ts
domains Node, Transport, Pipe
last_updated 2026-02-12 00:00 GMT

Overview

Description

The PipeTransport class implements the ConnectionTransport interface using Node.js stdio pipes. It provides an alternative to WebSocket-based communication for connecting Puppeteer to the browser's DevTools protocol, offering lower latency by avoiding the WebSocket overhead.

When Chrome is launched with the --remote-debugging-pipe flag, it exposes its DevTools protocol on file descriptors 3 (write) and 4 (read) instead of a WebSocket server. PipeTransport reads from and writes to these file descriptors using the null byte (\0) as a message delimiter.

The class works as follows:

  • Constructor -- Wraps the pipe read and write streams in Puppeteer's EventEmitter wrappers (tracked via a DisposableStack for cleanup). It listens for data events on the read pipe and dispatches complete messages, and listens for close and error events.
  • send -- Writes a message string followed by a null byte delimiter to the write pipe. Asserts that the transport is not closed before writing.
  • #dispatch -- An internal method that buffers incoming data chunks and splits them on null byte boundaries. Complete messages are dispatched asynchronously via setImmediate to the onmessage callback.
  • close -- Marks the transport as closed and disposes all event listener subscriptions.

Usage

PipeTransport is used internally by BrowserLauncher.createCdpPipeConnection when the user launches a browser with pipe: true. It is not part of the public API.

Code Reference

Source Location

packages/puppeteer-core/src/node/PipeTransport.ts

Signature

export class PipeTransport implements ConnectionTransport {
  onclose?: () => void;
  onmessage?: (value: string) => void;

  constructor(
    pipeWrite: NodeJS.WritableStream,
    pipeRead: NodeJS.ReadableStream,
  );

  send(message: string): void;
  close(): void;
}

Import

import {PipeTransport} from '../node/PipeTransport.js';

I/O Contract

Method Parameter Type Description
constructor pipeWrite NodeJS.WritableStream The writable pipe stream (browser's stdin / fd 3)
constructor pipeRead NodeJS.ReadableStream The readable pipe stream (browser's stdout / fd 4)
send message string The string message to send to the browser
Method Return Type Description
send void Writes the message followed by a null byte delimiter
close void Closes the transport and disposes event subscriptions
Callback Type Description
onmessage (value: string) => void Called for each complete null-delimited message received
onclose () => void Called when the read pipe closes

Usage Examples

// Used internally by BrowserLauncher when launching with pipe: true
const browser = await puppeteer.launch({
  pipe: true, // Uses PipeTransport instead of WebSocket
});
// Internal usage within BrowserLauncher
const {3: pipeWrite, 4: pipeRead} = browserProcess.nodeProcess.stdio;
const transport = new PipeTransport(
  pipeWrite as NodeJS.WritableStream,
  pipeRead as NodeJS.ReadableStream,
);

transport.onmessage = (message: string) => {
  const response = JSON.parse(message);
  handleResponse(response);
};

transport.send(JSON.stringify({ id: 1, method: 'Target.getTargets' }));

Related Pages

Page Connections

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