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

Save Playwright’s authenticated browser state after a confirmed sign-in, then load that state into a new browser context before navigating to the page you want to capture. Verify the page is signed in and ready before calling page.screenshot(). The saved state can contain more than cookies, and it must be protected like a password.

1. Sign in once and save the browser state

For Playwright Test, the recommended pattern is a setup project that performs the login, confirms authentication has finished, and saves state for test projects to reuse. Do not save immediately after clicking “Sign in”: some sites set cookies during redirects or after the authenticated interface loads.

  1. Create the auth directory and exclude it from version control. Add playwright/.auth to .gitignore.
  2. Use a setup script or Playwright Test setup project to sign in through the site’s normal flow.
  3. Wait for a site-specific confirmation, such as the final post-login URL or a selector only present when signed in.
  4. Save the context state with await page.context().storageState({ path: 'playwright/.auth/user.json' });.

For example, after completing the site’s login flow, wait for the destination and save:

await page.waitForURL('https://example.com/account');
await page.context().storageState({ path: 'playwright/.auth/user.json' });

Replace the example URL with the actual destination or use a reliable authenticated UI selector. A successful button click alone does not prove that authentication data has arrived or that the session is valid.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
HP OmniBook 3 17.3 inch Laptop PC, FHD Display, AMD Ryzen 3 30, 8 GB RAM, 512 GB SSD, AMD Radeon 610M Graphics, Windows 11 Home, Mica Silver, 17-dp0199nr
  • FULL HD IPS DISPLAY - Enjoy vibrant, crystal-clear images with 178-degree wide-viewing angles
  • AMD RYZEN 3 30 PROCESSOR - Everyday performance you can count on; Multitask, stream, game casually, and edit photos smoothly with responsive power and vibrant HDR visuals
  • ENJOY UP TO 14 HOURS AND 15 MINUTES OF BATTERY LIFE - HP Fast Charge restores battery from 0 to 50% in approximately 45 minutes
  • AMD RADEON 610M GRAPHICS - Experience smooth entertainment; Built for streaming and multitasking, enjoy realistic visuals and efficient performance for work and play
  • STORAGE AND MEMORY - 512 GB PCIe NVMe M.2 SSD offers fast speed and efficient storage; and 8 GB LPDDR5 RAM memory boosts performance with higher bandwidth

In Playwright Test, configure a setup project to run before projects that need authentication, then set those projects’ use.storageState to playwright/.auth/user.json. If parallel tests modify shared server-side data, use separate accounts per worker; otherwise, concurrent runs can interfere with one another.

2. Restore the saved state and capture the page

This standalone TypeScript/JavaScript example restores the previously saved state, opens the target page, checks a site-specific signed-in indicator, and captures the viewport:

Rank #2
HP 14" HD Chromebook Laptop for Students, Intel Quad-Core N4120(> N4020), 4GB RAM, 64GB eMMC, WiFi, Webcam, HDMI, USB-A&C, 14 Hours Battery Life, Zoom, Chrome OS, CUE Accessories
  • Intel Celeron N4120: 4 Cores & Threads, 1.1GHz Base Clock, Up to 2.6GHz Boost Clock, 4MB Cache, Intel UHD Graphics 600. The perfect combination of performance, power consumption, and value helps your device handle multitasking smoothly and reliably with four processing cores to divide up the work.
import { chromium } from 'playwright';

const browser = await chromium.launch();
const context = await browser.newContext({
  storageState: 'playwright/.auth/user.json',
});
const page = await context.newPage();

await page.goto('https://example.com/account');
// Replace this with a selector that exists only when signed in.
await page.locator('[data-testid="account-menu"]').waitFor();
await page.screenshot({ path: 'screenshot.png' });

await browser.close();

The selector is illustrative: use an element that the target site actually renders only for authenticated users, and, if necessary, wait separately for the content you intend to show. The correct readiness condition is site-specific; there is no universal wait that guarantees every page is fully rendered.

