Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

How to Refresh an Expired Playwright Session Before Capturing Screenshots

Refresh expired Playwright authentication state by rerunning the site’s sign-in flow, checking a post-login signal, and saving fresh state before screenshot capture.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a Playwright screenshot run uses expired authentication state, rerun the site’s normal sign-in flow, wait for a reliable post-login signal, and save fresh browser state before capturing. The exact login steps and session lifetime depend on the website; editing a cookie or refreshing a token is not a universal fix.

Why an expired session breaks a screenshot

A saved Playwright state file can stop representing a signed-in browser when the application expires its cookies or other authentication data. A screenshot may then show a login page, an access-denied screen, or incomplete content instead of the authenticated page. Detect expiry using an application-specific signal, such as a redirect to the login page, a failed state validation, or the absence of a control that appears only when signed in. Microsoft’s Power Platform sample validates saved state before a run and prompts for reauthentication when it is expired: Microsoft’s Playwright sample.

As an Amazon Associate I earn from qualifying purchases.

Regenerate Playwright authentication state

  1. Run authentication setup. Sign in with the authorized test account using the application’s normal flow. Playwright documents using a setup project to authenticate before tests and then having test projects load the resulting state. See Playwright authentication.
  2. Wait for proof of sign-in. Wait for the final URL or a visible authenticated UI element, rather than assuming that submitting the login form means authentication succeeded.
  3. Save the fresh state. Write the state only after the post-login check succeeds. If the saved state expires, rerun setup and replace it.
  4. Use the refreshed state for capture. Load the new state in the page or test project, navigate to the target page, and confirm the expected authenticated content is present before taking the screenshot.

A minimal setup-project pattern, adapted to your site’s login form and post-login signal, looks like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { test as setup, expect } from '@playwright/test';

const statePath = 'playwright/.auth/user.json';

setup('authenticate', async ({ page }) => {
  await page.goto('https://example.com/login');
  await page.getByLabel('Email').fill(process.env.TEST_USER!);
  await page.getByLabel('Password').fill(process.env.TEST_PASSWORD!);
  await page.getByRole('button', { name: 'Sign in' }).click();

  // Replace this with a URL or UI signal specific to your application.
  await expect(page.getByRole('navigation', { name: 'Account' })).toBeVisible();
  await page.context().storageState({ path: statePath });
});

Configure a Playwright setup project to run this setup before the screenshot tests, and configure those tests to use playwright/.auth/user.json as their storage state. The locator names, login route, and authenticated signal above are illustrative and must match the site you automate.

#1 Best Overall
Dell Optiplex 3060 Desktop Computer | Intel i5-8500 (3.2) | 32GB DDR4 RAM | 1TB SSD Solid State | Built in WiFi | Bluetooth | Windows 11 Professional | Home or Office PC (Renewed)
  • [INTEL POWERED CONTENT] - Built with a 8th Generation Hexa-Core Intel i5 and 32GB of DDR4 RAM; Modern, Windows 11 ready, with 4K support, Executive multitasking, media streaming and smooth, multi-tab web browsing; Perfect as an all-purpose multimedia computer; built for content creators; Plenty of RAM and Mass storage for photo and video editing powered by Intel HD 630
  • [LATEST WIRELESS TECH] - This Dell Desktop Computer easily connects to the internet through the Built In WiFi / Bluetooth
  • [SOLID STATE STORAGE] - This Dell Computer setup comes with an ultra-fast 1TB Solid State Drive (SSD); Setup as the primary boot device; Boot and load programs with lightning speed ; Additional expansion available
  • [BUY & OWN WITH CONFIDENCE] - From the world's largest Microsoft Authorized Refurbisher; Quality Guarantee and Free Tech Support; Award-winning Customer Service; | Support Sustainable Business
  • [MODERN HI-SPEED PORTS] - USB 3.0 (x4) | USB 2.0 (x4) | DisplayPort (x1) | HDMI Port (x1) | Audio Combo Jack (x1) | Audio Out (x1) | RJ-45 Ethernet (x1) | Internal SATA (x3)

Handle the storage type your site uses

Playwright’s standard storage state can persist cookies, local storage, IndexedDB, and passkey (WebAuthn)-based authentication. It does not automatically persist session storage. If the application’s sign-in depends on session storage, use the separate save-and-restore approach with addInitScript described in Playwright’s session-storage guidance. Session storage is domain-specific, so restoration must run for the relevant origin. Do not assume that every site stores authentication in the same place.

Capture only after the signed-in page is ready

After loading the refreshed state, verify both authentication and the content you intend to capture. For visual assertions using Playwright Test’s toHaveScreenshot, Playwright waits for two consecutive screenshots to match before comparing the final image; this helps stabilize visual tests but does not guarantee that every independent screenshot workflow has finished loading all site content. See Playwright visual comparisons.

Rank #2
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
  • Model: Dell OptiPlex 7050 Small Form Factor (SFF)
  • Processor: Intel Core i7-7700 3.60 GHz
  • Memory: 32GB DDR4 Ram
  • Storage: 1TB Solid State Drive (SSD) Fast Boot + Storage
  • Operating System: Windows 11 Pro (64-bit)

For other screenshot workflows, wait for a meaningful page-specific condition—such as a key heading, loaded data, or a selector—before capture. A fixed delay alone can be too short on a slow run and unnecessarily long on a fast one.

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

Protect the refreshed state file

