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

If a Puppeteer PDF sometimes misses charts, data, or other late-rendered content, wait for the application to say that the page is ready before calling page.pdf(). Navigation completion and network idleness are useful milestones, but neither defines when your own app has finished the work that belongs in its PDF. Add an app-owned readiness flag or event, reset it for each export, and have Puppeteer wait for it with a finite timeout.

Why Puppeteer PDFs can capture the wrong state

A PDF race happens when printing starts before the application has completed asynchronous work that affects the document. The browser may have loaded the route while JavaScript is still fetching report data, arranging a client-side layout, drawing a chart, or loading an image. Calling page.pdf() at that point can produce a valid PDF of an incomplete page.

Puppeteer can wait for browser events and page conditions, but it cannot infer what “finished” means for every application. A dashboard may be ready only after several independent renderers finish; a simpler page may be ready once a particular element appears. The most reliable contract is one the application defines explicitly: it signals readiness after all PDF-relevant work is complete, and the Node process waits for that signal before printing.

Use an application-owned readiness flag

A flag is a compact handshake between the page and the script that prints it. The page initializes it to false before starting relevant work and changes it to true only when that work is complete. The name window.__PDF_READY__ is an example, not a Puppeteer built-in event or property.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Front end: set the flag around real rendering work

Place the initial state before the code that starts loading or drawing the report. In an application with multiple asynchronous tasks, wait for all the tasks that affect the PDF rather than marking ready when only the first request finishes.

window.__PDF_READY__ = false;

async function renderReport() {
  try {
    const report = await loadReportData();
    updateReportLayout(report);

    await Promise.all([
      drawCharts(report),
      loadReportImages(report),
    ]);

    // Set true only after all PDF-relevant rendering has finished.
    window.__PDF_READY__ = true;
  } catch (error) {
    // Keep the page from claiming readiness after a failed render.
    window.__PDF_ERROR__ = String(error);
    throw error;
  }
}

renderReport();

Adapt the work list to the page. If a chart library has a completion callback or promise, wait for that completion; merely scheduling a draw is not the same as finishing it. If an image is required, account for its load or failure state. If a failed render should stop export, expose a page-side error state rather than silently setting the ready flag.

Node: wait before printing

Navigate to a useful initial milestone, wait for the application flag with a timeout chosen for your workload, then create the PDF:

await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForFunction(() => window.__PDF_READY__ === true, {
  timeout: 15_000,
});
const pdf = await page.pdf({ printBackground: true });

page.waitForFunction() waits until its page-side function returns a truthy value. The 15-second timeout is illustrative, not a Puppeteer recommendation; choose a limit based on expected rendering time and how your job runner handles slow or failed exports. A timeout should fail the job visibly instead of allowing an incomplete PDF to pass as successful.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

A complete Node script

This example assumes the report page implements the flag above and that Puppeteer is installed in the project. It writes the generated PDF to disk; replace the URL and output path for your environment.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    const url = 'https://example.com/report';

    await page.goto(url, { waitUntil: 'domcontentloaded' });
    await page.waitForFunction(
      () => window.__PDF_READY__ === true || Boolean(window.__PDF_ERROR__),
      { timeout: 15_000 },
    );

    const state = await page.evaluate(() => ({
      ready: window.__PDF_READY__ === true,
      error: window.__PDF_ERROR__ || null,
    }));
    if (!state.ready) {
      throw new Error(`Report rendering failed: ${state.error || 'unknown error'}`);
    }

    await page.pdf({
      path: 'report.pdf',
      printBackground: true,
    });
  } finally {
    await browser.close();
  }
})().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

This version waits for either success or an application error, then distinguishes the two. If the timeout expires before either state appears, Puppeteer throws and the script reports a failed job. Ensure your application catches errors from every relevant render operation and sets its error state, or the only signal may be the timeout.

Choose the right wait: milestones are not interchangeable

Use a navigation milestone to establish that the document has reached a useful starting point; add a condition that represents the actual print-ready state. The table summarizes what each approach tells you and where it falls short.

Wait strategy What it establishes Limitation Good fit
domcontentloaded or load A browser navigation milestone occurred. It does not represent arbitrary application rendering completion. Getting the initial document ready before checking app state.
Network idle Network activity met the configured idle condition. Quiet network activity does not promise that timers, local computation, canvas drawing, or state updates are done. Pages where a quiet network is a useful additional milestone.
Selector or DOM condition A chosen element or state is present. The condition is only useful if it truly corresponds to print readiness. A stable completion marker the page already exposes.
App-owned flag or event The application says its print-relevant work is complete. You must implement a correct, current-job handshake. Dynamic pages, charts, client-side data, and multi-step rendering.
Fixed delay A selected amount of time passed. It can be too short for a slow render and waste time on a fast one. Temporary diagnosis, not a reliable readiness contract.

When network idle helps—and when it does not

