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 Vue page with Playwright, open the running app in a Playwright Page and call await page.screenshot({ path: 'screenshot.png' }). Playwright’s screenshot API works with Vue pages just as it does with any other browser page; no Vue-specific screenshot code is required.

Set up Playwright and capture the Vue page

Install Playwright in your project if it is not already installed, then start the Vue app and use the URL served by its development server. This example uses http://localhost:5173; replace it with your app’s actual URL.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('http://localhost:5173');
  await page.screenshot({ path: 'screenshot.png' });
  await browser.close();
})();

The file path’s extension determines the image format. PNG is the default if no type is specified. The screenshot call captures the visible viewport unless you request a full-page image. See the Playwright Page API for the documented screenshot options.

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

Choose the screenshot area and image scale

Capture the visible viewport

The basic page.screenshot() call captures the currently visible page area. Set the viewport before navigation when the screenshot needs consistent dimensions.

Capture the full scrollable page

Pass fullPage: true to capture beyond the current viewport:

await page.screenshot({ path: 'full-page.png', fullPage: true });

The documented default for fullPage is false.

Capture one Vue component

Use a locator to target a component or other element by a selector that matches your app’s DOM:

await page.locator('.header').screenshot({ path: 'header.png' });

Locator screenshots are the recommended element-capture approach. Playwright discourages using ElementHandle.screenshot(); see the Locator API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Choose CSS-pixel or device-pixel output

Set scale: 'css' for one output pixel per CSS pixel. Use scale: 'device' to capture device pixels; on a high-density display, this can produce a larger image. The screenshot API documents both settings in the Page API.

Set a repeatable viewport

Viewport emulation is configured on the browser context. For example, create a context with a specific viewport, then open a page in it:

const context = await browser.newContext({
  viewport: { width: 1280, height: 800 }
});
const page = await context.newPage();

Choose dimensions that match the screen you want to represent. Playwright notes that setting a page viewport also resets screen size; when you need finer control, configure the context’s screen and viewport parameters. See the Pages guide.

Make captures more stable for visual comparisons

For a one-off image, the default capture may be sufficient. For repeatable checks, minimize changes between captures:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use the same viewport and browser configuration for the baseline and later screenshots.
  • Where animation makes the result vary, locator screenshots accept animations: 'disabled'. Playwright fast-forwards finite animations and cancels infinite animations for the capture behavior described in its Locator API.
  • Keep the capture environment consistent where practical. Playwright says rendering may vary with operating system, browser version, settings, hardware, power source, and headless mode. Its visual comparisons guidance documents expect(page).toHaveScreenshot() for Playwright Test screenshot comparisons.

Troubleshoot common screenshot problems

The image is blank or shows the wrong page

Check that the Vue development server is running and that page.goto() uses the exact URL and port it serves. A local example URL is not universal. If navigation happens before the relevant content appears, wait for an app-specific selector before capturing.

The screenshot only shows part of the page

That is the default viewport behavior. Add fullPage: true for the full scrollable page, or use a locator’s screenshot() method when you want just one component.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

The image dimensions differ from the expected size

Check the context viewport and the screenshot’s scale. CSS scale maps one output pixel to one CSS pixel; device scale uses device pixels and may yield more pixels.

Visual regression images change between runs

Keep the browser, host environment, viewport, and capture settings consistent. Consider disabling animation for locator captures when motion affects the target element. Different operating systems, browser versions, settings, hardware, power sources, and headless mode can affect rendering.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. Make a GET request with the page URL to get an image or PDF; this cURL example saves a WebP screenshot:

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

See the ScreenshotNeo API documentation for request options. Cookie banners and consent overlays, newsletter popups, and chat widgets are removed before capture; those cleanup steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response reports page verdict and billing headers. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month—no card required.

Frequently Asked Questions

Does a Vue component need a special Playwright screenshot method?

No. Navigate to the Vue app and use the standard Playwright page or locator screenshot API.

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

Can I use Playwright Test for screenshot comparisons?

Yes. Playwright Test documents `expect(page).toHaveScreenshot()` for screenshot comparisons.

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.