Authentication state can contain cookies and headers that let another person impersonate the test account. Playwright warns: “We strongly discourage checking them into private or public repositories.” Keep the authentication directory out of source control, restrict access to generated files, and use dedicated, least-privilege test accounts. Microsoft’s sample gives additional credential-handling recommendations for its Power Platform context, including secret handling; its specific certificate and Azure Key Vault setup is not a universal Playwright requirement. See Microsoft’s sample guidance.

Rank #3
Sale
HP All-in-OneDesktop Computer, 16GB DDR5 RAM, Intel Quad-Cores, 128GB SSD, WiFi6, Keyboard & Mouse, Windows 11
  • IMMERSIVE 24 INCH DISPLAY: Experience stunning clarity on a Full HD IPS screen with ultra-thin bezels, offering a 90% screen-to-body ratio that makes everything from spreadsheets to streaming come alive with vibrant colors and crisp details.
  • POWERFUL INTEL PROCESSING: Tackle demanding tasks with ease thanks to the Intel processor and 16GB of high-speed memory, delivering smooth performance whether you're multitasking between applications or running productivity software.
  • GENEROUS STORAGE: Store all your important files, photos, and programs with blazing-fast solid state drive technology that ensures quick boot times, rapid file access, and plenty of space for your digital life.
  • ENHANCED PRIVACY AND COLLABORATION: Work confidently with the pop-up privacy camera that tucks away when not in use, plus dual microphones with noise reduction for crystal-clear video calls that keep you connected professionally.
  • ECO-CONSCIOUS DESIGN: Feel good about your purchase with an EPEAT Gold registered and ENERGY STAR certified computer that combines premium performance with responsible environmental manufacturing practices.

Troubleshoot failed refreshes and screenshots

  • The screenshot shows the login page: Check whether the setup test completed and whether it saved state after the authenticated signal. Confirm the screenshot project loads the path you just refreshed.
  • The login submit finishes but state is still unauthenticated: Replace a generic navigation wait with a site-specific signed-in locator or final URL. Some applications complete sign-in asynchronously or display an intermediate consent or multi-factor step.
  • The browser appears signed in during setup, but not in the capture project: Check the storage-state path and origin. If authentication depends on session storage, implement its explicit restoration; standard storage-state handling does not include it.
  • State works once and then expires: The application controls token and cookie lifetimes. Rerun authentication setup when validation indicates expiry; do not rely on a fixed cookie edit or a universal refresh-token recipe.
  • Content is missing despite successful authentication: Wait for the relevant content or data selector, not only the login signal. Authentication and page readiness are separate conditions.
  • Parallel runs interfere with one another: Consider separate accounts or isolated state for workers when tests change server-side state. The appropriate arrangement depends on the application and the tests.

Or skip the browser setup

For a screenshot API alternative, ScreenshotNeo returns a screenshot or PDF from one GET request. Its capture flow accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also has an MCP server for AI agents, with tools for screenshots, page information, and PDFs.

Example cURL request (replace the target URL and provide your API key):

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 documentation for request options. Free includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo and get 1,000 free screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
  • This Certified Refurbished product is tested and certified to look and work like new. The refurbishing process includes functionality testing, basic cleaning, inspection, and repackaging. The product ships with all relevant accessories, a minimum 90-day warranty, and may arrive in a generic box. Only select sellers who maintain a high-performance bar may offer Certified Refurbished products on Amazon.com.
  • Dell Optiplex 3050 SFF Desktop computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD
  • Includes: USB Keyboard & Mouse, USB WiFi adapter, Microsoft office 30 days free trail.
  • Port: Front: USB 3.0(2), USB 2.0(2); Rear: DP, HDMI, USB 3.0(2), USB 2.0(2), RJ-45.
  • Support 4K (3840x2160) Dual display, makes it easy to connect two monitors at the same time, and you can expand working Windows, mirror content, or expand a single window across multiple monitors.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does rerunning Playwright setup refresh a website’s server-side session too?

It performs the site’s normal sign-in flow and saves the resulting browser state; what the site renews or issues during login is application-specific.

Can I reuse one authentication state file for every parallel worker?

That depends on whether the application permits concurrent sessions and whether tests alter shared server-side state. Isolated accounts or state may be safer for such runs.

Quick Recap

Bestseller No. 2
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
Model: Dell OptiPlex 7050 Small Form Factor (SFF); Processor: Intel Core i7-7700 3.60 GHz; Memory: 32GB DDR4 Ram
$394.99
Bestseller No. 4
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
Includes: USB Keyboard & Mouse, USB WiFi adapter, Microsoft office 30 days free trail.; Port: Front: USB 3.0(2), USB 2.0(2); Rear: DP, HDMI, USB 3.0(2), USB 2.0(2), RJ-45.
$179.98
Bestseller No. 5
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
Connectivity: Includes WiFi, Bluetooth, and LAN for wireless and wired connections; Memory: Features 16GB DDR4 RAM for smooth multitasking and performance
$255.00
Best Value
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
  • Connectivity: Includes WiFi, Bluetooth, and LAN for wireless and wired connections
  • Memory: Features 16GB DDR4 RAM for smooth multitasking and performance
  • Storage: Combines 500GB SSD and 1TB HDD for ample storage space
  • Graphics: Integrated Intel UHD Graphics 630 for crisp visuals and video playback
  • Design: Sleek desktop tower with black color and slim profile for modern look

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
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.