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

Wait for the application to reach a verified post-login state, then capture the page. In Playwright, that usually means waiting for the final application URL and, preferably, confirming that a meaningful authenticated control is visible before taking the screenshot.

Wait for SAML login to finish before capturing

A SAML sign-in can move through the identity provider and several redirects before the application finishes establishing its session. A successful redirect alone may not mean the application has rendered its logged-in UI, so use a URL check and, when possible, an authenticated-state check.

await page.waitForURL('https://app.example.com/');
await expect(page.getByRole('button', { name: 'Account' })).toBeVisible();
await page.screenshot({ path: 'logged-in.png', fullPage: true });

Replace the example URL and button locator with values that match your application. The URL should be the stable post-login destination; the UI locator should identify an element that appears only when the user is authenticated. Playwright’s authentication guide demonstrates waiting for the final URL or checking an authenticated UI element before proceeding: https://playwright.dev/docs/auth.

Choose a completion signal that matches your app

  • Final URL: Use page.waitForURL() when the destination after successful SAML sign-in is deterministic. If your app can land on multiple valid routes, match the appropriate route pattern instead of assuming one fixed URL.
  • Authenticated UI: Use an assertion such as expect(locator).toBeVisible() for an account menu, sign-out control, or other element that signifies an authenticated session in your application.
  • Both checks: Combining the expected destination with a positive UI check guards against capturing an intermediate redirect or a destination page that has not finished setting up its session.

Do not use an arbitrary fixed sleep as the only completion test. A delay does not establish that the redirect succeeded or that the authenticated interface appeared.

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

Capture the page and choose what to include

Once the authenticated-state condition succeeds, use Playwright’s Page screenshot API. The example sets fullPage: true to include content beyond the viewport. Omit that option for a viewport-only image. The API also supports masking selected locator regions; consult the Page screenshot API for the current options.

For example, to cover a sensitive region in a screenshot:

await page.screenshot({
  path: 'logged-in.png',
  fullPage: true,
  mask: [page.locator('[data-private]')]
});

Choose a mask selector that corresponds to content your application actually renders. A mask changes what appears in the image; it does not remove or protect the underlying data in the page or browser session.

Reuse authentication state carefully

For repeated runs, Playwright’s authentication guide shows saving browser storage state after login so a later browser context can reuse it. That file can contain cookies and headers capable of impersonating the account. Treat it like a credential: keep it out of source control and restrict access to it. See Playwright’s authentication guidance for the storage-state workflow and its security warning.

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

When the screenshot still shows the login page

  • The URL wait completes too early: The URL may match before the app has rendered its authenticated controls. Add a visible authenticated-UI assertion after the URL wait.
  • The URL never matches: Verify the actual post-login destination and account for valid route variations or additional redirects. Use the URL condition that reflects your application’s successful flow.
  • The UI assertion times out: Confirm the chosen element is only present after login and that the locator matches the rendered page. If the application uses a different authenticated indicator, wait for that instead.
  • A screenshot or browser page fails during a SAML flow: Individual Playwright issue reports describe failures in specific environments and versions, including intermittent CDP screenshot errors and a Microsoft SAML case involving a newer Playwright version. These reports do not establish a general SAML limitation or a fix that applies to every setup. Check the exact browser, Playwright version, and flow before applying a reported workaround: CDP screenshot issue reports and Microsoft SAML issue report.

Use visual assertions when stability matters

If the goal is to compare a page against a visual baseline rather than simply save a one-off image, Playwright’s toHaveScreenshot assertion waits until two consecutive screenshots match before comparing them; animations are disabled by default on that assertion path. This behavior belongs to the visual assertion API and should not be assumed for a basic page.screenshot() call. See Playwright visual comparisons.

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

Or skip the browser setup

When a page is publicly reachable and does not require your SAML session, ScreenshotNeo can return a screenshot in one GET request. It cannot capture a page that requires the browser session established by your SAML flow.

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

Replace the target URL with a publicly accessible page. See the ScreenshotNeo API documentation for parameters and setup. ScreenshotNeo removes supported cookie-consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

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.

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.