Recommended Free Tools
To save a cookie-authenticated webpage as a PDF with Playwright, add the site’s cookies to a browser context before navigating, wait for the page’s actual content to appear, then call page.pdf(). If the site’s login also depends on local storage or other browser state, restore Playwright’s saved storage state instead of injecting cookies alone.
Convert a page to PDF with explicitly supplied cookies
This JavaScript example uses Chromium and Node.js. Replace the illustrative cookie name and value with credentials you are authorized to use, and adjust the cookie scope and page URL for the target site.
As an Amazon Associate I earn from qualifying purchases.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
await context.addCookies([
{
name: 'session',
value: process.env.SESSION_COOKIE,
url: 'https://example.com',
httpOnly: true,
secure: true,
sameSite: 'Lax',
},
]);
const page = await context.newPage();
await page.goto('https://example.com/account', {
waitUntil: 'domcontentloaded',
});
// Wait for the content the PDF needs, not just the navigation event.
await page.getByRole('heading', { name: 'Account' }).waitFor();
await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true,
});
await context.close();
await browser.close();
})();
The cookie values and attributes here are examples, not universal settings. Use the values the site actually issued. Playwright accepts a cookie url, or a domain and path pair, along with expiry and security attributes. A cookie scoped to the wrong host or path may not be sent on the request.
Understand the browser context and cookie scope
A Playwright browser context isolates browser state, including its cookies. Pages created in a context share that context’s state, so add cookies to the context that will own the page and do so before navigating. Create a fresh context when you need a clean, isolated capture rather than reusing state from another task.
#1 Best Overall
- BEST FOR SMALL BUSINESSES – Engineered for extraordinary productivity, the Brother DCP-L2640DW Monochrome (Black & White) 3-in-1 combines laser printer, scanner, copier in one compact footprint and delivers high-quality black & white prints
- FAST PRINTER WITH EFFICIENT SCANNING – Produces documents quickly with print speeds up to 36 ppm(2) and scan speeds up to 23.6/7.9 ipm(3) (black/color). A 50-page auto document feeder(4) allows for convenient, time saving multi-page scanning and copying
- FLEXIBLE CONNECTION OPTIONS – Easily navigate the changing demands of your business with secure multi-device connectivity via built-in dual-band wireless (2.4GHz / 5GHz) and Ethernet. Or connect locally to a single computer via USB interface
- BROTHER MOBILE CONNECT APP – Print, scan, and manage your wireless printer anytime, from almost anywhere from your mobile device. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(5)
- CHOOSE BROTHER GENUINE TONER – When it’s time to replace your toner, be sure to choose Brother Genuine TN830 or TN830XL replacement toner. And with Refresh EZ Print Subscription Service, you’ll never worry about running out of toner again and you’ll enjoy savings of up to 50%(6) on Brother Genuine Toner. Get started with Refresh today with a Free Trial(1)
Use the cookie’s actual scope: a host-only cookie and a domain cookie are not interchangeable. The page’s scheme and the cookie’s secure setting also matter. If the site sets several cookies, supply all required cookies rather than assuming a single session cookie is sufficient.
Save and reuse an authenticated session
For a permitted login flow that you control, completing sign-in once and restoring the resulting browser state is often simpler than manually copying cookies. Playwright’s authentication guide describes saving state and loading it into a later context.
Rank #2
- BEST FOR HOMES & HOME OFFICES – Engineered for consistent, premium print quality, the Brother HL-L2405W Monochrome (Black & White) Laser Printer delivers sharp, crisp prints at an affordable price. Prints one-sided documents at speeds up to 30ppm(2)
- COMPACT, CONNECTED PRINTER – Flexible connection options make this an ideal printer for home use and at-home offices. Securely connect to multiple devices with built-in dual-band wireless (2.4GHz/5GHz) or locally to a single computer via USB interface
- BROTHER MOBILE CONNECT APP – Manage your printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
- VERSATILE PAPER HANDLING – Enjoy seamless, reliable everyday printing with the 250-sheet paper tray(4) and a manual feed slot that enables printing on envelopes and specialty pape
- BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer
// After completing a permitted login flow:
await page.context().storageState({ path: 'playwright/.auth/state.json' });
// In a later run, after launching the browser:
const context = await browser.newContext({
storageState: 'playwright/.auth/state.json',
});
const page = await context.newPage();
The state file can include cookies and local storage; the authentication guide also documents requesting IndexedDB state for applications that use it. Standard storage-state handling does not automatically persist sessionStorage. If the application relies on sessionStorage or another browser store, follow the current Playwright documentation for that store and confirm the behavior in your installed version.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteProtect saved state as a credential: it may contain cookies or headers that could let someone impersonate the account. Keep it out of source control and limit access to it.
Rank #3
- FAST PRINT SPEEDS: Print up to 19 pages per minute.
- COMPACT DESIGN: Space-saving, compact design fits anywhere in your home, school or small office.
- WIRELESS CONNECTIVITY: Print from almost anywhere in your workspace using your compatible mobile device.
- PAPER CAPACITY: Up to 150 sheets.
- SUSTAINABILITY: Uses less than 2 watts in Energy Saver mode.
Wait for the right page state before printing
page.goto() completing does not necessarily mean a modern application has loaded its data or finished rendering. Use a signal tied to the content you need, such as a heading, account name, or report container, as in the example. Choose a locator that appears only when the authenticated page is ready; otherwise the PDF may capture a loading shell or incomplete content.
Playwright’s pages guide explains navigation and load-state waiting, but the right readiness condition depends on the target page. If the page has no reliable locator, use an application-specific condition or a deliberate delay as a last resort; a fixed delay can be either too short or needlessly slow.
Rank #4
- BEST FOR HOME OFFICES & SMALL TEAMS – Engineered for consistent, premium print quality, the Brother HL-L2460DW Monochrome (Black & White) Laser Printer produces documents that are clear, crisp, and easy to review and share, all at an affordable price
- COMPACT, CONNECTED, EXCEPTIONALLY EFFICIENT– Connect with built-in dual-band wireless (2.4GHz/5GHz), Ethernet, or to a single computer via USB interface. Prints at speeds up to 36ppm(2), plus automatic duplex printing saves time and reduces paper waste
- BROTHER MOBILE CONNECT APP – Manage your wireless printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
- VERSATILE PAPER HANDLING – Tackle high-volume black & white printing with the 250-sheet capacity paper tray.(4) The manual feed slot enables printing on envelopes and specialty paper
- BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer
Choose PDF output and print styling
page.pdf() creates a PDF using print CSS media by default. With a path, it writes the file there; without one, the API returns a PDF buffer. Consult the Page API for the complete option set and verify option availability against your installed Playwright version.
- Paper and layout: Set
formatsuch as'A4', or use paper dimensions and margins. The API also supports page ranges and scale. - Backgrounds:
printBackgrounddefaults to false. Set it totruewhen background colors or images are part of the intended output. - Page-size CSS: Set
preferCSSPageSize: truewhen the page’s CSS@pagesize should take precedence over supplied paper dimensions. - Screen layout: If you want screen rather than print styling, call
await page.emulateMedia({ media: 'screen' })beforepage.pdf(). Check the result carefully because screen styling is not necessarily designed for pagination. - Printed colors: The API notes that CSS
-webkit-print-color-adjustcan affect exact printed colors.
For example, to make a screen-media PDF, place this before the PDF call:
Best Value
- FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for small teams printing professional-quality black & white documents and reports. Perfect for 1-3 people
- WORLD'S SMALLEST LASER IN ITS CLASS – Precision laser printing that fits anywhere
- FAST PRINT SPEEDS – Up to 21 black-and-white pages per minute single-sided
- WIRELESS WITH SELF-RESET – Helps you stay connected
- PRINT FROM ANY DEVICE – Wireless printing from any mobile device, PC or tablet. Works with Microsoft, Mac, AirPrint, Android, Chromebook and more
await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Common problems and fixes
- The PDF shows a sign-in page: Check that the cookie is valid and unexpired, its URL or domain/path matches the page, and its security attributes are compatible. Confirm the page is using the same context where you added the cookie. If authentication needs local storage or other state, restore a suitable storage state.
- The page is signed in manually but not in a later run: Save the authenticated context’s storage state after sign-in, load it into the later context, and keep the file secret. Check for sessionStorage dependencies, which are not covered by ordinary state persistence.
- Content is missing or still loading: Wait for a locator or condition that corresponds to the content itself. A navigation event alone may occur before client-rendered data is ready.
- The PDF looks unlike the browser: Remember that PDF generation uses print media by default. Review the site’s print CSS; select screen media if that is specifically what you want, and check paper size, margins, and
printBackground. - The output file is absent or unusable: Ensure the PDF call completes before closing the context and browser, and that the process can write to the requested path. If you omit
path, handle the returned buffer rather than expecting a file to be created.
Or skip the browser setup
If you need a screenshot rather than a PDF, ScreenshotNeo offers a one-request screenshot API. This example saves a WebP capture; see the ScreenshotNeo documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents, including Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000.
Sign up free for 1,000 screenshots a month, with no card required.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Frequently Asked Questions
Does Playwright’s PDF output include the browser’s cookies?
Cookies determine what the page can access while it is loaded; they are not a way to embed the browser session into the resulting PDF. The PDF contains the rendered page output.
Can I use this workflow for a page I do not have permission to access?
No. Use only credentials and authenticated sessions you are authorized to use, and follow the website’s access rules.
Quick Recap
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.




