Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
C++

How to Fix Selenium WebDriver C# Timeouts When Printing PDFs with Headless Chrome

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Selenium PDF timeout is not automatically fixed by increasing every wait. First identify whether navigation, JavaScript, element lookup, the print command, or the remote session actually timed out. Then verify headless Chromium, matching Chrome and ChromeDriver major versions, and driver logs. Use Selenium’s built-in PrintOptions and driver.Print() path first; only use direct CDP printing when you need an option or timeout control that the built-in API does not expose.

What Selenium is waiting for

Selenium has separate timeout categories, and they control different operations:

Timeout Controls What it does not prove
Page-load timeout Navigation and page loading It is not documented as the timeout for the built-in PDF print command.
Script timeout ExecuteAsyncScript and related asynchronous script execution It is not a general print-command timeout.
Implicit wait Element-location searches It does not make PDF generation wait longer.
Remote or transport timeout Communication with Grid, a remote driver, or a proxy It may be outside the browser’s own rendering time.

Selenium’s current Browser Options documentation lists new-session defaults of 300,000 ms for page load, 30,000 ms for scripts, and 0 ms for implicit wait. These are category defaults, not a recommended PDF-print value. The official .NET timeout API does not establish an ITimeouts property that extends the response wait for Selenium’s built-in print operation.

Use the documented C# print workflow first

Chromium printing requires headless mode. Navigate to the page, call Print, and save the returned PDF bytes. The following complete example follows Selenium’s documented shape and deliberately avoids an arbitrary timeout increase.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.IO;

var options = new ChromeOptions();
options.AddArgument("--headless");

using var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://example.com");

var printOptions = new PrintOptions();
PrintDocument pdf = driver.Print(printOptions);

string base64 = pdf.AsBase64EncodedString;
if (!base64.StartsWith("JVBER", StringComparison.Ordinal))
{
    throw new InvalidDataException("The response does not look like a PDF.");
}

File.WriteAllBytes("page.pdf", Convert.FromBase64String(base64));

The JVBER prefix is the base64 representation of a PDF header and is the check shown in Selenium’s official sample. Dispose the driver in application code, as in the using declaration.

Make the first reproduction small

  1. Run the example against a small, known page.
  2. Confirm that navigation completes before driver.Print() is called.
  3. Compare that result with the failing page.
  4. If only the complex page fails, investigate its rendering work: external resources, fonts, lazy content, scripts, page size, and unusually long network activity.

This comparison is diagnostic, not proof that any particular page feature is the cause. Capture the complete exception and driver log before changing settings.

Diagnostic sequence for a timeout

1. Record the exact operation

Save the full exception type and message, stack trace, and the last command your code issued. A timeout during GoToUrl is a navigation problem; an exception from Print is a browser-print or command-path problem; a failure from ExecuteAsyncScript belongs to the script timeout; and a Grid or HTTP-client timeout may be a transport problem. These cases need different fixes.

2. Confirm headless Chromium

Use a Chrome option that actually starts the session headlessly. Selenium’s print guide specifically requires headless Chromium for page printing. If your infrastructure adds its own arguments, log the final argument list and verify that a different profile, container image, or remote node is not replacing the expected browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Check browser and driver versions

Chrome and ChromeDriver major versions should match. A mismatch can prevent a session from starting or cause commands to fail unpredictably. Record all three versions:

  • the installed Chrome or Chromium major version;
  • the ChromeDriver major version;
  • the Selenium.WebDriver NuGet package version.

The package version matters because .NET APIs and versioned CDP adapters can differ.

4. Turn on ChromeDriver service logging

Driver logs provide evidence at the browser/driver boundary instead of leaving you with only the .NET exception. Configure a ChromeDriverService and write its log to a file:

using OpenQA.Selenium.Chrome;

var service = ChromeDriverService.CreateDefaultService();
service.LogPath = Path.GetFullPath("chromedriver.log");
service.EnableVerboseLogging = true;

var options = new ChromeOptions();
options.AddArgument("--headless");

using var driver = new ChromeDriver(service, options);

Keep the log with the failing run. It can reveal startup errors, rejected capabilities, browser crashes, or a driver-side command failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Separate local failures from remote failures

Repeat the minimal case locally and, if applicable, on the Grid or remote service. A local print failure points toward browser rendering, versions, or the page. A local success followed by a remote timeout points toward node resources, command routing, proxy limits, or a remote session timeout. Report which environment reproduces the issue.

