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 desk6 min

How to Archive Webpages as PDFs with Playwright

A practical guide to saving a rendered webpage as a PDF with Playwright, including readiness waits, print layout controls, troubleshooting, and archival limits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Playwright’s page.pdf() to save a rendered webpage as a PDF. Navigate to the page, wait for the content you need, then choose the print layout and PDF options. The result is a PDF rendering—not a complete preservation package of the page’s responses, assets, interactive behavior, or every dynamic state.

How do I save a webpage as a PDF with Playwright?

Install Playwright and its browser, then run a script that opens the target URL and calls page.pdf(). The method returns a PDF buffer; supplying path saves it directly to a file.

As an Amazon Associate I earn from qualifying purchases.

Install Playwright

For a new Node.js project, install the package and Chromium:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npm install playwright
npx playwright install chromium

Runnable JavaScript example

Save this as archive.js. Set the target URL in url, then run node archive.js.

#1 Best Overall
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
const { chromium } = require('playwright');

(async () => {
  const url = 'https://example.com/';
  const browser = await chromium.launch();

  try {
    const page = await browser.newPage();
    await page.goto(url, { waitUntil: 'load' });

    // Replace this with a meaningful selector or application signal
    // when the page renders important content after the load event.
    await page.pdf({
      path: 'page.pdf',
      format: 'A4',
      printBackground: true,
      preferCSSPageSize: true,
    });
  } finally {
    await browser.close();
  }
})().catch(error => {
  console.error(error);
  process.exitCode = 1;
});

The example uses the page’s CSS page size when available and includes background graphics. Change those choices to match the document you need. For the complete set of method options, see Playwright’s Page API reference; the API may change, so consult the current documentation.

Choose a readiness condition that fits the page

The navigation wait tells Playwright when to continue after requesting a page; it does not prove that every visible or dynamically loaded element is ready for capture. A client-rendered page may need an additional wait for a selector or other application-specific signal before you create the PDF.

Condition What it means When to consider it
commit Navigation has committed and the response document is being loaded. When you need to proceed as soon as navigation commits, and will handle later readiness yourself.
domcontentloaded The document’s DOMContentLoaded event has fired. When DOM parsing is enough to begin your own page-specific wait.
load The page’s load event has fired. A reasonable starting point for conventional pages, but not a guarantee that later app content or lazy content is ready.
networkidle No network connections for at least 500 ms. Only when that network condition suits the page. Playwright discourages using it for tests, and it does not guarantee that every required element is ready.

Wait for the content you actually need

If a known element marks when the main content is available, wait for it after navigation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
  • Easily store and access 1TB to content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop. Reformatting may be required for Mac
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.locator('main article').waitFor({ state: 'visible' });
await page.pdf({ path: 'page.pdf', format: 'A4' });

Replace main article with a selector that is meaningful for the target site. For an application whose content is announced through a JavaScript state or another signal, wait for that signal instead. No single navigation setting works for every site.

Set print layout, paper size, and backgrounds

page.pdf() uses print CSS media by default. A site’s print rules may hide navigation, change colors, or reflow the page. You can keep that print layout or switch to screen media before producing the PDF.

Choice Effect Use it when
Print media (default) Applies the page’s print CSS. You want the site’s intended print layout or a document-oriented reflow.
Screen media Applies screen styling instead of print styling. You want the PDF to follow screen presentation more closely.

To use screen styling, set the media before calling page.pdf():

Rank #3
UnionSine 1TB Ultra Slim Portable External Hard Drive HDD-USB 3.0
  • 【Upgraded version】 - The mirror logo strip is combined with the striped non-slip design. The rounded corners of the shell are more suitable for holding. The strips play a heat dissipation function to ensure a stable and fast transmission process.
  • 【Ultra-thin and quiet】 - The motherboard adopts JMicron 578 noise-free solution, giving you a quiet working environment. Lightweight and portable size designed to fit in your pocket for easy portability.
  • 【Ultra-Fast Data Transfers】 - Pairing this external hard drive with JMicron 578 solution USB 3.0 and USB 2.0 interfaces enables blazing-fast data transfer. It boasts theoretical read speeds of up to 125MB/s and write speeds of up to 103MB/s.
  • 【Plug and Play】 - With no software to install, just plug it in and the drive is ready to use.The hard disk chip is wrapped with an aluminum anti-interference layer to increase heat dissipation and protect data.
  • 【What You Get】 - 1 x Portable Hard Drive, 1 x USB 3.0 Cable, 1 x User Manual, Gift-type shell packaging ,Three-year manufacturer's warranty and free technical support services.
await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'page.pdf', format: 'A4' });

Playwright documents controls for paper format, explicit width and height, margins, scale, background printing, and whether CSS page size takes precedence. Length values accept px, in, cm, or mm; a value without a unit is treated as pixels.

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

Choose who controls the page size

