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

To save a protected page as a PDF with Playwright, authenticate the browser context first, open the page, wait for the content you need, and call page.pdf(). Use httpCredentials for HTTP authentication; for a site login form, complete its normal sign-in flow or reuse a verified Playwright storage-state file. Playwright generates PDFs with print CSS by default.

Choose the authentication method the page uses

A password prompt can represent different authentication mechanisms, and the setup depends on which one protects the page.

  • HTTP authentication: The browser is challenged for a username and password. Configure the context with httpCredentials.
  • Application login: The site displays a login form and establishes a session using cookies or other browser state. Sign in through the site’s normal flow, then export the page in that authenticated context. For recurring runs, save and reuse authenticated storage state.

The protected site determines whether redirects, multi-factor authentication (MFA), CAPTCHA, or other checks are involved. Those details are not interchangeable across sites.

Export a page protected by HTTP authentication

Install Playwright and its Chromium browser for your project, then store the credentials in environment variables or a secret manager. The following ES module saves the page as page.pdf:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Yojaro 4Pack Silicone Suction Phone Case Mount, Silicon Adhesive Smartphones Stand Sticky, Hands-Free Phone Accessories Holder for Selfies and Videos (Black & White & Translucent & Light Pink)
  • 【Strong Adsorption】The inspiration of the silicone phone suction case comes from the adhesive force of the octopus. Each suction cup phone mount is 3.15 inches long and 2.17 inches wide, with 24 independent suction cups providing a stronger and more stable suction force, so you don't have to worry about your phone falling during use.
  • 【Back of Phone Suction Grip】Remove the adhesive film on the phone suction cup and stick it on the phone case. You can then fix the phone on any smooth surface, which is very convenient. (The phone suction cup cannot be removed and reused after being attached to the phone case. It is recommended to attach it to a regular phone case, not a valuable one.)
  • 【Widely Used】Our non-slip silicone phone sticky grip mount attaches to almost any flat phone case and make it compatible with common mobile phones such as iPhone and Android.You can shoot, watch videos or video calls in the kitchen, gym, dance studio, bathroom and other places.
  • 【Capture the Wonderful Picture】Whether you are a TikTok creator or just like to share videos and photos, this phone suction cup can help you hands-free capture wonderful videos and photos for sharing with friends.
  • 【Note】You can fix the phone suction cup on a smooth surface such as a mirror or glass. If necessary, wipe the suction cup with a damp cloth to obtain stronger suction. Before releasing your hand, make sure the phone is firmly fixed. (Not applicable to rough walls, wooden surfaces, and other uneven surfaces)
import { chromium } from 'playwright';

const browser = await chromium.launch();
try {
  const context = await browser.newContext({
    httpCredentials: {
      username: process.env.PAGE_USERNAME,
      password: process.env.PAGE_PASSWORD,
      origin: 'https://example.com',
    },
  });
  const page = await context.newPage();
  await page.goto('https://example.com/protected-page');
  await page.pdf({ path: 'page.pdf', format: 'A4' });
} finally {
  await browser.close();
}

Replace the example origin and URL with the site’s values. Setting origin constrains where credentials are sent; Playwright notes that browsers may cache credentials per origin after successful authentication. The browser is closed even if navigation or PDF generation fails.

Export a page that requires an application login

First authenticate using the site’s normal login flow. For a one-off export, perform that flow in the same browser context before navigating to the protected page. For repeated jobs, Playwright’s documented pattern is to establish and verify authentication, save the context’s storage state, and load it in later runs.

Rank #2
Apple EarPods Headphones with USB-C Plug, Wired Ear Buds with Built-in Remote to Control Music, Phone Calls, and Volume
  • SUPERIOR COMFORT — Unlike traditional circular ear buds, the design of EarPods is defined by the geometry of the ear. Which makes them more comfortable for more people than any other ear bud–style headphones.
  • HIGH-QUALITY AUDIO — The speakers inside EarPods have been engineered to maximize sound output and minimize sound loss, which means you get high-quality audio.
  • BUILT-IN REMOTE — EarPods with USB-C plug also include a built-in remote that lets you adjust the volume, control the playback of music and video, and answer or end calls with a pinch of the cord.
  • COMPATIBILITY — Works with all devices that have a USB-C port.
  • INTEGRATED MICROPHONE — A built-in microphone precisely captures your voice while you’re on the phone, taking a FaceTime call, or summoning Siri — so you’re always heard loud and clear.

Reuse a saved authenticated state

After generating a valid state file at playwright/.auth/user.json, create a context from it:

import { chromium } from 'playwright';

const browser = await chromium.launch();
try {
  const context = await browser.newContext({
    storageState: 'playwright/.auth/user.json',
  });
  const page = await context.newPage();
  await page.goto('https://example.com/protected-page');

  // Replace this with a locator or condition specific to the page.
  await page.getByRole('heading', { name: 'Account report' }).waitFor();
  await page.pdf({ path: 'page.pdf', format: 'A4' });
} finally {
  await browser.close();
}

