TechBuzzPro

Why Cypress Screenshots Look Blurry & Scale Option

· 6 min read · Apps & Browsers

In this article
  1. Background: Why Screenshots Get Blurry
  2. What the Scale Option Actually Does
  3. How to Choose the Right Scale Value
  4. Common Problems and Misconceptions
  5. Scale vs. Device Pixel Ratio (DPR)
  6. Performance and Storage Considerations
  7. Alternatives for Crisper Screenshots
  8. Frequently Asked Questions

Cypress screenshots often appear blurry because the browser window is captured at a lower resolution than the physical display, and the scale option in cy.screenshot() controls how much the image is resized before saving. By default, Cypress captures the viewport at its CSS pixel dimensions, which on high-DPI (Retina) screens is only a fraction of the actual device pixels, leading to soft, pixelated images when viewed at full size. The scale option lets you multiply that capture resolution, so setting it to 2 on a 2x display yields a crisp, high-resolution image.

Background: Why Screenshots Get Blurry

Modern screens pack more physical pixels into the same CSS space. A 13-inch MacBook Pro, for instance, has a CSS width of 1440px but a physical resolution of 2880px (2x). When Cypress takes a screenshot, it captures the page at the CSS viewport size—1440×900 on that laptop—not the physical pixel count. If you then view that screenshot on the same screen or share it, the browser or image viewer stretches the 1440px-wide image to fill the 2880px-wide display, and the interpolation makes edges look soft.

Cypress does this deliberately for consistency: tests run in a headless browser or Electron, and the viewport is defined in CSS pixels. The tool doesn't know or care about your monitor's pixel density unless you tell it to capture more detail.

What the Scale Option Actually Does

The scale option is a multiplier applied to the screenshot's internal resolution. It does not change the layout or the viewport size; it only changes how many pixels are written to the output file.

  • scale: 1 (default) – captures at CSS pixel dimensions (e.g., 1280×720 on a 720p viewport).
  • scale: 2 – captures at double the CSS dimensions (e.g., 2560×1440 for a 720p viewport).
  • scale: 0.5 – captures at half the CSS dimensions (e.g., 640×360 for a 720p viewport).

Think of it as the DPI setting in a graphics editor. A 100×100px image at 1x and at 2x contain the same layout, but the 2x version has four times as many pixels, so it appears sharper when scaled to the same physical size.

How to Choose the Right Scale Value

The ideal scale depends on where the screenshot will be viewed. If you're generating documentation or visual regression tests that will be compared pixel-by-pixel, you want a consistent, high-resolution capture. If you're just logging a quick view for debugging, the default is fine and saves disk space.

Here are practical guidelines:

  • Default (1) – for quick debugging, small file size, and when the screenshot will be viewed at the same CSS size.
  • 2 – for high-DPI displays, documentation, or when you plan to zoom in. This is the most common choice for crisp images.
  • 3 or higher – for very large displays or when you need extreme detail, but beware of large file sizes and memory usage.

You can also set a global default in cypress.config.js under screenshotOnRunFailure and screenshot options, so you don't have to repeat it in every test.

Common Problems and Misconceptions

“My screenshots are blurry even with scale: 2.” This often happens because the image viewer is still downscaling. If you capture at 2x and view it at 50% zoom, it will look identical to a 1x capture at 100% zoom. The sharpness only appears when you view the image at its full pixel dimensions or when you zoom in.

“Scale doesn't affect the file size much.” Actually, it does—quadrupling the pixel count (scale 2) can increase file size by 3–5x for PNGs, depending on content. For large suites, this can bloat your artifacts.

“The scale option also scales the element screenshot.” Yes, it applies to cy.screenshot() for both full-page and element captures. However, for element screenshots, the scale is relative to the element's bounding box, not the viewport.

“I set scale in the test but it's ignored.” Check that you're passing it as an options object: cy.screenshot('name', { scale: 2 }). Also, ensure you're not using a plugin or a custom command that overrides the option.

Scale vs. Device Pixel Ratio (DPR)

Some test runners have a separate “device pixel ratio” setting that emulates a high-DPI display. Cypress does not have a built-in DPR emulation; the scale option is the only way to increase capture resolution. This is a key difference from tools like Playwright or Puppeteer, where you can set deviceScaleFactor to simulate a Retina screen. If you need to test responsive behavior at different DPRs, you'd have to use a different tool or a workaround.

Performance and Storage Considerations

Higher scale values increase memory usage during capture and disk usage for the saved files. For a test suite with hundreds of screenshots, the difference can be significant:

  • At 1280×720, a PNG screenshot is typically 200–500 KB.
  • At 2560×1440 (scale 2), the same screenshot can be 1–2 MB.
  • At 3840×2160 (scale 3), expect 3–5 MB.

If you're running in CI, this can slow down artifact upload and increase storage costs. A common pattern is to use scale 2 only for visual regression tests and keep scale 1 for failure screenshots.

Alternatives for Crisper Screenshots

If you need high-resolution captures without manual scale values, consider these options:

  • Use a headless browser with a high DPR – Cypress's Electron browser doesn't support DPR emulation, but you can use a different browser like Chrome with the --force-device-scale-factor flag, though this is not officially supported.
  • Post-process with an image upscaler – Tools like sharp or ImageMagick can resize images with high-quality algorithms, but this won't recover detail that wasn't captured.
  • Set a larger viewport – Increasing the viewport size (e.g., cy.viewport(1920, 1080)) gives you more CSS pixels, which translates to more detail in the screenshot, but it also changes the layout and may break responsive tests.

For most use cases, scale 2 is the sweet spot between quality and performance.

Frequently Asked Questions

Why are my Cypress screenshots blurry on a Mac?

Macs have high-DPI Retina displays, so the default CSS pixel capture is half the physical resolution. Use scale: 2 to match the physical pixel density and get sharp images.

Does the scale option affect the test's behavior?

No, it only affects the screenshot output. The test runs at the viewport size you set with cy.viewport() or the default, and the scale option does not change any layout or interaction.

Can I set a global scale for all screenshots?

Yes, in cypress.config.js you can add screenshotOnRunFailure: { scale: 2 } and screenshot: { scale: 2 } to apply it to all screenshots, including failure captures.

What is the maximum scale value I can use?

There's no hard limit, but very high values (e.g., 10) can cause memory issues and produce enormous files. Stick to 2 or 3 for practical use.

Why do my screenshots look fine in the Cypress runner but blurry in CI?

In CI, the browser often runs in headless mode with a different default viewport size and no high-DPI display. The screenshot is captured at the CSS viewport, which may be smaller than what you see locally. Set an explicit viewport and scale in your tests to ensure consistency.