Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk8 min

How to Capture Screenshots of Authenticated Pages in Different Browser Contexts

Reuse verified Playwright authentication state in separate browser contexts to capture the right signed-in page for each test user or role.

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.

To screenshot a page after login, reuse the signed-in browser context—not just the page URL. In Playwright, complete sign-in in a setup context, verify that login succeeded, save its storage state, then create a separate context from that state and capture the page. Use a different state file and context for each user or role, and handle sessionStorage separately if your app relies on it.

How authentication state and screenshots fit together

A browser context is an isolated browser session; it carries the cookies and other storage that may identify a signed-in user. A page belongs to a context, and its screenshot captures what that page rendered. Creating a new page does not itself make that page authenticated: create it inside the context initialized with the intended state. See the Playwright BrowserContext API and Page API.

As an Amazon Associate I earn from qualifying purchases.

Do not assume that copying cookies alone restores a login. Depending on the application, authentication may rely on cookies, local storage, IndexedDB, WebAuthn credentials, or session storage. Playwright’s authentication guide documents saving and reusing state and notes that session storage is not included in its standard storage-state workflow: Playwright authentication.

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

Save a reusable signed-in state with Playwright

The following JavaScript example uses Playwright’s Chromium browser. Replace the example URLs and signed-in marker with values from your application. Install Playwright in the project first, and use the same browser engine and compatible Playwright version when creating and reusing the state.

#1 Best Overall
1080P Webcam with Microphone, Privacy Cover for PC, Laptop and Desktop
  • 1080P Full HD Webcam for Streaming & Zoom Calls ✅ Experience professional-grade video with this HD webcam, delivering crystal-clear 1920x1080 resolution at a smooth 30fps. The advanced CMOS sensor makes this the perfect computer camera for streaming on Twitch or YouTube, capturing vibrant, lifelike colors for truly clear video calls and recordings
  • Superior Low-Light Performance & Auto-Correction ✅ Look your best in any environment. This PC webcam features smart light-adjustment technology that automatically balances brightness and enhances colors, making it an ideal gaming webcam or office camera. Say goodbye to grainy or dim video, even in rooms with poor lighting, ensuring you always present a clear, professional image
  • AI Noise-Canceling Webcam with Microphone ✅ Sound like a pro with studio-quality audio. This webcam with microphone features dual mics powered by AI noise reduction to effectively eliminate distracting background sounds like keyboards, fans, and chatter. Your voice remains the focus, making this web camera perfect for important conferences, clear online classes, and professional streams
  • Plug & Play Webcam with Privacy Cover ✅ Get started in seconds. This USB camera is a true plug and play webcam – no drivers needed. The convenient 5ft (1.5m) cable provides flexible placement on any laptop or desktop. Plus, the integrated sliding webcam privacy cover gives you instant peace of mind, protecting your lens and securing your privacy when the camera is not in use
  • Universal Compatibility - The Ideal Webcam for PC & Mac ✅ Works with everything you use. This versatile webcam for desktop and laptop camera seamlessly connects to Windows 7/8/10/11, Mac OS, and Linux. It’s fully compatible with all major platforms including Zoom, Microsoft Teams, Skype, Twitch, and YouTube. Whether you need a reliable webcam for Mac or a high-performance webcam for PC, this is your all-in-one solution
  1. Keep the state file out of source control. Create playwright/.auth and add that directory to .gitignore.
  2. Sign in and wait for proof of completion. Wait for a post-login URL or a UI element that only appears for a signed-in user before saving.
  3. Save the context state. If your app stores its auth token in IndexedDB, request IndexedDB inclusion where supported by your installed Playwright version.
  4. Load the state into a new context. Open the target page inside that context, verify the signed-in UI, then take the screenshot.
import { chromium } from 'playwright';
import { mkdir } from 'node:fs/promises';

const authDir = 'playwright/.auth';
const statePath = `${authDir}/user.json`;
const browser = await chromium.launch({ headless: true });