Puppeteer’s PDF guide demonstrates navigation with waitUntil: 'networkidle2' before printing, and network idleness can be a useful milestone when the page’s requests are relevant to its content. The separate network-idle wait is defined in terms of network activity and a minimum idle period. Neither definition says that application-specific computation or rendering is complete.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

You can combine a suitable navigation milestone with the readiness condition. Do not treat network idle as inherently wrong, or assume it proves every page is ready. Long polling, analytics, and other continuing requests can also make a network-idle strategy a poor fit for a particular page; choose based on the page’s behavior and keep the app-owned condition as the definition of print readiness.

Use an event when a flag is not the right interface

An application can signal completion through its own event or an exposed Node callback instead of a global flag. Puppeteer’s page.exposeFunction() installs a function on window that calls a Node function and resolves a promise. The application still has to implement the event wiring; exposing a callback does not automatically detect rendering completion.

Whichever interface you choose, make the handshake one-shot for the render being printed. Reset readiness for every export, and associate the signal with the current document or job. Otherwise, a late signal from an earlier render could release a later PDF request while its content is still changing.

Prevent navigation-ordering races

If clicking an export control triggers navigation, register the navigation wait before the click by starting both together. Waiting for navigation only after awaiting the click can miss the event.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
const [response] = await Promise.all([
  page.waitForNavigation(),
  page.click('#export-report'),
]);

await page.waitForFunction(() => window.__PDF_READY__ === true, {
  timeout: 15_000,
});
const pdf = await page.pdf({ printBackground: true });

Use the selector for your actual control. If the click does not cause navigation, do not add a navigation wait just for the sake of it; wait for the app’s state change instead. When it does navigate, the readiness wait remains a separate step after navigation completes.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Account for fonts and print-specific layout

page.pdf() uses print CSS media by default, so print styles can change visibility, dimensions, or layout compared with the screen view. Check the output under the media type used for the PDF, not only in a normal browser tab. If the intended output should use screen media, call await page.emulateMediaType('screen') before printing.

Puppeteer’s PDF guidance says font loading is awaited by default. The PDF option waitForFonts waits for document.fonts.ready and defaults to true; it may require bringing a background page to the foreground. Avoid adding an arbitrary font delay unless you have diagnosed a font-loading issue. For exact print colors, the Page API documents the CSS property -webkit-print-color-adjust.

@media print {
  .report {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

Also verify the PDF’s paper format, margins, orientation, and background expectations against the report’s print styles. A readiness signal means the application work is done; it does not itself guarantee that the chosen print layout matches the intended design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Troubleshoot incomplete or stalled PDFs

  1. List the content that must appear. Identify which requests, chart draws, images, client-side layout updates, and other asynchronous operations produce that content.
  2. Reset readiness for each export. Initialize the flag or event state before the relevant work starts. A stale “ready” state can make the script print immediately on a subsequent run.
  3. Signal only after all required work finishes. Await the relevant promises or renderer callbacks. Surface failures through an application error state instead of reporting success.
  4. Register navigation waits before an action that navigates. Use the concurrent Promise.all() pattern for a navigation-triggering click, then wait for app readiness after navigation.
  5. Keep a finite timeout and inspect state on failure. When a wait expires, log the URL, relevant page state, and application error signal. Increase the timeout only if normal workloads legitimately need longer; do not use a larger number to conceal a signal that never arrives.
  6. Use network idle as a milestone, not a verdict. It may help with request-driven pages, but it does not encode the application’s complete-render semantics.
  7. Check print output settings. Confirm print versus screen media, paper size, margins, backgrounds, and the page’s print CSS.
  8. Investigate font waits only when indicated. The default PDF flow waits for fonts; if a background page stalls at that stage, check the documented foreground-page consideration for waitForFonts.

A fixed sleep can help isolate whether a timing issue exists, but it is not a correctness mechanism: a slow run can outlast it, while a fast run pays the full delay unnecessarily. Prefer a condition tied to the work that actually determines the PDF state.

Or skip the browser setup

If your goal is a website screenshot rather than a Puppeteer-generated PDF, ScreenshotNeo is a one-request screenshot API and MCP server. Its API can return PNG, JPEG, WebP, or PDF; use the PDF option when you need a PDF rather than the image response shown below. The following cURL example saves a WebP screenshot:

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 API documentation for request options. ScreenshotNeo removes known cookie and consent banners, newsletter popups, and chat widgets before capture; each removal step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Free includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. This is a different workflow from implementing an application-owned Puppeteer readiness handshake: use Puppeteer when you need control over your own browser automation and page contract.

Sign up free for 1,000 screenshots a month with no card.

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.

Frequently Asked Questions

Is window.__PDF_READY__ provided by Puppeteer?

No. It is an example of an application-defined readiness flag; your page must set it and your script must wait for it.

Should I use a fixed sleep instead of waiting for readiness?

A sleep does not establish that rendering finished. Use it only as a temporary diagnostic, not as the PDF’s correctness condition.

Does Puppeteer wait for fonts before creating a PDF?

The PDF flow waits for fonts by default through waitForFonts; the option defaults to true.

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.

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