Change only the timeout that matches the work

If navigation is the operation that times out, set a deliberate page-load timeout and investigate why the page is slow:

driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(90);
driver.Navigate().GoToUrl("https://example.com");

If an asynchronous JavaScript call is timing out, set the script timeout for that call:

driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(30);

Use an implicit wait only for element searches, and prefer explicit conditions when a particular state matters:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
driver.Manage().Timeouts().ImplicitWait = TimeSpan.Zero;

Do not present any of these values as a universal PDF-print fix. The official Selenium material reviewed does not say that enlarging page-load or script timeout extends the response wait for driver.Print(). If the exception is raised by printing itself, diagnose the command path rather than blindly increasing unrelated waits.

When direct CDP printing is appropriate

Selenium’s .NET PageAdapter API for a versioned adapter documents a PrintToPDF method with an optional millisecondsTimeout parameter. That is the relevant command-level control when you deliberately call Chrome DevTools Protocol (CDP) instead of the built-in WebDriver print API.

CDP is version-dependent and Selenium warns that it is not designed as a stable, cross-version testing API. Pin and test the Selenium package, adapter version, and Chrome version together. Verify that the PageAdapter version available in your project matches the browser you deploy.

Choose CDP only when the built-in PrintOptions surface cannot express a required PDF setting or when you have a controlled compatibility matrix. It is not a universal replacement for driver.Print(). The built-in API is the normal Selenium page-print workflow; direct CDP adds maintenance responsibility.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure patterns and fixes

Symptom Likely scope Action
Timeout while opening the URL Navigation Check page-load timing, network access, redirects, and page-load logs. Set page-load timeout only if it matches this operation.
Exception occurs at driver.Print() Print/browser command Confirm headless mode, reproduce on a small page, collect ChromeDriver logs, and check versions. Do not assume script timeout is involved.
Session cannot start Browser/driver startup Match Chrome and ChromeDriver major versions and inspect service logs.
Works locally but fails on Grid Remote node or transport Compare node browser versions, resource limits, proxy settings, and remote command timeouts.
Only a media-heavy page fails Page-specific rendering Reduce the page to a minimal reproduction and inspect resources, fonts, scripts, and page dimensions.
CDP call breaks after a browser update Protocol compatibility Review the versioned adapter and Chrome/CDP compatibility; return to built-in printing if it satisfies the requirement.

Reliability and cost considerations

  • Keep browser and driver versions pinned in CI rather than allowing silent major-version changes.
  • Archive the exception, Selenium package version, Chrome and ChromeDriver versions, execution mode, URL class, and driver log for each failure.
  • Use a small deterministic page as a health check before diagnosing production pages.
  • Give remote sessions enough CPU, memory, disk, and shared-memory capacity for the page being rendered; distinguish an exhausted node from a WebDriver timeout.
  • Set page-specific print options deliberately, but do not hide a rendering defect by adding very large global waits.
  • When a page depends on authentication, ensure the session has the required cookies or credentials before printing; a login redirect can look like a navigation or print problem.

Or skip the browser setup

For a one-call website capture, ScreenshotNeo accepts a URL and returns a PNG, JPEG, WebP, or PDF. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server gives AI agents tools named take_screenshot, get_page_info, and capture_pdf.

For PDF output, the API call is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for PDF parameters, paper size, margins, orientation, page ranges, waiting rules, authentication, and other options. The service includes 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

What to include when asking for help

  • Full exception type, message, and stack trace.
  • The exact line or WebDriver command that timed out.
  • Selenium.WebDriver, Chrome, ChromeDriver, and (if used) PageAdapter versions.
  • Whether the run is local, containerized, Grid, or another remote session.
  • Whether navigation succeeded and whether a small page prints successfully.
  • The failing page’s relevant characteristics, such as heavy scripts, fonts, authentication, or very large output.
  • ChromeDriver service logs from the same run.

Frequently Asked Questions

Does Selenium provide one global PDF-print timeout in C#?

The documented timeout categories cover navigation, asynchronous scripts, and element lookup. The reviewed .NET timeout API does not establish a general built-in print timeout.

Should I switch to CDP immediately after a print timeout?

No. First verify headless mode, matching browser and driver versions, logs, and a minimal reproduction. CDP can expose a command timeout, but its version-dependent compatibility adds maintenance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is the first version detail to check?

Check that Chrome and ChromeDriver major versions match, then record the Selenium.WebDriver package and any versioned PageAdapter in use.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.