October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober 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 Screenshot a Logged-In Web App with a Rotating Session Cookie

Keep login, navigation, and capture in one Playwright context so the browser can manage rotating cookies. Learn how to reuse state safely and troubleshoot expired sessions.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use one Playwright BrowserContext for login, navigation, and capture. Let the browser manage the app’s rotating session cookie; do not keep replaying a copied cookie value. For later runs, save and reload the context’s storage state, verify that the session is still accepted, then take the screenshot.

Why one browser context handles cookie rotation

A browser context owns its cookies and other browser state. When the app responds with a replacement session cookie, the browser processes it and uses the updated value on subsequent requests in that context. Keeping login, page navigation, and capture in the same context avoids manually copying a potentially stale cookie into each request.

As an Amazon Associate I earn from qualifying purchases.

Playwright also documents that API requests associated with a BrowserContext share its cookie storage and that response Set-Cookie headers update the context’s browser cookies. The app controls its own expiry and rotation policy, so a previously saved state file is only a snapshot—not a promise of a permanently valid login. See the BrowserContext API and API testing guide.

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

Log in, verify, and capture in one run

The following Node.js example uses the normal login form, waits for an authenticated-page marker, saves state for reuse, and captures the page. Replace the example URL, selectors, and credentials with values appropriate to your application. Install Playwright with npm install playwright and install its browser with npx playwright install chromium.

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({ headless: true });
  const context = await browser.newContext();
  const page = await context.newPage();

  try {
    await page.goto('https://app.example.com/login', {
      waitUntil: 'domcontentloaded',
    });

    await page.getByLabel('Email').fill(process.env.APP_EMAIL);
    await page.getByLabel('Password').fill(process.env.APP_PASSWORD);
    await page.getByRole('button', { name: 'Sign in' }).click();

    // Wait for evidence of a completed, authenticated login.
    await page.waitForURL('**/dashboard');
    await page.getByRole('button', { name: 'Account' }).waitFor();

    // Store cookies and supported browser storage for a later run.
    await context.storageState({ path: 'playwright/.auth/user.json' });

    // Navigate in the same context; any Set-Cookie rotation is handled by the browser.
    await page.goto('https://app.example.com/dashboard', {
      waitUntil: 'domcontentloaded',
    });
    await page.getByRole('button', { name: 'Account' }).waitFor();

    await page.screenshot({ path: 'dashboard.png', fullPage: true });
  } finally {
    await browser.close();
  }
})();

Use a final URL, visible account control, or another reliable signed-in marker as the success condition. A click completing is not proof that authentication completed: redirects may set cookies over several steps. Playwright’s authentication guide covers UI login and API-assisted authentication. Keep credentials in environment variables or a secret manager rather than committing them with the script.

Reuse saved authentication state on later runs

For repeated captures, authenticate once and initialize a new context from the saved state. Verify the signed-in UI after opening the target route. If the marker is missing or the app redirects to login, the snapshot has expired, been revoked, or does not include all state the app requires; perform the authorized login flow again and save a fresh snapshot.

const { chromium } = require('playwright');

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

  try {
    await page.goto('https://app.example.com/dashboard', {
      waitUntil: 'domcontentloaded',
    });
    await page.getByRole('button', { name: 'Account' }).waitFor();
    await page.screenshot({ path: 'dashboard.png' });
  } finally {
    await browser.close();
  }
})();

Playwright’s standard storage state includes cookies and local storage. Some applications also depend on IndexedDB or session storage; check the authentication guide for the relevant save/restore approach. Session storage is not generally included in the usual storage-state file, so restoring cookies alone may not restore such an app’s session. State can also be browser- or application-specific.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

Choose UI login or an authentication API

Approach When it fits Trade-off
Log in through the UI You need to reproduce the user journey, or the app establishes required state through its pages and redirects. More steps to automate; wait for the final authenticated condition rather than assuming the sign-in click is enough.
Use an authentication API The app provides a supported API that can authenticate a test account. It can be quicker, but confirm it establishes all browser state required by the page. Use requests associated with the same context when relying on its shared cookie store.

Playwright documents both UI-based and API-assisted setup in its authentication guide. Do not manufacture or hard-code a rotated cookie as a substitute for the app’s supported login flow.

Choose viewport or full-page capture

  • Viewport: the default screenshot is the currently visible browser area. Use it when the evidence concerns the screen as a user currently sees it.
  • Full page: set fullPage: true to capture the entire scrollable page. The resulting image can be much taller and may expose more account data.

Playwright’s Page API documents screenshot options, including locator masking. Mask sensitive regions when appropriate, and protect the resulting image according to the information it contains.

Protect authentication state and screenshots

  • Keep the authentication directory out of source control. Playwright warns: “The browser state file may contain sensitive cookies and headers that could be used to impersonate you or your test account.”
  • Limit access to saved state files and use a dedicated, minimally privileged test account.
  • Do not assume saved state stays valid: expiry, revocation, and rotation behavior are controlled by the application.
  • Cookie domain and path matter. Prefer letting the app establish cookies through login; when a test genuinely needs to add a cookie manually, follow Playwright’s requirements for a URL or both domain and path.
  • Mask private content and securely store screenshots if the signed-in page displays sensitive information.

Troubleshooting

The page redirects to login after loading saved state

The snapshot may have expired or been revoked, or the app may require state not captured in the file. Repeat the authorized login flow, wait for the signed-in marker, save a fresh state, and check whether the app relies on session storage or other browser-specific state.

Rank #3
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

The script captures the login page instead of the app

Do not treat the button click as the completion signal. Wait for the expected post-login URL or an authenticated control, then check again after navigating to the capture route.

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.

A cookie appears to rotate but requests stop authenticating

Keep requests in the same context and avoid manually replaying an old cookie value. Context-associated API requests share cookie storage and process response Set-Cookie updates. If the app rejects the session, log in again rather than inventing a replacement cookie.

Login works in the browser but not from the saved state

The app may depend on session storage, IndexedDB, or state established by a particular flow. Consult the Playwright authentication guide’s state handling details and add the app’s required supported state handling; do not assume a cookie-only snapshot is complete.

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

The screenshot contains private data or misses content

Use Playwright’s screenshot masking support for sensitive regions. If content below the visible screen is required, enable fullPage: true; otherwise the default is a viewport capture. Review the image before sharing it.

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

Or skip the browser setup

If you need a screenshot API rather than managing a logged-in Playwright session, ScreenshotNeo takes a screenshot from one GET request. It removes cookie banners, popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed; and its MCP server lets AI agents take screenshots. It is not a way to authenticate into a private app: use an authorized browser session for pages that require login.

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

Example request for a publicly accessible page; see the ScreenshotNeo API documentation for parameters:

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

The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does saving Playwright storage state preserve a rotating session cookie?

It saves a snapshot of browser state, including cookies and local storage; it does not guarantee that the app will continue accepting that snapshot after expiry, revocation, or rotation.

Can ScreenshotNeo take a screenshot of a page that requires my login?

The one-call example is for a publicly accessible page. For a page protected by your app’s login, use the authorized Playwright context flow described above.

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

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