try {
  await mkdir(authDir, { recursive: true });

  // Setup context: perform the normal login flow once.
  const setupContext = await browser.newContext();
  const setupPage = await setupContext.newPage();
  await setupPage.goto('https://example.com/login');
  await setupPage.getByLabel('Email').fill(process.env.TEST_EMAIL);
  await setupPage.getByLabel('Password').fill(process.env.TEST_PASSWORD);
  await setupPage.getByRole('button', { name: 'Sign in' }).click();

  // Replace this with a URL or visible control that proves login completed.
  await setupPage.waitForURL('**/dashboard');
  await setupPage.getByRole('button', { name: 'Account menu' }).waitFor();

  // Add indexedDB: true if the application stores auth there
  // and the installed Playwright version supports this option.
  await setupContext.storageState({ path: statePath, indexedDB: true });
  await setupContext.close();

  // Capture context: this is a separate browser session initialized
  // from the saved signed-in state.
  const captureContext = await browser.newContext({ storageState: statePath });
  const page = await captureContext.newPage();
  await page.goto('https://example.com/reports');
  await page.getByRole('button', { name: 'Account menu' }).waitFor();
  await page.screenshot({ path: 'authenticated-page.png', fullPage: true });
  await captureContext.close();
} finally {
  await browser.close();
}

The example’s selectors, route, and credentials are application-specific. Supply credentials through environment variables or a secret manager rather than hard-coding them. If your installed Playwright version does not accept the indexedDB option, check its API documentation and update or omit the option according to where your app stores authentication. The BrowserContext API annotates IndexedDB export as added in v1.51, setStorageState in v1.59, and origin private file system support in v1.63; verify availability against your installed version at the API reference.

Run separate users or roles in independent contexts

Use one storage-state file and one context per independent test identity. Do not share a context when the purpose is to test role isolation: cookies or other state could otherwise mix between users. A practical setup is to authenticate each test account once, save a distinct file such as admin.json or viewer.json, and create each test’s context with the matching file.

Rank #2
Sale
Lenovo Essential FHD Webcam Gen 2, Full HD, 1080p, Dual Microphones, 85 Degree FOV, 30 fps, USB-A Connection, Bulit-in Manual Privacy Shutter, Black
  • Capture the moment: With sharp, vibrant 1080p resolution, every video call looks more natural, with better brightness, richer colors, and smoother motion. Whether you’re leading a meeting or catching up with family, they’ll see you exactly as they should.
  • Be heard, loud, and clear: No more muffled audio or repeating yourself. With dual built-in microphones, your voice comes through clear, natural, and balanced—so whether you’re speaking softly or laughing out loud, you sound just right.
  • Total privacy, in a snap: When you’re not on a call, just slide the built-in privacy shutter closed, and rest easy knowing your camera is completely off.
  • Tilt Degree: -20°~10°; Monitor Thickness: 4 mm ~ 40 mm; Maximum Resolution: 1080P; Frame Rate: 30 fps; FOV: 85°
  • Connection: USB-A 2.0; Cable Length: 1.8m Integrated Cable; Power Consumption: 5V/1A
const adminContext = await browser.newContext({
  storageState: 'playwright/.auth/admin.json'
});
const viewerContext = await browser.newContext({
  storageState: 'playwright/.auth/viewer.json'
});

const adminPage = await adminContext.newPage();
const viewerPage = await viewerContext.newPage();

await adminPage.goto('https://example.com/reports');
await viewerPage.goto('https://example.com/reports');

// Capture only after checking each role's expected signed-in UI.
await adminPage.screenshot({ path: 'admin.png' });
await viewerPage.screenshot({ path: 'viewer.png' });

await adminContext.close();
await viewerContext.close();

Pages and popups opened from a page remain associated with that page’s context. Cookies added to a context apply to pages within it. HTTP credentials can also be configured per context; however, the API cautions that browsers may cache credentials per origin after successful authentication, so changing credentials for an already authenticated origin may not have the intended effect. Review the BrowserContext API when configuring credentials or cookies directly.

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

Handle sessionStorage-based authentication

Playwright’s standard storage-state workflow does not persist sessionStorage. If the application depends on it, save only the required values after login and restore them with an initialization script before the application code runs. Restrict restoration to the exact origin: session storage is scoped by origin, and injecting tokens on unrelated sites would be unsafe.

