Subscribe to IPage.Console to capture page console messages, including JavaScript errors and warnings. Also subscribe to IPage.PageError for uncaught exceptions in page code, and to IPage.Error if you need to know that the page crashed. These events describe different things; attach the handlers before navigation or before triggering the code you want to diagnose.
Choose the event that matches the failure
Puppeteer Sharp is a .NET port of the Node.js Puppeteer API, but its event handlers and event-argument types are part of the installed .NET package. The official Page API reference documents three useful signals for JavaScript diagnostics:
| Event | What it tells you | Use it for |
|---|---|---|
Console |
Page JavaScript called a console API; the event also reports page errors and warnings. | Console output and a broad first view of page-side diagnostics. |
PageError |
An uncaught exception happened within the page. | Exceptions that escaped page JavaScript rather than being handled there. |
Error |
The page crashed. | Crash detection, not as a synonym for every JavaScript exception. |
Use Console when you want to record what the page sends to its console. Add PageError when you need to distinguish uncaught exceptions from ordinary console output. Add Error when a crash matters to your automation or monitoring. A single failure may be reflected by more than one diagnostic signal; keep the event names in your logs so you can tell which one your handler received.
Attach handlers before navigating
Register event handlers immediately after you obtain the IPage, and before calling GoToAsync, clicking a control, evaluating a script, or otherwise triggering the behavior under investigation. If you subscribe after the page has already run, earlier console messages and exceptions cannot be recovered through those handlers.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
The documented Console event shape uses e.Message.Args. This handler follows the official example and writes each argument with its index:
page.Console += (sender, e) =>
{
for (var i = 0; i < e.Message.Args.Count; ++i)
{
System.Console.WriteLine($"{i}: {e.Message.Args[i]}");
}
};
This is useful for messages such as console.log("state", state), where the call supplies several arguments. The loop records each argument separately, rather than assuming every console call has one string. The Puppeteer Sharp Page reference shows this Console handler pattern.
For an error-focused log, you may also want to label the event and send output to standard error. Keep in mind that the example above records the message arguments; it does not establish a particular property name for the console message type. Check the API reference for the package version in your project before adding type-based filtering or formatting.
Rank #2
Log uncaught exceptions and crashes separately
Subscribe to PageError for uncaught page exceptions and Error for page crashes. The event names and meanings are documented, but event-argument members can vary with the installed release. The reviewed API material identifies PageErrorEventArgs without establishing a stable exception-property name, so avoid copying a guessed property such as e.Message or e.Exception.
page.PageError += (sender, e) =>
{
// Inspect PageErrorEventArgs for the installed Puppeteer Sharp version.
System.Console.Error.WriteLine($"PageError event: {e}");
};
page.Error += (sender, e) =>
{
// A page crash is distinct from an uncaught JavaScript exception.
System.Console.Error.WriteLine($"Page crash event: {e}");
};
The handlers above are a safe starting point for recording that an event occurred. To log the actual exception details, inspect the PageErrorEventArgs members exposed by your installed package and write the relevant member to your logger. Confirm the signature and available properties against the API documentation matching that release; the current online references do not establish which member name will be present in every version.
The official IPage API reference corroborates the separate event definitions. The examples and API pages do not identify a package release or publication date, so treat online signatures as guidance and verify them against the version your project restores.
Put the subscriptions in your page setup
In an existing Puppeteer Sharp program, the practical order is: create or obtain the page, subscribe, then navigate and perform the action being tested. The following shows where the Console handler belongs; page here is the IPage your existing browser setup has created.
- Obtain the page. Use your existing browser setup to create or select the
IPage. - Register diagnostics. Add the Console, PageError, and, if crash reporting is needed, Error handlers before the page starts the work.
- Start the scenario. Navigate to the target or trigger the interaction whose JavaScript behavior you want to observe.
- Review logs by event. Separate console output, uncaught page exceptions, and crashes. Then use the installed version’s event-argument members to enrich exception records.
For reference, the official Puppeteer Sharp examples describe the library as the .NET port of Puppeteer and demonstrate its basic usage. Use those examples alongside the API reference for your package version rather than assuming an event-argument shape from a different release.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Make the log useful without losing context
When you add these handlers to an application logger, include enough surrounding information to connect a message to its run: the page or scenario identifier, the event category, and when your own code observed it. That is application-side logging practice, not a guarantee about fields supplied by Puppeteer Sharp. Avoid relying on an event-argument property until you have checked that it exists in your version.
Rank #4
- Preserve Console arguments. A console call can pass multiple arguments; logging each one avoids silently dropping all but the first.
- Keep categories distinct. Label records as console output, uncaught page exception, or page crash so later analysis does not mistake one for another.
- Choose filtering deliberately. The event definitions cover console APIs and page errors or warnings. If you discard messages, make that a deliberate policy rather than assuming every Console event is an uncaught exception.
- Check the output destination. The samples use
System.Console. In a service or test runner, route the event data to the logging mechanism your application actually collects.
Troubleshooting
No events appear
First confirm that the handler is attached to the same IPage that navigates or runs the script. Subscribe before the action, then verify that the page actually calls a console API or produces the failure in that run. A handler added after a message was emitted cannot observe it retroactively.
Console messages appear, but the exception handler does not
Console and PageError represent different signals. A page may log an error or warning through a console API without throwing an uncaught exception. Conversely, use PageError for the documented uncaught-exception case; do not treat the absence of that event as proof that no console error was logged.
The page-error handler compiles differently from an example
Check the version of Puppeteer Sharp restored by the project and inspect that version’s event-argument type. Do not assume a property name from a different release. The official online API references do not state an exact release date or establish one exception member name for all versions.
Best Value
You see a crash, not an exception record
A page crash is represented by Error, while an uncaught exception is represented by PageError. Subscribe to both if your diagnostic goal includes both conditions, and retain the event category in the log.
Several arguments make the output confusing
The Console example emits an indexed line for every item in e.Message.Args. Preserve those indices or serialize the values with your application’s own structured logger; do not assume one event always corresponds to one simple text string.
Or skip the browser setup
If your goal is a clean image or PDF of a page rather than instrumenting its JavaScript in Puppeteer Sharp, ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. It does not replace the event handlers above or expose their page-error logging; it handles screenshot and PDF capture. Its clean-shot options accept cookie and consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture, and each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; responses identify the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients.
Example cURL request (see the ScreenshotNeo documentation):
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo includes 1,000 shots per month free with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan. Visit ScreenshotNeo for the service details, or sign up free to try 1,000 screenshots a month with no card.
Frequently Asked Questions
Does Puppeteer Sharp use the same event names as Node.js Puppeteer?
Puppeteer Sharp is a .NET port of the Node.js Puppeteer API, but use the C# API reference and package version for handler signatures and event-argument members.
Can these handlers recover errors from a page that already finished loading?
No. Event handlers observe events after subscription; they do not provide a replay of messages emitted before they were attached.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools

