October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Make a PDF from a Webpage That Requires JavaScript

Wait for the page’s JavaScript-generated content to appear, then print it to PDF. For automation, use Chrome Headless or Playwright with a page-specific readiness check and verify the output.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To save a webpage that depends on JavaScript, let it render in a JavaScript-capable browser first, then print the rendered page to PDF. For a repeatable capture, use Chrome Headless or browser automation such as Playwright, and wait for the specific content you need—not just for navigation or network activity to stop.

Save a rendered page once from your browser

  1. Open the page in a JavaScript-capable browser and wait until the content you need is visible.
  2. Use the browser’s print command and select its PDF destination. Menu names vary by browser and version.
  3. Save the file, open it, and check that the needed text, images, colors, and page breaks are present.

A browser print workflow captures the page after scripts have run. If the page loads content asynchronously, do not print until that content appears. The Chrome Headless documentation confirms command-line PDF output, but does not specify interactive print-dialog steps: Chrome Headless command-line reference.

Automate PDF creation with Chrome Headless

Chrome Headless can print a URL directly to a PDF file:

chrome --headless --print-to-pdf=output.pdf https://example.com/

Use the Chrome binary name installed on your system; it may differ by operating system or installation. The Chrome documentation also describes --timeout, which bounds the wait before capture. Capture proceeds when that time expires even if the page is still loading, so a timeout is not proof that JavaScript-generated content is ready. For timer-driven updates, --virtual-time-budget can fast-forward virtual time, but it does not guarantee that all site-specific requests and rendering have completed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images

To omit the default PDF header and footer, Chrome documents --no-pdf-header-footer; older versions may require --print-to-pdf-no-header. Check the flag against your installed Chrome version. The reference was last updated October 21, 2024: Chrome Headless command-line reference.

Use Playwright when you need page-specific readiness and layout controls

Playwright’s page.pdf() uses print CSS by default, which can produce a different layout from the on-screen page. If you want screen styling instead, emulate screen media before generating the PDF. This Node.js example waits for a selector that represents the content you need; replace the URL and selector with ones for your page.

Rank #2
Plustek Mobile Scanner S410 Plus - Compact Portable Document Sheet-Fed
  • Digitize on the Go - Connect to your computer via BUS powered, eliminating the need for batteries or external power sources
  • Button Free Scanning Experience - The S410 Plus is an automatic scanning device, no need to push any buttons or click any screens, and automatically processes images and saves them to the designated folders
  • Versatile Paper Handling - Easily scan documents ranging from Letter and Legal sizes to business cards, plastic ID cards, invoices and receipts
  • Ultra compact & Lightweight - Weighing less than 1 lb, lighter than a bottle of mineral water, and its slim design is perfect for portability
  • Work smarter with Plustek Docaction - Built-in OCR allows you convert the files into editable, such as searchable PDF, excel or word. Seamless save to your local computer, FTP and even shared folder
import { chromium } from 'playwright';

const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();

try {
  await page.goto('https://example.com/', { waitUntil: 'domcontentloaded' });
  await page.locator('.article-content').waitFor({ state: 'visible' });
  await page.emulateMedia({ media: 'screen' });
  await page.pdf({
    path: 'output.pdf',
    format: 'A4',
    printBackground: true,
    margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' }
  });
} finally {
  await browser.close();
}

Install Playwright and its browser according to the official Playwright installation guide. Choose a selector tied to the actual content: for example, a results panel, article body, or a page-specific status that changes when rendering is complete. If the target page exposes a reliable application state or text, wait for that instead. Playwright advises against treating networkidle as a general readiness test; a quiet network does not establish that the content you need has appeared. See the PDF API and navigation API.

Choose PDF settings deliberately

  • Print or screen media: Keep the default print media for a print-oriented layout. Use page.emulateMedia({ media: 'screen' }) if the screen design better preserves the content.
  • Backgrounds and color: printBackground defaults to false; enable it when backgrounds matter. Browsers may adjust colors for printing. The Playwright docs identify -webkit-print-color-adjust for pages that need exact print colors.
  • Paper and fit: The API supports paper format or explicit width and height, margins, scale, and preferCSSPageSize. The documented scale range is 0.1 to 2, with a default of 1. Inspect the output for clipped or unexpectedly scaled content.

Puppeteer alternative

Puppeteer’s official PDF guide shows navigation with waitUntil: 'networkidle2' followed by page.pdf(), and says PDF generation waits for fonts by default. Treat that as an example, not a universal readiness guarantee: a page may render needed content after network activity quiets. Prefer waiting for a page-specific signal when available, then inspect the saved file. See Puppeteer PDF generation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
PDF Scanner
  • Scan your important papers & documents.
  • Use magic color to improve scan quality.
  • Scan documents quickly and effortlessly with auto-cropping.
  • Enhance your PDF with brightness and contrast settings.
  • Converts your doc scans to bright & clear PDFs.

Check the PDF before relying on it

  • Search or inspect the file for the exact text or element that was missing in a basic capture.
  • Check images and other late-loaded content, as well as page breaks and clipped edges.
  • Compare colors and backgrounds with the intended view; print CSS and print color handling can change appearance.
  • If content is missing, adjust the readiness condition before increasing a fixed delay. A longer wait can help in some cases but is not a guarantee for every page.

Troubleshooting common failures

The PDF is blank or missing JavaScript content

The page may have been printed before its scripts populated the content. Wait for a specific visible selector, text, or application state, then capture again. A generic navigation event or timeout alone may occur too early.

Content appears in the browser but not in the PDF

Print CSS may hide or rearrange elements. Try Playwright screen-media emulation, or inspect the page’s print styling. Also verify the element is present in the document at capture time.

Rank #4
PDF Director 2 PRO with OCR - for 3 PCs - Comprehensive PDF Editor Software compatible with Win 11, 10, 8 and 7 – Edit, Create, Scan and Convert PDFs – 100% Compatible with Adobe Acrobat
  • PDF editor for all cases - fully edit, merge, create, compare, reduce PDFs, edit page structure
  • incl. NEW OCR module: for text and image recognition in scanned documents
  • Merge several PDF documents into one document
  • Edit text and images directly in the document
  • NEW in version 2: 4K and 8K resolution

Colors or backgrounds are absent

Enable Playwright’s printBackground option. Print color adjustment can still affect colors; the page may need -webkit-print-color-adjust for exact colors.

Text or images are clipped or split badly

Review paper size, margins, scale, and CSS page sizing. Adjust the format or margins, then reopen the generated PDF to check pagination rather than assuming the settings produced a fit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
  • Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.
  • EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
  • READ and Comment on PDFs – Intuitive reading modes & document commenting and mark up tools!
  • CREATE, COMBINE, SCAN and COMPRESS PDFs.
  • FILL forms & Digitally Sign PDFs. Work with Digital certificates

Chrome captures too early

Chrome’s --timeout sets a bounded wait, but capture still happens when it expires even if loading continues. Use a page-specific readiness signal through browser automation when the page’s content timing cannot be reliably covered by a fixed timeout.

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 can return a webpage capture as a PDF with one GET request. Its clean-shot steps accept cookie or consent banners like a visitor and remove 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also offers an MCP server with screenshot and PDF tools for AI agents.

Example using cURL (replace the target URL as needed):

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

See the ScreenshotNeo API documentation for request options, including PDF output settings. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo.

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

Frequently Asked Questions

Does Chrome Headless wait until every JavaScript request is finished before printing?

No. Its timeout bounds the wait and capture proceeds when that limit is reached, even if the page is still loading. Use a page-specific readiness condition when completeness matters.

Why does my Playwright PDF look different from the page on screen?

Playwright uses print CSS for PDFs by default. Emulate screen media before calling page.pdf() when you need the screen layout.

Quick Recap

Bestseller No. 1
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00
Bestseller No. 3
PDF Scanner
PDF Scanner
Scan your important papers & documents.; Use magic color to improve scan quality.; Scan documents quickly and effortlessly with auto-cropping.
Bestseller No. 4
PDF Director 2 PRO with OCR - for 3 PCs - Comprehensive PDF Editor Software compatible with Win 11, 10, 8 and 7 – Edit, Create, Scan and Convert PDFs – 100% Compatible with Adobe Acrobat
PDF Director 2 PRO with OCR - for 3 PCs - Comprehensive PDF Editor Software compatible with Win 11, 10, 8 and 7 – Edit, Create, Scan and Convert PDFs – 100% Compatible with Adobe Acrobat
incl. NEW OCR module: for text and image recognition in scanned documents; Merge several PDF documents into one document
$49.99
Bestseller No. 5
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.; EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
$99.99

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
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.