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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To capture a Chromium screenshot of a page behind a login, first authenticate an automated Chromium browser, confirm that sign-in succeeded, then navigate to the protected page and capture the viewport, an element, or the full page. The screenshot API does not sign you in. This guide uses Playwright for the repeatable workflow; it also covers saved browser state, HTTP authentication, Puppeteer, security, and common failures. Use it only for accounts and pages you are authorized to access.

Capture a logged-in page with Playwright

The example below automates a site’s normal login form, waits for the browser to reach an authenticated page, and saves a full-page PNG. It assumes the login form has accessible labels named “Email” and “Password”; adjust those locators and the success condition to match the target application.

Install Playwright and Chromium

  1. Install Node.js, then create a project and install Playwright:

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    mkdir chromium-login-shot
    cd chromium-login-shot
    npm init -y
    npm install playwright
    npx playwright install chromium
  2. Set credentials in the environment rather than writing them into source code. For example, in a POSIX shell:

    #1 Best Overall
    HexChecks Cr(VI) Hexavalent Chromium Testing Swabs, Pack of 10
    • Easy Testing: HexChecks Instant Swabs allow for quick and convenient testing for the presence of hexavalent chromium.
    • Efficient Pack: Comes in a pack of 10 swabs, providing ample supply for multiple testing needs.
    • Reliable Results: Utilizes a proven testing method to accurately detect hexavalent chromium traces.
    • Compact Design: Swabs are conveniently packaged in a compact box for easy storage and portability.
    • Straightforward Usage: Simply swab the desired surface and observe the color change for a clear indication of test results.
    export LOGIN_USER='you@example.com'
    export LOGIN_PASSWORD='your-password'
  3. Save this as screenshot.mjs. Replace the example URLs and, if needed, the accessible labels or authenticated-page selector:

    import { chromium } from 'playwright';
    
    const loginUrl = 'https://example.com/login';
    const targetUrl = 'https://example.com/account/reports';
    const username = process.env.LOGIN_USER;
    const password = process.env.LOGIN_PASSWORD;
    
    if (!username || !password) {
      throw new Error('Set LOGIN_USER and LOGIN_PASSWORD before running this script.');
    }
    
    const browser = await chromium.launch({ headless: true });
    try {
      const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
      await page.goto(loginUrl, { waitUntil: 'domcontentloaded' });
      await page.getByLabel('Email').fill(username);
      await page.getByLabel('Password').fill(password);
      await page.getByRole('button', { name: /sign in|log in/i }).click();
    
      // Prefer an application-specific authenticated element when one is available.
      await page.getByRole('navigation', { name: /account/i }).waitFor({ state: 'visible' });
    
      await page.goto(targetUrl, { waitUntil: 'domcontentloaded' });
      await page.getByRole('heading', { name: /reports/i }).waitFor({ state: 'visible' });
      await page.screenshot({ path: 'shot.png', fullPage: true });
    } finally {
      await browser.close();
    }
  4. Run it with node screenshot.mjs. The output is shot.png in the current directory.

The two waits are intentional. Clicking the sign-in button only starts the login flow; it does not prove that authentication succeeded. A visible account navigation and a target-page heading are examples of application-specific signals. If a login redirects to a known URL reliably, Playwright can instead wait for that URL, but a visible authenticated element can better distinguish a successful login from an error page or an incomplete redirect. Identity providers may use multiple redirects while setting cookies, so wait for a stable success condition before continuing.

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

Choose the right login method

Normal web login form

Use the site’s supported sign-in flow when authentication happens in the application UI. Keep any required MFA or identity-provider steps within the site’s authorized process. If the flow requires a human challenge or another step your automation cannot complete, do not treat a failed or partial login as success; use an approved test account or supported test mechanism.

Reuse saved browser state for repeat runs

For recurring captures, Playwright can save an authenticated browser context and load it in a later run, avoiding a new form login each time while the state remains valid. Playwright recommends keeping such files under a local playwright/.auth directory and adding that directory to .gitignore.

After the login and success check in the previous script, save state before closing the browser:

await page.context().storageState({ path: 'playwright/.auth/user.json' });

Create the directory first if necessary. In a later script, initialize the context with that state:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const context = await browser.newContext({
  storageState: 'playwright/.auth/user.json',
  viewport: { width: 1440, height: 1000 }
});
const page = await context.newPage();
await page.goto('https://example.com/account/reports', { waitUntil: 'domcontentloaded' });
await page.getByRole('heading', { name: /reports/i }).waitFor({ state: 'visible' });
await page.screenshot({ path: 'shot.png', fullPage: true });

Playwright storage state can include cookies, local storage, IndexedDB, and virtual WebAuthn credentials; whether those are sufficient depends on how the application implements authentication. Its standard storage-state flow does not automatically persist sessionStorage. Only add a separate session-storage save-and-restore step if the target application actually depends on it. A saved state can expire or stop working, so verify the authenticated page on every run and regenerate the state through the supported login flow when needed. See Microsoft Playwright’s Authentication documentation and BrowserContext API.