The heading wait is an example readiness check, not a universal selector. Choose a page-specific condition that confirms the content intended for the PDF is present. Navigation completing does not necessarily mean that client-rendered content or images have finished loading.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
PopSockets Adhesive Phone Grip, Holder- Black
  • Secure Hold: Our PopSockets adhesive phone grip gives your cell phone a secure, comfortable hold in hand to help prevent drops while texting, taking photos, or scrolling on the go. Designed to stick firmly to most phone cases and devices.
  • Hands-Free Made Easy: Easily turn your PopSocket into a phone stand to prop up your phone anywhere, perfect for watching videos, video calls, or following recipes. A must-have phone holder that keeps your device secure and ready for anything.
  • Compatibility: Works with all phones, tablets, and Kindles. Sticks best to smooth, hard plastic cases and may not adhere to silicone or textured cases. Easily swap your PopTop to change up your style.
  • Black PopSockets: Simple, refined, and endlessly versatile. A timeless essential for any phone.
  • Travel Must-Have for People On the Go: A must-have travel accessory for flights, flying, airports, air travel, airplanes, planes, international trips, cruises, and long travel days. Key gadget for your airport haul, travel accessories and must-haves.

Playwright also documents authenticating through an API request when the application provides a suitable route. Whichever method you use, confirm that authentication succeeded before exporting—for example, by waiting for a known authenticated-page element rather than assuming that a successful navigation means the session is valid.

Protect the state file

Storage state can contain cookies and headers that allow access to the account. Keep it out of source control, do not print its contents in logs, and remove or refresh it when it expires. Treat it as a credential, not as an ordinary test fixture.

Rank #4
360° Rotating Stainless Steel Phone Tether Tab (Silvery 3-Pack) - Universal for iPhone & Other Phones (Fits Wristbands/Necklaces/Crossbody Straps)
  • [360 ° Flexible Rotation Design] Comes with a rotatable lanyard ring that supports 360 ° free rotation, effectively solving the problem of twisted and tangled lanyards
  • [Wide compatibility] The ultra-thin 0.02-inch design does not block the charging port at all, and both wired and wireless charging can be used directly without removing the pad. Compatible with most smartphones such as iPhone, compatible with various wristbands, lanyards, crossbody straps, and keychains
  • [Durable and Portable Material] Premium rust-resistant stainless steel material with good flexibility, which not only avoids scratching the phone case, but also has excellent anti rust and anti fading performance
  • [Multi scenario Practical] Paired with a lanyard or wristband, hands-free use can be achieved. The phone is within reach and not easily dropped, ideal for daily commuting and outdoor activities. Suitable for full coverage phone cases, does not support half coverage phone cases
  • [Quality Service] If you find any damage or other issues with the product upon receipt, please contact us immediately. We will handle it quickly

Control PDF appearance and readiness

Print CSS or screen CSS

page.pdf() uses print CSS media by default. If the PDF should reflect screen styles instead, set the media before exporting:

await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'page.pdf', format: 'A4' });

Choose based on the site’s print stylesheet and the output you need. A page designed for printing may intentionally omit navigation, backgrounds, or other screen-only elements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anteel 2 Pack Silicone Suction Cup Phone Case Mount Double Sided, Hands-Free Silicon Phone Grip with Higher Suction Power for Selfies and Videos, Non Slip Phone Accessories (LightPink&White)
  • 【PKYAA Double Sided Silicone Suction Phone Case Mount】PKYAA With Double Sided 40 Strong and Reliable individual suction cups, PKYAA provides a thicken and upgraded universal silicon suction mount for your phone.
  • 【Friendly to Content Creators】If you are a content creator or an online influencer, you can create videos anywhere with this suction mount completely hands free with this silicone cell phone mount for cases.
  • 【HANDS-FREE & Adhere to Mirrors】This Double Sided silicone suction phone case mount allows you to stick your phone to the mirror easily. No longer holding your phone in one hand to watch video tutorials while making up.
  • 【Strong Grip on the Smooth Surface】You can easily hang your phone anywhere with a smooth surface. All you do is you clean off your phone and smooth surface. It is STURDY and it not only sticks to mirrors, it also sticks to windows, it sticks to refrigerators, tiles and other clean, flat surfaces.
  • 【Press Down Firmly Every 30 Minutes】Use your palm or fingers to press the phone down firmly and check it's secure before letting go. Apply even pressure for a few seconds to allow the suction cup to adhere properly. To maintain the grip and prevent accidental falls, it's a good practice to periodically reapply pressure to the suction cup.

Wait for the content you need

Use a meaningful readiness condition—such as a report heading, table, or other page-specific element—before calling page.pdf(). If the site loads content asynchronously, a generic page-load event may occur before that content is ready. MFA, CAPTCHA, redirects, and expiring sessions require site-specific handling; Playwright’s general PDF and authentication APIs do not determine how a particular site behaves.

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

Troubleshoot common failures

  • The page shows a login screen in the PDF: Authentication did not take effect, expired, or redirected to a login page. Check the credential origin or rerun the application login, and verify an authenticated-only element before exporting.
  • Credentials are rejected: Confirm the username and password are supplied correctly and that the configured origin matches the protected site. Do not put real credentials in source code.
  • The PDF is missing content: Wait for a selector tied to the content you need, and check whether the page renders it asynchronously. The correct wait condition is site-specific.
  • The styling differs from the browser: The PDF uses print CSS by default. Try page.emulateMedia({ media: 'screen' }) when screen styles are the desired output.
  • A saved-state run stops being authenticated: The session may have expired or the site may require a fresh login or additional challenge. Re-establish authentication, verify it, and save fresh state.

Or skip the browser setup

If you do not need a custom Playwright workflow, ScreenshotNeo can return a PDF from one GET request. Use an authorized URL only; this does not replace a site’s login flow or grant access to protected content. ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents.

For example, request a PDF by adding the PDF output option supported by the API:

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

See the ScreenshotNeo API documentation for authentication, output formats, and parameters. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

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

Official Playwright references

Check the documentation for the Playwright release installed in your project when implementing; the cited guidance does not specify a particular release.

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.