3. Choose the right kind of saved authentication state

Playwright’s storage-state file is not limited to cookies. It can include cookies and local storage, and can optionally include IndexedDB. Check how the target application stores its login state before assuming that a cookie snapshot is sufficient.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
AKCHART 15.6'' AI Laptop with Office 365 12GB RAM 256GB SSD Win 11 Laptops
  • Stunning 15.6" FHD IPS Display: Experience crisp 1920x1080 resolution on this 15.6 inch laptop with an IPS panel that delivers wide viewing angles and vivid colors. The narrow-bezel design maximizes screen real estate for comfortable viewing on this Win 11 laptop, whether you're studying or working.
  • Celeron J4105 Processor & 256GB SSD: Powered by a reliable Celeron J4105 processor paired with 12GB DDR4 memory and a fast 256GB M.2 SSD. This laptop computer supports SSD expansion up to 2TB and TF card expansion up to 1TB, so your storage grows with your needs. Delivers smooth multitasking for daily productivity.
  • AI-Powered Win 11 Laptop: Built-in AI features enhance your productivity with smart assistance for writing, summarizing, and task management. Pre-installed with Win 11 and includes Office 365 subscription. This student laptop is backed by 1-year warranty and 24/7 customer support.
  • All-Day 7000mAh Battery & 180° Hinge: The high-capacity 7000mAh battery keeps this laptop powered through long classes or meetings. The 180-degree lay-flat hinge lets you share your screen effortlessly during presentations. This durable laptop computer adapts to your dynamic workflow.
  • Versatile Connectivity Hub: Equipped with USB 3.2, Type-C, Mini HDMI, and 3.5mm audio jack to connect all your peripherals. Stay online anywhere with high-speed 5G WiFi and Bluetooth 4.2. This college laptop keeps you connected at home, in the library, or on the go.
  • Cookies and local storage: included in the ordinary storage-state workflow.
  • IndexedDB: if the application stores authentication tokens there, use the documented IndexedDB option. IndexedDB state capture was added in Playwright v1.51; confirm your installed version before relying on it.
  • Virtual WebAuthn credentials: the BrowserContext API documents a credentials option, added in Playwright v1.61. Confirm version support and whether it matches your authentication flow.
  • Session storage: it is scoped to a domain and is not persisted across page loads by Playwright’s built-in storage-state API. If the app relies on it, save it separately and restore it with an init script before the application code runs.

State files contain data that may allow someone to impersonate the account. Keep them out of repositories and shared artifacts. If the session expires, repeat the login-and-save flow. For state needed only during one test run, Playwright’s authentication guide suggests storing it in the test project’s output directory, which is cleaned before each run.

4. Select viewport, full-page, or element capture

Use the capture mode that matches what the screenshot needs to contain:

Rank #4
HP Essential Laptop 2026, Intel CPU, 128GB Storage, Office 365, Windows 11
  • Efficient Performance for Everyday Computing: Powered by Intel N150 processor with up to 3.6 GHz Intel Turbo Boost Technology, 6 MB L3 cache, 4 cores, and 4 threads, this HP laptop delivers responsive performance for web browsing, streaming, document editing, and multitasking. Paired with 4GB LPDDR5 RAM and 128GB UFS storage, it handles daily tasks smoothly. Includes 1-year Microsoft 365 Personal subscription for Word, Excel, PowerPoint, and cloud storage to maximize your productivity.
  • 14-Inch HD Micro-Edge Display:Enjoy clear visuals on the 14-inch HD (1366 x 768) anti-glare screen with 250-nit brightness and 62.5% sRGB coverage. The micro-edge bezel delivers a 79% screen-to-body ratio in a compact design. An HP True Vision 720p HD camera with noise reduction and dual-array microphones supports clear video calls, remote work, and online learning.
  • Modern Connectivity and Wireless Technology: Stay connected with Wi-Fi 6 (2x2) for faster wireless speeds and Bluetooth 5.4 for seamless pairing with accessories. Versatile port selection includes 1 USB Type-C 10Gbps with DisplayPort 1.2 for external displays, 2 USB Type-A 5Gbps ports for peripherals, 1 HDMI 1.4b port, 1 headphone/microphone combo jack, and 1 multi-format SD media card reader. Connect monitors, transfer files quickly, and expand your workspace with ease.
  • All-Day Battery Life and Portable Design: Enjoy up to 11 hours of video playback, 7.5 hours of mixed usage, or 7.5 hours of wireless streaming on a single charge, perfect for students and professionals on the go. Weighing just 3.24 lb and measuring 12.76" x 8.86" x 0.71", this lightweight laptop fits easily in backpacks and bags. The stylish willow green top cover with matte finish and natural silver keyboard deck with vertical brushing pattern offer a modern, professional look.
  • AI-Enhanced Productivity: Access Microsoft Copilot instantly with the dedicated Copilot key for faster assistance. AI Noise Reduction filters background sounds and improves voice clarity during calls. Dual speakers provide clear audio, while the full-size natural silver keyboard and HP Imagepad support comfortable typing and navigation.