Rank #3
HP 320 FHD Webcam - USB-A Computer Camera with Mic & Privacy Cover - for Desktop, Laptop, & Chromebook - 1080p Resolution w/Wide FOV - Zoom & Teams Compatible - Clip Mount, Tripod Support, & Swivel
  • EASY PLUG-N-GO CAMERA – Simply connect the USB-A cable to your PC, clip the external webcam to the display, and let the webcam's auto-adjust to your room’s lighting; plus, stay secure with the manual privacy cover and red LED camera-in-use indicator
  • LOOK YOUR BEST – Enjoy crisp, Full HD 1080p video resolution combined with a 66-degree wide-angle field of view for a more natural conversational feel (1).
  • OPTIMIZED FOR MODERN PLATFORMS – Instantly and easily integrate your USB-A webcam with popular video conferencing platforms, such as Zoom, Microsoft Teams, and other video chat applications.
  • CUSTOMIZE YOUR SETUP – Find the perfect angle for your next video conference with this webcam’s laptop display or desktop monitor clip mount, 360-degree swivel, and support for tripod mounting (2).
  • WORKS WITH CHROMEBOOK – This PC webcam has been optimized to work seamlessly with your Chromebook and other Chrome OS devices (3) (4).
const sessionValues = await setupPage.evaluate(() => ({
  authToken: sessionStorage.getItem('authToken')
}));

const targetOrigin = 'https://example.com';
const captureContext = await browser.newContext({ storageState: statePath });
await captureContext.addInitScript(({ origin, values }) => {
  if (location.origin !== origin) return;
  if (values.authToken) sessionStorage.setItem('authToken', values.authToken);
}, { origin: targetOrigin, values: sessionValues });

const page = await captureContext.newPage();
await page.goto(`${targetOrigin}/reports`);
await page.getByRole('button', { name: 'Account menu' }).waitFor();

Adapt the key names and origin to your application, and avoid logging or publishing the stored values. If the login flow changes, regenerate the state by signing in again rather than assuming an old snapshot remains valid.

Wait for the right page state before capturing

A screenshot can succeed technically while showing a redirect, login screen, loading placeholder, or incomplete content. After navigation, wait for a condition that demonstrates both the intended route and the relevant signed-in UI. For a dynamic report, also wait for its own loaded marker or data-specific element before calling page.screenshot(). Playwright’s screenshot API captures the page; the context provides its authentication state.

Rank #4
ELG Full HD 1080p Webcam with Microphone & Privacy Cover, Autofocus, Noise-Cancelling Mic, 360° Rotation, USB Web Camera for PC/Mac/Laptop, Zoom/Teams/Skype, USB-C Adapter Included, Black
  • FULL HD 1080P WITH AUTOFOCUS - STAY SHARP ON EVERY CALL: Stream and record in crisp Full HD 1080p on Zoom, Teams, Skype, and Google Meet. The autofocus lens keeps your face sharp as you lean in or move - no soft image like fixed-focus webcams
  • BUILT-IN NOISE-CANCELLING MIC - BE HEARD WITHOUT A HEADSET: The integrated microphone reduces background noise so your voice comes through clearly on calls, classes, and streams. No separate headset or external mic to set up
  • PRIVACY COVER INCLUDED - BLOCK THE LENS IN ONE SLIDE: A built-in cover slides over the lens to physically block the camera when you are off-call - no software toggle to trust. Peace of mind at your desk, in the office, or on any shared or work computer
  • 360 ROTATION + MULTIFUNCTIONAL BASE: The adjustable base clips onto a monitor or laptop, sits flat on a desk, or mounts on a tripod, and rotates a full 360 to frame yourself, a group, or a whiteboard. Note: tripod not included (base is tripod-ready)
  • USB PLUG & PLAY FOR PC, MAC & LAPTOP - USB-C ADAPTER INCLUDED: Connect over USB and start in seconds - no drivers, no software to install. Works with Windows, macOS, and Linux. Includes a USB-A to USB-C adapter for newer USB-C machines too
  • For a login flow, wait for a post-login URL or a signed-in control rather than relying only on the submit click completing.
  • For a target page, verify a role-specific marker if different accounts should see different content.
  • For an element-only image, use Playwright’s locator screenshot method when the target is a particular element; use the page screenshot method for the page view.
  • Use a dedicated test account and avoid capturing customer data unless access and handling are authorized.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Protect authentication files and captured images

