Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix 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×
Skip to content
World desk5 min

How to Make an AI Agent Screenshot a Webpage at a Fixed Viewport Size

Set a webpage viewport before navigation to make an AI agent’s screenshot use consistent dimensions. Learn Playwright, Python, Puppeteer, scale options, and common fixes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the browser page viewport to the required width and height before navigating, then take a normal screenshot. For example, a 1280 × 720 viewport produces a screenshot of the visible page area at those dimensions when captured at CSS-pixel scale. This fixes the webpage’s layout viewport—not the outer operating-system window with browser tabs and controls.

Set a fixed viewport with Playwright

Install Playwright and its browser for your project, then configure the page before loading the target URL. This complete Node.js example saves the visible viewport as page.png:

As an Amazon Associate I earn from qualifying purchases.

import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage();

await page.setViewportSize({ width: 1280, height: 720 });
await page.goto('https://example.com');
await page.screenshot({ path: 'page.png' });

await browser.close();

Replace the URL and dimensions as needed. Width and height are pixels for the webpage viewport. Set the viewport before navigation: responsive pages may lay themselves out based on the size they see when first loaded. Playwright recommends this ordering because many websites do not expect a page to change size after navigation. Playwright page API

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

Apply the dimensions to multiple pages

If your agent creates several pages in the same browser context, set the viewport when creating that context rather than resetting it page by page:

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
const context = await browser.newContext({
  viewport: { width: 1280, height: 720 }
});
const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'page.png' });

Use context-level screen configuration as well if the page needs screen dimensions controlled separately. Calling page.setViewportSize() also resets the screen size. See Playwright browser context options.

Choose viewport or full-page capture

A normal page.screenshot() captures what is visible inside the viewport. It does not capture the full scrollable document. If you need the whole page instead, explicitly request it:

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

A full-page image is taller than the viewport, so do not enable fullPage when the output must remain exactly 1280 × 720. For a specific part of the page, Playwright also supports element screenshots; see its screenshot guide.

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.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Control screenshot pixel scale

The viewport dimensions describe CSS pixels. Playwright’s screenshot scale option determines how those pixels map to image pixels:

  • scale: 'css' produces one image pixel per CSS pixel, which is the clearest choice when you need predictable output dimensions tied to the viewport.
  • scale: 'device' uses device pixels. On a high-density display, the resulting image can be larger than the CSS viewport dimensions.

For a 1280 × 720 image, use CSS scale explicitly when the installed Playwright version supports the option: await page.screenshot({ path: 'page.png', scale: 'css' });. Check the screenshot API options for the version installed in your project.

Python and Puppeteer alternatives

Python with Playwright

Create the page with its viewport before navigation. This asynchronous example saves the visible viewport:

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page(viewport={"width": 1280, "height": 720})
        await page.goto("https://example.com")
        await page.screenshot(path="page.png")
        await browser.close()

Run the function from your application’s async entry point. Playwright APIs and options can evolve, so consult the documentation for the version installed in your environment.

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

JavaScript with Puppeteer

If your agent already uses Puppeteer, set the page viewport before navigating:

const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 720 });
await page.goto('https://example.com');
await page.screenshot({ path: 'page.png' });

Puppeteer likewise recommends setting the viewport before navigation for pages that respond to size changes. Some mobile or touch configurations can reload the page when the viewport is set; see the Puppeteer viewport API.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Make repeated captures more consistent

A fixed viewport is necessary for repeatable screenshots, but it does not guarantee pixel-identical images on different machines. Rendering can vary with operating system, browser version, browser settings, hardware, power source, and headless mode. For visual comparisons, keep the browser version, execution environment, viewport, and capture settings stable. Playwright describes these sources of rendering variation in its visual comparison documentation.

  • Set viewport dimensions before navigation.
  • Use CSS scale when the output should map one-to-one to CSS pixels.
  • Keep the browser and host environment consistent across runs.
  • Choose ordinary viewport capture or full-page capture deliberately; they produce different image dimensions.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting fixed-size screenshots

The image has unexpected dimensions

Check whether you enabled fullPage: true; that makes the image taller than the viewport. Also check the screenshot scale: device scale can produce more image pixels than CSS pixels. Use a normal viewport screenshot and CSS scale when exact CSS-pixel dimensions are needed.

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

The page looks like the wrong responsive layout

Set width and height before goto(), not after the page has loaded. If you use a context, pass viewport to browser.newContext() before creating pages.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Images differ between runs despite the same viewport

Compare the browser version, operating system, rendering settings, hardware, and headless mode. Keep the execution environment stable as well as the viewport; size alone cannot control all rendering differences.

I need the actual desktop window size

Playwright’s viewport APIs control the webpage’s layout area, not the browser’s outer window including tabs and controls. The documented page APIs here do not provide a host-level capture workflow for that different requirement.

Or skip the browser setup

ScreenshotNeo offers a screenshot API and MCP server for AI agents. One GET request can return a screenshot or PDF, without setting up Playwright or Puppeteer in your agent:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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. Cookie banners, newsletter popups, and chat widgets are removed before the shot; each cleanup step can be turned off. Bot checks, blank pages, and failed loads are not billed, and the response identifies the page verdict and billing status. Its MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does a fixed viewport set the browser window size?

No. It sets the webpage’s layout viewport, not the outer operating-system window and its browser controls.

Will 1280 × 720 always produce a 1280 × 720 file?

For a normal viewport capture using CSS scale, it maps to one screenshot pixel per CSS pixel. Full-page capture or device-pixel scale can produce different dimensions.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.