Use format for a standard paper size such as A4, or use width and height for explicit dimensions. With preferCSSPageSize: true, a CSS @page size takes priority over those supplied paper dimensions. Its default is false; in that case, content is scaled to fit the paper size.

Decide whether to print backgrounds

printBackground controls background graphics and defaults to false. Turn it on when the design depends on background colors or images; leave it off when you want to omit them.

Rank #4
Sale
WD 2TB Elements Portable External Hard Drive for Windows, USB 3.2 Gen 1/USB 3.0 for PC & Mac, Plug and Play Ready - WDBU6Y0020BBK-WESN
  • High capacity in a small enclosure – The small, lightweight design offers up to 6TB* capacity, making WD Elements portable hard drives the ideal companion for consumers on the go.
  • Plug-and-play expandability
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • SuperSpeed USB 3.2 Gen 1 (5Gbps)

Example with explicit margins and dimensions

await page.pdf({
  path: 'page.pdf',
  width: '210mm',
  height: '297mm',
  margin: {
    top: '15mm',
    right: '12mm',
    bottom: '15mm',
    left: '12mm',
  },
  scale: 1,
  printBackground: false,
  preferCSSPageSize: false,
});

Choose either the site’s CSS page sizing or your explicit paper dimensions deliberately. If page content is clipped, compare those settings and margins rather than assuming the browser omitted content.

What does a Playwright PDF archive preserve?

It preserves a rendered PDF output of the page at capture time. The Playwright Page API describes PDF generation and its output settings; it does not promise to package original HTTP responses, save embedded resources as separate files, preserve interactive behavior, capture every dynamic state, or establish legal authenticity or long-term preservation.

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.

If you need evidentiary provenance or a preservation package, define those requirements separately and use a workflow that records the necessary provenance and resources. A PDF alone should not be represented as proof of those properties.

Best Value
Kosbees 500 GB External Hard Drives,Portable Hard Drive for Windows,Ultra Slim External HDD Store Compatible with PC, MAC,Laptop,PS4, Xbox one, Xbox 360;Plug and Play Ready
  • 【Plug-and-Play Expandability】 With no software to install, just plug it in and the drive is ready to use in Windows(For Mac,first format the drive and select the ExFat format.
  • 【Fast Data Transfers 】The external hard drives with the USB 3.0 cable to provide super fast transfer speed. The theoretical read speed is as high as 110MB/s-133MB/s, and the write speed is as high as 103MB/s.
  • 【High capacity in a small enclosure 】The small, lightweight design offers up to 500GB capacity, offering ample space for storing large files, multimedia content, and backups with ease. Weighing only 0.35 Lbs, it's easy to carry "
  • 【Wide Compatibility】Supports PS4 5/xbox one/Windows/Linux/Mac and other operating systems, ensuring seamless integration with game consoles,various laptops and desktops .
  • Important Notes for PS/Xbox Gaming Devices: You can play last-gen games (PS4 / Xbox One) directly from an external hard drive. However, to play current-gen games (PS5 / Xbox Series X|S), you must copy them to the console's internal SSD first. The external drive is great for keeping your library on hand, but it can't run the new games.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting PDF captures

  • The PDF looks like a printout, not the browser view: this is expected by default because PDF generation uses print media. Call page.emulateMedia({ media: 'screen' }) before page.pdf() if screen styling is what you need.
  • Background colors or images are missing: set printBackground: true if they should appear in the PDF; the default is false.
  • The PDF uses an unexpected paper size or content is scaled: check format, width, height, and preferCSSPageSize. When that option is false, content is scaled to fit the paper size; when true, CSS @page sizing takes priority.
  • Content is absent even though navigation completed: wait for the content’s selector or application-specific readiness signal before calling page.pdf(). A navigation event or a 500 ms network-idle interval is not universal proof that all page content is ready.
  • Page content is clipped or poorly paginated: review the site’s print CSS, paper size, margins, and scale. If the site defines an @page size, decide whether it should take priority.
  • The file is not saved where expected: supply an explicit path such as page.pdf. Without a path, page.pdf() returns a buffer for your code to handle.

Or skip the browser setup

For a screenshot or PDF through an API instead of running a browser yourself, ScreenshotNeo accepts a URL in one request. Its cleanup steps accept cookie and consent banners like a visitor and remove 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses report the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Every feature is on every plan; the free plan includes 1,000 shots a month with no card, and paid plans start at $5 for 3,000 shots.

Example cURL request, using the target URL shown:

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, including PDF output. Sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Playwright print a webpage to PDF?

Yes. Use page.pdf(); it returns a PDF buffer and can also save to a file when you provide a path.

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

Does networkidle mean a page is fully ready to archive?

No. It means there were no network connections for at least 500 ms. Use a page-specific readiness condition for important dynamic content.

Quick Recap

SaleBestseller No. 1
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$129.99
Bestseller No. 2
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.80
SaleBestseller No. 4

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

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.