How to Wait for Browser Process Output in Puppeteer
Use @puppeteer/browsers’ waitForLineOutput() to wait for a matching browser-process line. Learn when to use dumpio, recent logs, or page console events instead.
To wait for a browser-process output line that matches a pattern, use Process.waitForLineOutput(regex, timeout) from @puppeteer/browsers. It returns a Promise<string>. Use Puppeteer’s dumpio: true when you want browser stdout and stderr forwarded to Node’s terminal, and use page.on('console') for messages logged by JavaScript inside the page. These are different output channels.
The examples below use the documented method signature. Check the reference for the version installed in your project: the method-specific reference reviewed is for version 25.3.0, while the current Process class reference is for version 25.12.0. The API references establish the method and return type but do not specify every detail of buffering, matching, or timeout behavior. waitForLineOutput() reference · Process class reference
Wait for a matching line with @puppeteer/browsers
Call waitForLineOutput() on the Process returned by launch(). Pass a JavaScript RegExp and, optionally, a timeout in milliseconds. The promise resolves with the matching line as a string.
import {launch} from '@puppeteer/browsers';
const process = await launch({
// Supply the launch options required by your installed package version.
});
try {
const matchingLine = await process.waitForLineOutput(/your-pattern/, 30_000);
console.log('Matching browser output:', matchingLine);
} finally {
// Clean up the launched browser process using the lifecycle API
// available in your installed @puppeteer/browsers version.
}
This is an API usage pattern, not a complete launch configuration: the package’s launch options depend on your setup. Consult the installed version’s launch options reference for required values, and arrange cleanup for your application’s lifecycle. Do not assume the method’s undocumented details, such as whether it searches previously emitted output or how it handles partial lines.
Install the package
If the project does not already depend on @puppeteer/browsers, add it with your package manager:
npm install @puppeteer/browsers
Use the API reference corresponding to the installed package version. The documentation pages reviewed do not establish all matching, buffering, or timeout edge cases, so verify those details against that version if your program relies on them.
Choose a pattern and timeout
- Pattern: provide a
RegExpthat identifies the output line you need. Make it specific enough to avoid matching an unrelated line. - Timeout: the method accepts an optional timeout. Set one when the program must stop waiting if the expected output never arrives. The API reference does not document all timeout semantics; check your installed version if exact rejection behavior matters.
- Returned value: the documented return type is
Promise<string>. Await it before using the matching output.
Choose the right output channel
| What you need | Use | Important boundary |
|---|---|---|
| Wait in code for a matching browser-process line | Process.waitForLineOutput(regex, timeout?) |
Call it on the @puppeteer/browsers Process returned by its launch API. |
| Show browser executable stdout and stderr in Node’s terminal | dumpio: true in Puppeteer launch options |
Forwards streams; it is not a promise that resolves with a matching line. |
| Inspect recent browser output after it has been emitted | process.getRecentLogs() |
The current Process API describes recent browser stderr and stdout output. |
Handle console.log() from page JavaScript |
page.on('console', handler) |
Page console events are separate from browser executable stdout and stderr. |
| Get the child process for a Puppeteer-launched browser | browser.process() |
It returns ChildProcess | null; it is null when connected using Puppeteer.connect(). |
These APIs are not interchangeable. In particular, Puppeteer’s dumpio forwards browser stdout and stderr to Node’s corresponding streams. The pipe launch option configures additional stdio streams for browser automation instead of WebSocket; it does not mean “print browser logs.” See the official LaunchOptions reference and debugging guide.
Forward browser logs with dumpio
Use this when you want to see executable output while debugging a Puppeteer launch. The default for dumpio is false; setting it to true forwards browser stdout and stderr to Node’s stdout and stderr.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({
dumpio: true,
});
try {
const page = await browser.newPage();
await page.goto('https://example.com');
} finally {
await browser.close();
}
Use the other launch options required by your environment, such as those for your installed Puppeteer version and browser setup. The debugging guide recommends enabling browser process output when investigating unexpected crashes or launch failures. Puppeteer debugging guide
Capture console messages from page JavaScript
Code running in a page does not directly write its console.log() messages to Node’s console. Subscribe to the page’s console event if you need to handle those messages in your Node program.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
page.on('console', message => {
console.log(`[page ${message.type()}] ${message.text()}`);
});
await page.goto('https://example.com');
await page.evaluate(() => console.log('Message from page JavaScript'));
} finally {
await browser.close();
}
This handles page console events, not the browser executable’s process streams. For a direct process reference, use Browser.process() when the browser was launched locally. The method returns ChildProcess | null, and is documented as null for a browser attached through Puppeteer.connect().
Or skip the browser setup
If your goal is to capture a website image or PDF rather than debug a local browser process, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
const bytes = new Uint8Array(await res.arrayBuffer());
await (await import('node:fs/promises')).writeFile('shot.webp', bytes);
Cookie banners, newsletter popups, and chat widgets are removed before the shot. Bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents use screenshot tools. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for 1,000 free screenshots a month, no card required.
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| The call does not compile or the method is missing | The installed package version may differ from the reference, or the value is not an @puppeteer/browsers Process. |
Check the installed package version and its Process API; call the method on the Process returned by the package’s launch API. |
| The promise keeps waiting | The expected line may not be emitted, or the pattern may not match it. Detailed timeout behavior is not established by the references reviewed. | Confirm that the browser reaches the code path that emits the output, narrow or correct the regular expression, and set an appropriate timeout. Use dumpio: true to see forwarded output while diagnosing. |
| Browser output does not appear in Node’s terminal | dumpio defaults to false, or you are looking for page JavaScript logs rather than executable output. |
Set dumpio: true for executable stdout and stderr. Use page.on('console') for page messages. |
browser.process() returns null |
The browser may have been attached with Puppeteer.connect(). |
A connected browser has no local child process exposed by this method. Use the connection’s available debugging path, or launch a local browser when you need its child process. |
| Recent output is needed after the event | A line-waiting call is not the same as retrieving the recent log buffer. | Check whether getRecentLogs() is available on the Process API for your installed version. |
| Page logs and browser logs seem out of order or incomplete | They come from different channels, and the reviewed references do not specify stream ordering or buffering guarantees. | Handle page console events separately from process output. Consult the exact installed version’s documentation or implementation if ordering and buffering are essential. |
Performance, reliability, and cost
- Wait only for the signal you need. A specific pattern and a bounded timeout help keep a waiting task from holding up your application indefinitely. Choose the timeout based on your workflow; the documentation reviewed does not provide a recommended value.
- Do not treat terminal forwarding as programmatic matching.
dumpiois useful for diagnosis, whilewaitForLineOutput()is the documented method for awaiting a matching line. - Keep process ownership clear. Close launched browsers through the lifecycle your application uses, including on errors. A browser attached with
Puppeteer.connect()does not expose a local child process throughbrowser.process(). - Use the right channel for reliable handling. If your code depends on exact matching, timeout rejection, buffering, or event ordering, verify those semantics for the precise installed package version; they are not all covered by the references cited here.
- Budget considerations. These Puppeteer APIs do not describe a per-output-line charge. Browser execution still uses the resources of the environment running it. For hosted website captures, ScreenshotNeo bills only clean shots; its response identifies the page verdict and billing status in headers.
FAQ
Does waitForLineOutput read page console.log messages?
It waits for browser-process output. Use page.on('console') to receive console messages from JavaScript running inside the page.
Can I use browser.process() after Puppeteer.connect()?
The documented return type is ChildProcess | null, and it is null for a browser attached with Puppeteer.connect().
Should I use dumpio or pipe to print browser logs?
Use dumpio: true to forward browser stdout and stderr to Node’s stdout and stderr. The pipe option configures automation streams instead.
Does the method return the full browser log?
The documented return type is one string for the matching line. The method reference reviewed does not establish full-log or buffering semantics. The current Process API separately lists getRecentLogs() for recent browser output.


