Playwright has no documented screenshot option that adds a border of pixels around the finished image. If you want a fixed border around the bitmap, capture to a buffer and extend it with an image library such as Sharp. If the whitespace should be part of the page design, add CSS padding to a wrapper and capture the wrapper instead. The distinction matters: CSS changes what is rendered; image extension changes the finished file.
Choose where the padding belongs
First decide what you mean by padding. For a card or component that should appear with surrounding space as part of its design, use CSS. For a screenshot that needs a uniform margin around its existing pixels—for example, a framed image for a report—extend the image after capture. Playwright documents screenshot controls such as clipping, full-page capture, format, scale, and background behavior, but not an output-padding option. Playwright’s Page API reference documents the screenshot options.
| Approach | What it changes | Use it when |
|---|---|---|
| CSS wrapper | The rendered page includes the spacing, and the wrapper’s background is part of the screenshot. | The gap belongs to the page or component design. |
| Image extension | The screenshot’s existing pixels stay intact; new pixels are added around them. | You need a fixed border or canvas around a completed screenshot. |
This is a practical comparison of the two workflows, not a performance benchmark. Both can produce a padded-looking image, but they produce it at different stages.
Add a pixel border after capture with Sharp
In Node.js, page.screenshot() can return image bytes as a Buffer when you do not provide a path. Playwright’s screenshots guide explicitly describes getting a buffer so it can be post-processed or passed to pixel-diff tooling. Playwright Screenshots documentation. Sharp’s extend() operation adds pixels to image edges; it accepts per-edge amounts and lets you set the background or fill from edge pixels. Sharp’s resize API reference.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- 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
Install Playwright and Sharp if they are not already in your project, then install a browser supported by your Playwright setup. For a project using npm, the commands are:
npm install playwright sharp
npx playwright install chromium
Save the following as an ES module, such as padded-shot.mjs. It captures a page, adds 24 pixels on every side using a light-gray background, and writes a PNG. Change targetUrl, the padding values, or the background to suit your use case.
import { chromium } from 'playwright';
import sharp from 'sharp';
const targetUrl = 'https://example.com';
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto(targetUrl, { waitUntil: 'load' });
const screenshot = await page.screenshot({ type: 'png' });
const padded = await sharp(screenshot)
.extend({
top: 24,
right: 24,
bottom: 24,
left: 24,
background: '#f4f4f4',
})
.png()
.toBuffer();
await sharp(padded).toFile('padded-shot.png');
} finally {
await browser.close();
}
The output grows by the total added amount on each axis: 24 pixels on the left and 24 on the right add 48 pixels to the width; top and bottom add 48 to the height. Sharp returns a new image buffer, so the code writes that result—not the original Playwright buffer—to the output file. Sharp is an optional image-processing dependency; Playwright does not bundle it, and you do not need it for the CSS-wrapper approach.
Rank #2
- 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
Set different padding on each edge
The four extend values are independent. For example, use top: 16, right: 32, bottom: 16, and left: 32 for a wider horizontal border. You can also use a uniform pixel amount where supported by the Sharp API. The background value fills the added area; alternatively, Sharp documents edge extension modes that copy, repeat, or mirror edge pixels. Consult the Sharp API reference for the accepted options and current details.
Transparency and image format
If the new border should be transparent, use an alpha-capable format such as PNG and set a transparent background value supported by Sharp. JPEG does not retain transparency. Playwright’s omitBackground: true affects the page screenshot background, not the pixels Sharp adds later; JPEG cannot use Playwright’s transparent-background option. Choose the page background and extension background separately when both matter. Playwright’s Page API reference and the Sharp reference describe these controls.
Add spacing to the rendered page with CSS
When the whitespace should be part of the design, wrap the target element, style the wrapper, and take a locator screenshot of that wrapper. Playwright supports screenshots of a selected locator; the locator you screenshot must include the wrapper for its padding to appear. Playwright’s screenshots guide.
Rank #3
- 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.
<div class="screenshot-frame">
<section class="card">Content to capture</section>
</div>
.screenshot-frame {
display: inline-block;
padding: 24px;
background: #f4f4f4;
}
await page.locator('.screenshot-frame').screenshot({ path: 'card.png' });
These snippets belong in the page and Playwright code for your application: the markup and CSS create the spacing, and the locator screenshot captures the element. If you instead screenshot .card, the wrapper and its padding are outside the selected target, so they will not be included. This is ordinary CSS layout behavior, not a special Playwright padding setting.
Use screenshot options for capture bounds, not padding
The clip option accepts a rectangle with x, y, width, and height. It selects which region to capture; it is not documented as a way to expand the output with a border. Use it when you know the capture region, not as a substitute for CSS or post-capture extension. See the Page API reference and Playwright API Parameters reference.
Other screenshot settings affect the image you extend or the region you capture, so choose them deliberately:
Rank #4
- 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
fullPage: truecaptures the full scrollable page rather than only the viewport. Full-page content dimensions affect how large the padded result becomes.typeselects PNG, JPEG, or WebP; the documented default is PNG. Pick a format that supports the background behavior you need.scale: 'css'produces one output pixel per CSS pixel, whilescale: 'device'uses device-pixel resolution and may produce larger dimensions. A 24-pixel extension applies to the screenshot buffer’s pixels, so account for the selected scale.omitBackground: truemakes the captured page background transparent except for JPEG. It does not set the color or transparency of the added border.pathwrites a screenshot to a file; omit it when you want the screenshot buffer for post-processing.
Keep padded screenshots consistent
For visual regression tests or repeatable assets, make the entire capture pipeline deterministic. Keep the viewport, target element, screenshot scale, format, CSS state, and extension values fixed. Set an explicit border background rather than relying on an incidental page color. Playwright’s screenshots documentation notes that a returned buffer can be passed to pixel-diff tooling, which is useful when comparing generated images. Playwright Screenshots documentation.
Mind the final dimensions: image extension increases each axis by the sum of its corresponding edge values. A large full-page image or device-scale capture will make a larger output buffer, and any image-processing pipeline must handle that output. No performance figure is established by the API references cited here; measure your own pages and image sizes if throughput or memory use is important. Avoid adding the border twice: if CSS already provides a frame and you also call extend(), both margins will appear.
Troubleshooting
- The output has no padding. Confirm the code processes the Buffer returned by
page.screenshot(), and that it writes the result ofextend(). In the CSS method, confirm the locator targets the wrapper rather than only its child. - The border is the wrong color. Set Sharp’s
backgroundexplicitly for post-capture pixels. For CSS padding, set the wrapper’s CSSbackground; these are separate backgrounds. - The border appears transparent or turns black. Check the output format and alpha settings. Use PNG for transparency; JPEG cannot preserve it. A transparent page background does not automatically make Sharp’s extension transparent.
- The image dimensions are larger than expected. Add the left and right values to predict width, and top and bottom to predict height. Also check whether device-pixel scaling or full-page capture made the source image larger than expected.
- The wrapper spacing is missing or clipped. Capture the wrapper locator, not its inner element, and ensure the wrapper is rendered with the padding and background before the screenshot call.
- The capture rectangle cuts off content. Review the
clipcoordinates and dimensions. Clipping defines the capture region; it does not create extra canvas around it. - The Sharp import or command is unavailable. Make sure Sharp is installed in the project that runs the script and that the script’s module format matches its imports. Sharp is not included with Playwright.
- The browser will not launch. Install the browser binary for the Playwright setup in the project, and check the launch error for environment-specific requirements. The example’s
npx playwright install chromiumcommand installs Chromium for that setup.
Or skip the browser setup
ScreenshotNeo can return a website screenshot through one GET request, so you can avoid installing and launching a local browser for the capture. This call returns a screenshot; it does not add bitmap padding. If you need a fixed border, pass the returned image through the Sharp extension step above. For page-design spacing, arrange the page or target content with CSS before capturing.
Best Value
- 【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.
cURL example, with the request format and API details in the ScreenshotNeo documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses indicate the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, or any MCP client. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.
FAQ
Can I add a negative amount to create an inset or crop?
No. Extension adds pixels outside image edges; use a crop or a different capture region when you need to remove pixels.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Frequently Asked Questions
Can I add a negative amount to create an inset or crop?
No. Image extension adds pixels outside the existing edges; use a crop or change the capture region to remove pixels.
Quick Recap
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.