Need Playwright call Result
Visible viewport await page.screenshot({ path: 'screenshot.png' }) Image of the current viewport.
Entire scrollable page await page.screenshot({ path: 'screenshot.png', fullPage: true }) Image of the full page, beyond the current viewport.
One component await page.locator('.header').screenshot({ path: 'screenshot.png' }) Image of the selected locator.

Omit path when you want the screenshot as an image buffer for further processing instead of writing it directly to a file.

5. Troubleshoot common failures

The page opens, but it is logged out

  • Cause: state was saved before the login redirect or authenticated UI completed, the session expired, or the site uses storage beyond the saved cookies and local storage.
  • Fix: repeat sign-in, wait for the final URL or a signed-in selector before saving, and check whether the application depends on IndexedDB, session storage, or another authentication mechanism.

The state file is missing or cannot be loaded

  • Cause: the save step did not run, the path differs from the path passed to storageState, or a test-run output directory was cleaned.
  • Fix: run the authentication setup first and confirm that the configured file path matches the saved path.

The screenshot is blank or shows a loading state

  • Cause: navigation completed before the relevant content was ready, or the page did not reach the expected authenticated state.
  • Fix: wait for a site-specific signed-in indicator and the actual content to appear before taking the screenshot. Avoid treating a generic navigation event as proof of application readiness.

Parallel runs log one another out or change the page data

  • Cause: workers share an account while tests mutate common server-side state.
  • Fix: assign separate accounts to parallel workers when their actions can interfere. A shared state is suitable when tests do not conflict.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

6. Capture through ScreenshotNeo instead

Or skip the browser setup

If the page is publicly reachable, ScreenshotNeo can capture it with one request. For pages requiring authentication, this endpoint example alone does not restore Playwright cookies or establish a logged-in session; use the Playwright workflow above when you need that browser state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
HP 14'' Laptop, 2027 Edition, Intel N150 CPU, 4GB DDR5 RAM, 128GB SSD, 1TB Cloud Storage, Long Battery Life, Windows 11 with Microsoft 365, Copilot AI
  • 【Powerful Performance】Equipped with an Intel N150 CPU, featuring up to 4.4 GHz, 4 cores, ensuring efficient and powerful multitasking capabilities.
  • 【Versatile Connectivity】Stay connected with multiple ports including USB 3.0 Type-C, USB 3.0 Type-A, and a headphone/mic combo jack, with Wi-Fi and Bluetooth for seamless wireless networking.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for free.

Frequently Asked Questions

Can I reuse the same Playwright auth file across test projects?

Yes. Configure each project that needs the session to load the saved storage-state path, and make the authentication setup project run first.

Does Playwright storage state automatically save session storage?

No. Playwright does not provide a built-in API to persist session storage; it must be handled separately if the application depends on it.

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.

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