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 DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog › authentication

Fix Puppeteer Screenshots That Show the Login Page Instead of the Dashboard

By Freedom251 Team · · 6 min read

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.

If a Puppeteer screenshot shows a login page, first check whether the browser is actually authenticated and whether the dashboard finished rendering before capture. A resolved navigation promise does not prove login succeeded. Log the final URL and response, verify the same browser context holds the session, then wait for a dashboard-only selector before taking the screenshot.

Why the screenshot shows the login page

A screenshot records what the page looks like at capture time. Seeing a login screen usually means one of three things: the page has no valid session, the site redirected navigation to login, or the dashboard had not rendered when the screenshot was taken. Which explanation applies depends on the site’s authentication flow and your code.

As an Amazon Associate I earn from qualifying purchases.

Puppeteer’s screenshot guide demonstrates navigation with a chosen wait condition and waiting for an element before capture. In Puppeteer 25.12.0, Page.goto() resolves with the main resource response; after redirects, that is the response for the last redirect. A resolved call alone does not establish that the dashboard loaded.

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

Diagnose the failure before changing login code

  1. Record what navigation actually did. Log the requested URL, page.url() after navigation, response status, redirect chain if available, and whether a login-specific or dashboard-specific selector is present. Do not log passwords, session-cookie values, or authorization headers.
  2. Check the browser context and profile. Confirm the login step and screenshot step use the same BrowserContext and browser profile. A new context or a fresh browser process may not inherit the earlier run’s session state.
  3. Check the authentication flow. Run the site’s supported login flow, or restore valid test-session state into the active context if that is how your test is designed. A cookie being present does not guarantee the site will accept it.
  4. Inspect the final destination. After navigating to the dashboard, check the final URL and visible page. If it is the login URL, troubleshoot authentication or redirects rather than taking a screenshot.
  5. Wait for an application-specific readiness signal. Use a stable selector that appears only in the dashboard. If it times out, report the URL and whether the login or dashboard selector appeared.
  6. Capture only after the dashboard assertion passes. If request interception is enabled, also verify every intercepted request is resolved exactly once.

Use the right strategy for keeping a session

Approach When it fits Trade-offs
Reuse a persistent profile with userDataDir Repeated runs in a controlled environment where retaining a browser profile is permitted. Convenient, but profile access, expiry, and CI isolation need care. A persistent profile does not keep an expired or rejected session valid. Puppeteer’s troubleshooting guide notes that it normally creates a temporary profile and that the chosen directory must be writable: Puppeteer troubleshooting.
Restore cookies or session state into the active context Tests intentionally using a valid test session that can be handled securely. Requires explicit setup. Domain, path, expiry, and context matter, and cookies may not represent all application state. The cookie guide is under Puppeteer’s Next documentation; check API names against your installed version.
Perform the supported login flow for each run Short-lived sessions, SSO or MFA checks, or tests that need to exercise login itself. Adds steps and synchronization but tests the real authentication path. The application’s specific login behavior is not defined by Puppeteer documentation.

Choose based on session expiry, SSO/MFA behavior, secret handling, CI repeatability, and whether the test is meant to cover login. There is no universally correct strategy without knowing the site’s authentication policy.

Wait for the dashboard, not just navigation

Use a selector that is both stable and exclusive to the signed-in dashboard, such as a navigation landmark or account control that cannot appear on the login screen. Avoid relying only on networkidle or a fixed delay: background requests may keep running, while a delay can expire before a slow dashboard is ready. Puppeteer’s waitForSelector() is intended for waiting until an element appears.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();

