DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
browser printing

How to Add a Delay Before Browser Printing or PDF Capture

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

Put the wait immediately before printing or PDF generation. For a deliberate time buffer, call setTimeout(() => window.print(), delayMs). In Playwright or Puppeteer, await a readiness signal—navigation, a selector, fonts, or application state—then call page.pdf(). Chrome Headless offers --timeout for command-line capture. A fixed sleep is simple, but a condition-based wait is more reliable because it matches what your page actually needs.

First identify which printing path you use

“Printing” can mean three different operations. A page that calls window.print() opens the browser’s native print dialog. Playwright and Puppeteer create a PDF through their automation APIs. Chrome Headless prints from the command line. The correct place for a delay depends on that control point.

Path Wait goes before Output and important behavior
In-page JavaScript window.print() Native print dialog; the browser finishes loading a still-loading document before opening it (MDN Window.print()).
Playwright page.pdf() Generated PDF using print CSS by default; options include printBackground (Playwright Page API).
Puppeteer page.pdf() Generated PDF using print CSS by default; PDF generation waits for fonts by default (Puppeteer Page.pdf()).
Chrome Headless The capture command itself Use --timeout in milliseconds with --print-to-pdf (Chrome Headless command-line reference).

If the page is still loading when window.print() runs, the browser waits for loading before opening the dialog. That built-in behavior does not wait for every asynchronous API call, animation, chart, or client-side data update.

Add a fixed delay before native browser printing

Use a timer only when elapsed time is genuinely the requirement—for example, a short transition or a known third-party widget that needs a brief buffer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const delayMs = 1500;
setTimeout(() => window.print(), delayMs);

setTimeout() schedules a callback and returns immediately; code after it continues running. The callback can run later than requested when the main thread or operating system is busy (MDN Window.setTimeout()). The 1,500-millisecond value is an example, not a measured recommendation.

If you need to prevent duplicate clicks, keep the timer handle and disable the print control until it fires:

const button = document.querySelector('#print-button');
button.addEventListener('click', () => {
  button.disabled = true;
  const delayMs = 1500;
  setTimeout(() => {
    window.print();
    button.disabled = false;
  }, delayMs);
});

This prevents two dialogs from being queued by repeated clicks, but it still cannot prove that application data is ready. Replace the timer with a readiness condition when the page has a specific dependency.

Prefer a readiness condition over sleeping

A useful wait describes what must be true before capture. Choose the narrowest signal that corresponds to the missing content.

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

Wait for navigation

For a document whose important work happens during navigation, wait for the navigation promise to reach an appropriate load state. Puppeteer’s PDF guide demonstrates waitUntil: 'networkidle2' before calling page.pdf() (Puppeteer PDF generation guide). A quiet network is not proof that an application’s background job or client-side rendering has finished, so use it only when it matches the site’s behavior.

Rank #2
Sale
Canon PIXMA TS6520 Wireless Color Inkjet Printer, Duplex Printing, Copier/Scanner, 1.42" OLED Display, Compact, White
  • Affordable Versatility - A budget-friendly all-in-one printer perfect for both home users and hybrid workers, offering exceptional value
  • Crisp, Vibrant Prints - Experience impressive print quality for both documents and photos, thanks to its 2-cartridge hybrid ink system that delivers sharp text and vivid colors
  • Effortless Setup & Use - Get started quickly with easy setup for your smartphone or computer, so you can print, scan, and copy without delay
  • Reliable Wireless Connectivity - Enjoy stable and consistent connections with dual-band Wi-Fi (2.4GHz or 5GHz), ensuring smooth printing from anywhere in your home or office
  • Scan & Copy Handling - Utilize the device’s integrated scanner for efficient scanning and copying operations

Wait for a selector

If a report, chart, or “ready” marker appears only after data is rendered, wait for that element. A selector-based gate fails loudly when the element never appears instead of silently producing an early PDF. Set a sensible timeout and report the missing selector in your logs.

Wait for fonts and layout

When the symptom is fallback fonts or text moving between pages, await the font set:

await page.evaluate(() => document.fonts.ready);
await page.pdf({ path: 'page.pdf' });

MDN states that document.fonts.ready fulfills after used fonts finish loading and layout operations are complete (MDN Document.fonts). It does not mean that unrelated API data, images, or animations are complete.

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.

Wait for the application’s own state

The most reliable gate is often a page-owned signal such as data-render-complete='true', a resolved promise exposed by the application, or a visible “Report ready” element. This ties the capture to business state rather than an arbitrary number of milliseconds.

Playwright: delay or condition before PDF capture

A fixed wait is available, but Playwright explicitly discourages page.waitForTimeout() in production because time-based tests are inherently flaky (Playwright Page API).

Rank #3
Sale
Canon PIXMA TS4320 – Wireless Color Inkjet Printer with Print, Copy, Scan
  • Affordable Versatility - A budget-friendly all-in-one printer perfect for both home users and hybrid workers, offering exceptional value
  • Crisp, Vibrant Prints - Experience impressive print quality for both documents and photos, thanks to its 2-cartridge hybrid ink system that delivers sharp text and vivid colors
  • Effortless Setup & Use - Get started quickly with easy setup for your smartphone or computer, so you can print, scan, and copy without delay
  • Reliable Wireless Connectivity - Enjoy stable and consistent connections with dual-band Wi-Fi (2.4GHz or 5GHz), ensuring smooth printing from anywhere in your home or office
  • Scan & Copy Handling - Utilize the device’s integrated scanner for efficient scanning and copying operations

Simple fixed buffer

import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
await page.waitForTimeout(1500); // Use only when a time buffer is intentional.
await page.pdf({ path: 'page.pdf' });
await browser.close();

Condition-based capture

import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.locator('[data-report-ready="true"]').waitFor({ state: 'visible' });
await page.evaluate(() => document.fonts.ready);
await page.pdf({
  path: 'report.pdf',
  printBackground: true,
  format: 'A4'
});
await browser.close();

Use a locator that is stable and specific to the content you need. If the site continuously polls, networkidle may never be reached; in that case, wait for the ready marker and fonts instead. page.pdf() uses print CSS media by default, so a delay cannot correct a stylesheet that hides or rearranges content for print.

Puppeteer: wait for navigation, a selector, and fonts

Puppeteer’s documented pattern waits during navigation and then generates the PDF:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.waitForSelector('[data-report-ready="true"]', { visible: true });
await page.evaluate(() => document.fonts.ready);
await page.pdf({
  path: 'report.pdf',
  printBackground: true,
  format: 'A4'
});
await browser.close();

Puppeteer says PDF generation waits for fonts by default (Puppeteer Page.pdf()). The explicit font wait is still useful when you want the readiness gate to be visible in your code or when diagnosing layout movement.

When the page is designed for screens

Both Playwright and Puppeteer use print media for PDF output by default. If the PDF must match screen styling, emulate screen media before capture, then verify the result:

await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styled.pdf', printBackground: true });

Conversely, if print CSS is correct, leave the default print media in place. Puppeteer documents print-media behavior and color adjustment details in its PDF API reference (Puppeteer PDF API).

Rank #4
HP OfficeJet Pro 8125e Wireless All-in-One Color Inkjet Printer, Print, scan, Copy, ADF, Duplex Printing Best-for-Home Office, 3 Month Instant Ink Trial Included, AI-Enabled (405T6A)
  • The OfficeJet Pro 8125e is perfect for home offices printing professional-quality color documents like business documents, reports, presentations and flyers. Print speeds up to 10 ppm color, 20 ppm black
  • PERFECTLY FORMATTED PRINTS WITH HP AI – Print web pages and emails with precision—no wasted pages or awkward layouts; HP AI easily removes unwanted content, so your prints are just the way you want
  • UPGRADED FEATURES – Fast color printing, scan, copy, auto 2-sided printing, auto document feeder, and a 225-sheet input tra
  • WIRELESS PRINTING – Stay connected with our most reliable dual-band Wi-Fi, which automatically detects and resolves connection issues
  • 3 MONTHS OF INSTANT INK WITH HP+ ACTIVATION – Subscribe to Instant Ink delivery service to get ink delivered directly to your door before you run out. After 3 months, monthly fee applies unless cancelled.

Chrome Headless command-line delay

Chrome Headless accepts a timeout in milliseconds for capture operations, including --print-to-pdf:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
chrome --headless --timeout=5000 --print-to-pdf=output.pdf https://example.com

The command bounds how long Chrome waits before capture; it does not verify that a particular application condition is ready (Chrome Headless command-line reference). If the page needs a report query, a chart, or a specific font, a browser-automation script with an explicit readiness check gives you better control.

Print CSS and lifecycle events are separate from timing

Use print styles for presentation

Timing controls when capture starts. It does not decide which elements are visible, whether backgrounds are painted, or how colors and paper dimensions are handled. Keep those concerns in @media print rules and PDF options such as paper format, margins, and background printing.

Use beforeprint and afterprint for temporary presentation changes

window.addEventListener('beforeprint', () => {
  document.body.classList.add('printing');
});
window.addEventListener('afterprint', () => {
  document.body.classList.remove('printing');
});

MDN recommends preferring @media print and using these events only when script-driven changes are necessary (MDN beforeprint event). They are lifecycle hooks, not a general-purpose asynchronous wait; starting a fetch in beforeprint does not make the print dialog wait for that fetch.

Troubleshooting delayed prints and PDFs

  • The PDF is missing data. Cause: the script waited for navigation but the data arrived later. Fix: wait for the result selector or application-ready state, then fonts.
  • The delay appears shorter or longer than requested. Cause: setTimeout is scheduled asynchronously and can be delayed by a busy main thread. Fix: treat the timer as a minimum buffer, not a precise clock; move heavy work off the main thread where possible.
  • Playwright hangs at networkidle. Cause: analytics, polling, or sockets keep the network active. Fix: use domcontentloaded plus a specific locator, or wait for a finite request your application controls.
  • Text shifts or uses the wrong font. Cause: fonts were not ready when layout was measured. Fix: await document.fonts.ready; also check that the font request is reachable from the capture environment.
  • Screen-only elements disappear. Cause: PDF APIs use print media by default. Fix: inspect @media print rules; use emulateMediaType('screen') only when screen styling is the desired output.
  • Colors or backgrounds differ. Cause: print color and background settings are independent of waiting. Fix: enable the API’s background-print option where appropriate and validate the print stylesheet.
  • The native dialog opens before a script change appears. Cause: asynchronous work in beforeprint is not guaranteed to finish first. Fix: complete the work before calling window.print(), then use beforeprint only for synchronous class or layout changes.
  • Chrome captures an incomplete page despite --timeout. Cause: the timeout is only a maximum wait and does not know your app’s ready state. Fix: switch to Playwright or Puppeteer and wait for a selector or explicit readiness signal.
  • The script times out waiting for a selector. Cause: the selector is wrong, hidden, or never rendered for that account or URL. Fix: log the URL and HTML state, confirm the selector in a normal browser, and provide a controlled fallback or fail the job.

Reliability, performance, and cost decisions

  • Reliability: state-based waits fail when their condition is absent, but they avoid both premature output and unnecessary sleeping. Give every wait a timeout and capture diagnostic context on failure.
  • Performance: a fixed delay adds its full duration to every job, even when the page is ready sooner. A selector or font gate can finish as soon as the dependency is satisfied. Conversely, a condition that never resolves can cost more than a short bounded delay, so always cap it.
  • Dynamic pages: network-idle signals are useful for finite loads, not for pages with continuous telemetry or polling. Prefer a one-time application marker.
  • Output correctness: timing, print media, paper settings, margins, and background graphics are separate controls. Test them independently so a styling defect is not misdiagnosed as a timing defect.
  • Scaling: browser launches, navigation, fonts, and PDF rendering consume CPU and memory. Reuse browser processes where your isolation model permits, limit concurrency, and record the selected wait condition and elapsed time for each job.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a hosted website screenshot API and MCP server. It is the first option to try when you want clean captures without maintaining Playwright, Puppeteer, or Chrome: it accepts cookie and consent banners like a visitor, removes more than 60 known consent platforms plus newsletter popups and chat widgets, and bills only clean shots. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; each response identifies the result with X-Page-Verdict and X-Billed headers.

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

For AI workflows, its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. The service also supports full-page captures with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, clicks, selector or network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs are accepted to ease migration.

Best Value
Sale
Brother Work Smart 1360 Wireless Color Inkjet All-in-One Print, Scan, Copy
  • AFFORDABLE ALL-IN-ONE FOR HOME AND HOME OFFICE: Print, copy, and scan on one compact wireless printer designed for everyday home office printing, schoolwork, documents, and reports. Produce beautiful prints for results that stand out.
  • EASY TO USE WITH CLOUD APP CONNECTIONS: Print from and scan to popular Cloud apps(2), including Google Drive, Dropbox, Box, OneDrive, and more from the simple-to-use 1.8” color display on your printer.
  • FULL-SIZE FEATURES IN A COMPACT DESIGN: This printer includes automatic duplex (2-sided) printing, a 20-sheet single-sided Automatic Document Feeder (ADF)(3), and a 150-sheet paper tray(3). Engineered to print at fast speeds of up to 16 pages per minute (ppm) in black and up to 9 ppm in color(4).
  • MULTIPLE CONNECTION OPTIONS: Connect your way. Interface with your printer on your wireless network or via USB.
  • MOBILE PRINTING MADE EASY: Go mobile with the Brother Mobile Connect app(5) that delivers easy onscreen menu navigation for printing, copying, scanning, and device management from your mobile device. Monitor your ink usage with Page Gauge to help ensure you don’t run out(6).

One-call example

See the complete parameter reference in the ScreenshotNeo documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`ScreenshotNeo returned ${res.status}`);
const data = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', data));

Use the PDF capture tool and PDF options documented by ScreenshotNeo when your output must be a PDF rather than an image. Every feature is available on every plan: Free includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots, followed by Growth at $15 for 15,000, Pro at $39 for 60,000, Scale at $99 for 250,000, and Business at $249 for 1,000,000. Yearly billing gives two months free. Sign up free to get the 1,000-shot monthly allowance without adding a card.

FAQ

Does window.print() block JavaScript?

MDN says it blocks while the print dialog is open. Schedule any preparation before the call; do not expect code after it to run while the dialog remains open.

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

Is a five-second delay a safe universal setting?

No. A delay is only an elapsed-time guess. The correct value depends on the page and workload; a selector, navigation state, or font readiness promise is a better gate when available.

Can I fix a wrong print layout by waiting longer?

No. Waiting cannot change print CSS, media emulation, paper dimensions, margins, or background settings. Correct those independently, then capture after the required content is ready.

Frequently Asked Questions

Does window.print() block JavaScript?

MDN says it blocks while the print dialog is open. Complete preparation before calling it; code after the call does not run until the dialog closes.

Is a five-second delay a safe universal setting?

No. A delay is an elapsed-time guess. Use navigation, a ready selector, or font readiness when those signals represent the real dependency.

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

Can waiting longer fix a wrong print layout?

No. Print CSS, media mode, paper dimensions, margins, and background settings must be corrected separately from timing.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.