Rank #2
HexChecks Hexavalent Chromium Test Swabs Bulk Pack (90 swabs), Cr6, Cr(VI), Colorimetric
  • DETECTION KIT: Complete hexavalent chromium testing kit includes Cr6 test swabs, neutralizer solution, and a convenient spray bottle for professional use
  • QUANTITY: Bulk pack contains 90 colorimetric swabs for extensive testing needs in industrial or laboratory settings
  • MADE IN USA: Manufactured in the United States by HexChecks, ensuring consistent quality and reliability in chemical detection
  • EASY TO USE: Simple colorimetric detection method provides quick visual indication of hexavalent chromium presence
  • COMPLETE PACKAGE: All-in-one testing solution with necessary components for immediate use in surface contamination detection

HTTP authentication

HTTP authentication is a server-level challenge, not a username-and-password form rendered by the site. For Playwright, supply credentials when creating the context:

const context = await browser.newContext({
  httpCredentials: {
    username: process.env.HTTP_USER,
    password: process.env.HTTP_PASSWORD
  }
});
const page = await context.newPage();
await page.goto('https://example.com/private/report');
await page.screenshot({ path: 'shot.png', fullPage: true });

For Puppeteer, configure credentials on the page before navigating:

await page.authenticate({
  username: process.env.HTTP_USER,
  password: process.env.HTTP_PASSWORD
});
await page.goto('https://example.com/private/report');
await page.screenshot({ path: 'shot.png', fullPage: true });

Puppeteer documents that page.authenticate() enables request interception behind the scenes, which may affect performance. These HTTP-auth examples do not replace a site’s web-form login. See the Puppeteer Page API reference.

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

Choose viewport, element, or full-page capture

  • Viewport: captures only what is visible at the current browser size. Use await page.screenshot({ path: 'viewport.png' });.

  • Element: captures a component rather than the whole page. Use a selector or locator: await page.locator('.invoice').screenshot({ path: 'invoice.png' });. Replace the selector with one that uniquely identifies the intended element.

  • Full page: captures content beyond the viewport: await page.screenshot({ path: 'full-page.png', fullPage: true });. Very long pages may produce large images, and pages that load content only as you scroll may need scrolling or an application-specific readiness condition before capture.

Playwright’s screenshot guidance also covers device-scale output, which is useful when the artifact needs higher pixel density. For reproducible visual comparisons, keep the viewport and execution environment consistent: operating system, browser version, settings, hardware, power source, and headless mode can all affect rendering. See Microsoft Playwright’s Screenshots guide and Visual comparisons documentation. Puppeteer’s documented capture method is Page.screenshot(); see its Screenshots guide.

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.

Protect credentials, browser state, and screenshots

Playwright’s guidance on authentication and state is at playwright.dev/docs/auth.

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

Troubleshoot failed or misleading captures

  • The screenshot shows the login page. The login may have failed, the redirect may still be in progress, or saved state may have expired. Wait for an authenticated UI element or known final URL before navigating to the target; if reusing state, confirm it still works and sign in again if not.

  • A locator times out. The sample labels, button name, navigation name, or heading do not match the application, or the relevant content has not appeared. Inspect the authorized page’s accessible labels and choose a stable app-specific locator rather than relying on a button click alone.

  • The target page redirects to sign-in. Authentication may not carry to the target URL, the saved context may be wrong, or the application may require state the standard storage file does not contain. Confirm that the same browser context completed sign-in; if the app relies on session storage, handle it explicitly before the app loads.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • HTTP credentials do not work. Confirm the server actually uses HTTP authentication. If it presents a web form, use the form-login flow instead.

    Rank #4
    Industrial Test Systems WaterWorks 480047 Chromium (Chromate), 1 Minute and 17 Seconds Test Time, 0.1-50mg/L Range (Bottle of 50)
    • ✔EASY TO USE: Single dip and read test strip procedure and optimized color chart make the product ideal for technical and non technical users alike for detection of Chromium (as Cr+6) in water
    • ✔COMPLETE KIT: Bottle of 25 test strips with verified color chart bottle label for easy color matching
    • ✔ACCURATE AND RELIABLE: Components are tested by Quality Control personnel at each step and are rejected if they are outside of specifications. Standards are prepared using calibrated equipment, and concentrations are confirmed by recognized reference methods
    • ✔HIGHEST QUALITY: ITS, manufactures test strip products in their USA facility in an environment that allows for reproducibility, accuracy, and traceability based on Good Manufacturing Practices
  • The screenshot is incomplete or inconsistent. The page may render content after the initial navigation event or load it on scroll. Wait for a meaningful element or application-ready condition, and keep the browser version, viewport, and headless setting stable when comparing runs.

  • Repeated runs change shared data or interfere with each other. Avoid parallel automation against one account when tests can alter server-side state; use separate test accounts where needed.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. A GET request can capture a public URL as an image or PDF. It is not a substitute for signing into a private site in your own browser; use it only where the URL is accessible to the service through supported request options and your access is authorized.

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

For a URL that can be captured this way, the one-call example is:

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 and authentication. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; those cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides screenshot and page-information tools for AI agents. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Playwright save and restore sessionStorage automatically?

No. Playwright’s standard storage-state mechanism does not automatically persist sessionStorage; capture and install it separately only if the application needs it.

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

Does a screenshot capture call log me into a protected website?

No. Authenticate the browser or provide the appropriate HTTP credentials first, then verify access before capturing.

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.