try {
  // Use the application's authorized login flow here, if required.
  await page.goto('https://example.com/dashboard', {
    waitUntil: 'domcontentloaded',
  });

  const response = await page.goto('https://example.com/dashboard', {
    waitUntil: 'domcontentloaded',
  });

  console.log({
    requestedUrl: 'https://example.com/dashboard',
    finalUrl: page.url(),
    status: response?.status(),
  });

  // Replace these example selectors with stable selectors from your app.
  const dashboardSelector = '[data-testid="dashboard"]';
  const loginSelector = 'form[data-testid="login"]';

  try {
    await page.waitForSelector(dashboardSelector, { timeout: 15000 });
  } catch (error) {
    const loginVisible = await page.$(loginSelector);
    throw new Error(
      `Dashboard did not appear. URL: ${page.url()}; ` +
      `login form present: ${Boolean(loginVisible)}`,
    );
  }

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

In this example, remove the first navigation call: it is shown only to emphasize that duplicate navigation is unnecessary. A concise version should navigate once:

const response = await page.goto('https://example.com/dashboard', {
  waitUntil: 'domcontentloaded',
});
await page.waitForSelector('[data-testid="dashboard"]', { timeout: 15000 });
await page.screenshot({ path: 'dashboard.png', fullPage: true });

For diagnosis, capture the response status and final URL before waiting. If the site redirects to login, the dashboard selector should time out rather than silently producing a misleading screenshot.

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

Keep cookies and profiles scoped correctly

Puppeteer provides APIs to read and set browser cookies, and equivalent cookie methods are available on BrowserContext. Use the context that will perform the dashboard navigation; cookie scope and expiry still have to match the site. Never place live session cookies in source control or logs.

For a persistent profile, set Puppeteer’s userDataDir launch option to a writable directory. That preserves browser data between launches where the environment permits it, but it is not a substitute for checking that the site’s session remains accepted. In CI, use an isolated, access-controlled profile directory and decide explicitly whether it should survive between jobs.

Do not confuse HTTP authentication with a website login

Page.authenticate() supplies credentials for HTTP authentication and enables request interception behind the scenes. It is not a general way to sign in to a web application’s login page or restore a normal website session. Use the application’s authorized login mechanism or a valid session state instead.

Audit request interception when enabled

Puppeteer’s official Request Interception guide states: “Once request interception is enabled, every request will stall unless it’s continued, responded or aborted.” A handler that leaves a request unresolved—or resolves it more than once—can prevent scripts, API responses, or authentication redirects from completing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Review every interception handler and ensure each request receives exactly one outcome: continue, respond, or abort.
  • Check that rules do not block login endpoints, scripts, styles, or API calls required by the dashboard.
  • Temporarily disable interception to see whether the normal login and dashboard flow completes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common errors and fixes

  • Final URL is the login route: the site redirected the request. Re-run the supported login flow or correct the session context; do not treat navigation resolution as proof of authentication.
  • Dashboard selector times out while login selector is present: authentication did not complete, or the session was rejected. Inspect the login flow and session validity.
  • Dashboard selector times out but neither selector appears: check the final URL, app-specific loading state, and whether required requests were blocked or stalled.
  • Works locally but not in CI: the CI run may use a fresh profile, a different context, or a profile directory without the expected permissions. Make session setup explicit and isolate credentials.
  • Cookie restoration has no effect: verify domain, path, expiry, and context, and consider whether the application requires additional state or a fresh login.
  • Capture happens before client-rendered content appears: wait for the dashboard’s unique selector or another reliable app-ready signal, then capture.
  • Requests hang after enabling interception: ensure all intercepted requests are continued, answered, or aborted exactly once.

Or skip the browser setup

For a screenshot request without managing Puppeteer sessions and browser setup, ScreenshotNeo accepts a URL and returns an image or PDF. It removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. It also provides an MCP server so AI agents can take screenshots. It does not authenticate you to a private dashboard: the target page still needs to be publicly accessible or otherwise reachable without an interactive login.

Install no browser for this request; call the API with a URL and your key. See the ScreenshotNeo API documentation for options.

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo includes 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000. Sign up for free.

Frequently Asked Questions

Does Page.goto() resolving mean Puppeteer is logged in?

No. It means navigation completed with a response; inspect the final URL and assert a dashboard-specific selector.

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.

Can Page.authenticate() sign in to a normal dashboard?

No. It is for HTTP authentication, not a general application login or session-restoration mechanism.

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.

authenticationbrowser automationJavaScriptPuppeteerweb screenshots

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.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
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.