A saved state file may contain cookies and headers that can let someone impersonate the account. Playwright explicitly warns about this risk and recommends storing auth files in playwright/.auth and adding the directory to .gitignore in its authentication guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Never commit state files, attach them to bug reports, publish them with screenshots, or paste their contents into logs.
  • Use restricted test accounts with only the permissions needed for the scenario.
  • Limit access to screenshots too; they can reveal account names, records, or other sensitive page content.
  • Regenerate state when credentials, sessions, or the sign-in flow change, and remove obsolete files securely.

A screenshot records what the browser rendered at that moment. It is not independent proof that the account was authorized or that its session remains valid; verify access through the application’s expected signed-in state and use only accounts and pages you are permitted to access.

Best Value
200074 Webcam Wireless Video Camera Screenshot Display LED Light Neon Sign
  • Neon signs for business, Game Store, Restaurant, Coffee Cafe, Tattoo, Hotel, Fashion, Beauty, Barber, Bar.
  • Decorative - Perfect for Studio, Living Room, Bed Room, Game Room, Man Cave, Garage
  • Unique Neon Sign for Birthday, Anniversary, Christmas, Grand Opening Gift.
  • Ultra-bright - Use good quality LED, durable long-life material and components.
  • Green environmental protection product

Common problems and fixes

  • The screenshot shows the login page. Login may not have completed before state was saved, state may belong to another user, or the app may rely on storage not captured. Wait for a post-login URL or marker before saving; determine whether the app uses IndexedDB or session storage; then recreate and verify the state.
  • Cookies exist but the app still treats the page as logged out. Cookie-only copying may miss local storage, IndexedDB, or another authentication mechanism. Capture the full supported storage state after a verified login instead of copying cookies alone.
  • A token in sessionStorage disappears in the new context. That is outside Playwright’s standard storage-state workflow. Restore only the necessary values with an origin-restricted initialization script before navigation.
  • The page is captured before its content appears. Navigation completion does not necessarily mean the app’s data is ready. Wait for the target content or signed-in UI explicitly before taking the screenshot.
  • Changing HTTP credentials has no effect. The browser may have cached credentials for that origin after an earlier successful authentication. Start a fresh context with the intended credentials and consult the BrowserContext API behavior.
  • The state option is rejected by Playwright. Storage-state capabilities are version-sensitive. Check the installed Playwright version and use only options supported by that version; IndexedDB export is documented as available from v1.51.
  • Another user’s screenshot has the wrong role or data. Reusing one context or state file can mix identities. Authenticate each role separately, assign distinct files, and create a distinct context for each capture.

When Selenium may fit better

If your existing QA suite uses Selenium, its official documentation covers browser windows and tabs, while its API documentation covers screenshot capture. The available sources do not establish a complete current feature comparison between Selenium and Playwright, so choose based on your browser engines, language binding, existing test stack, authentication storage model, need for isolated user contexts, and whether you need a full-page or element capture. See Selenium’s windows and tabs documentation.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server, but a URL-only screenshot request does not import the private state in your Playwright auth file. Use the browser-context workflow above when the page requires that signed-in session. For pages the API can reach without your local browser state, one GET request can return a screenshot; see the ScreenshotNeo website and API documentation.

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

ScreenshotNeo accepts cookie and consent banners and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers identifying the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month, with no card required.

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

Frequently Asked Questions

Can I reuse a Playwright authentication state file indefinitely?

No fixed lifetime is established by Playwright’s storage-state mechanism; validity depends on the application’s session and token policies. Regenerate the file when the session expires or the login flow changes.

Can a saved storage state prove that a user was authorized?

No. It recreates browser state; authorization must be validated through the application’s access rules and the account’s permitted scope.

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
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.