To convert a Playwright screenshot to Base64, capture it without a file path so Playwright returns the image bytes, then encode those bytes with your language’s Base64 API. In Node.js, the short version is const base64 = (await page.screenshot()).toString('base64');. The same workflow works in Python, Java, and .NET. You do not need to write an image to disk first.
Capture screenshot bytes, then encode them
Playwright separates taking the screenshot from choosing how to represent it. A screenshot call returns image data in memory when you omit the path option. That result is a Node.js Buffer, Python bytes, a Java byte[], or a .NET byte[], depending on the language. Pass it to that language’s Base64 encoder to get a text string.
This is useful when an API accepts an image as Base64, when you need to place an image in a data URL, or when you want to pass screenshot data between program components without creating a temporary file. The encoded string is text; it is not itself an image file. A receiving API may require raw Base64 or a data URL, so check its expected input format.
JavaScript and Node.js
The official Playwright JavaScript guide demonstrates taking a screenshot and converting the returned buffer with Node’s built-in Buffer method. The example below assumes you already have a Playwright page open and loaded.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
const screenshotBuffer = await page.screenshot();
const base64 = screenshotBuffer.toString('base64');
console.log(base64);
page.screenshot() returns a Promise that resolves to a Buffer. Await it before encoding. To save a file instead, provide a path option; a path is not needed for the in-memory Base64 flow.
Here is a runnable Node.js example that opens a page, captures it, prints the Base64 string, and closes the browser. Install Playwright in your project and install its browser binaries as described in the official JavaScript screenshots guide.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com');
const screenshotBuffer = await page.screenshot({ type: 'png' });
const base64 = screenshotBuffer.toString('base64');
console.log(base64);
} finally {
await browser.close();
}
})();
The full encoded image can be large. For production use, consider returning it from a function, storing it, or sending it directly to the consumer rather than printing it to a terminal or log.
Python
In Python, use base64.b64encode() on the bytes returned by page.screenshot(). The result of the encoder is also bytes, so decode it to a string if the receiving code expects textual Base64.
import base64
screenshot_bytes = await page.screenshot()
base64_string = base64.b64encode(screenshot_bytes).decode("ascii")
This snippet uses the async Playwright API. The same byte-to-Base64 conversion applies if you use Playwright’s synchronous API; the screenshot call itself is synchronous in that mode. The official Python screenshots guide includes both sync and async patterns and documents screenshot paths and capture scope.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
A complete asynchronous example:
import asyncio
import base64
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
try:
page = await browser.new_page()
await page.goto("https://example.com")
screenshot_bytes = await page.screenshot(type="png")
base64_string = base64.b64encode(screenshot_bytes).decode("ascii")
print(base64_string)
finally:
await browser.close()
asyncio.run(main())
Java
Java’s standard Base64 encoder accepts the byte array produced by Playwright’s screenshot call. The Playwright Java guide shows this in-memory pattern.
byte[] screenshotBytes = page.screenshot();
String base64 = Base64.getEncoder().encodeToString(screenshotBytes);
Import java.util.Base64 and use the Playwright Java dependency and browser setup appropriate to your project. You can pass screenshot options to select a path or capture behavior; for Base64, omit the path and encode the returned bytes. See the official Java screenshots guide for setup and capture examples.
.NET
In .NET, Page.ScreenshotAsync() returns a byte array. Convert.ToBase64String() turns that array into a Base64 string.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
var screenshotBytes = await page.ScreenshotAsync();
string base64 = Convert.ToBase64String(screenshotBytes);
For a complete capture flow, create and navigate a Playwright page first, then await the screenshot operation before encoding. The official .NET screenshots guide covers screenshot capture and saving to a path; the .NET Page API reference documents the API for the installed version.
Choose the screenshot before encoding it
Base64 represents the bytes you captured; it does not change what is in the image. Decide on the capture target and format first. Playwright supports page screenshots, full-page screenshots, and locator screenshots in the language guides. Relevant option names differ by language, so use the reference for your installed Playwright version.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Viewport, full page, or one element
- Viewport: The default page screenshot captures the page as currently visible in the viewport. This is appropriate for a screen-sized image or a visual check of the current state.
- Full page: Set
fullPage: truein JavaScript orfull_page=Truein Python to capture the full scrollable page, rather than only the visible viewport. Java and .NET provide corresponding screenshot options in their APIs. - Element: Use a locator’s screenshot method when only a particular element is needed. This can reduce irrelevant content in the image; make sure the locator resolves to the intended element before capturing.
For example, the documented JavaScript forms include await page.screenshot({ fullPage: true }) for the page and await page.locator('article').screenshot() for a matching element. Python uses the spelling full_page=True. See the relevant language guide for syntax in Java or .NET.
Image format and options
Screenshot output can use PNG, JPEG, or WebP where supported by the applicable API. PNG is a sensible default when you need lossless image data or transparency; JPEG is useful when a smaller photographic image matters more than lossless fidelity. WebP is another supported output choice. Quality settings apply only to relevant formats, and options such as background omission do not apply to JPEG. Consult the API reference for exact availability and spelling in your Playwright version.
Free tools Windows power users keep installed
One-click scans. No signup required.
Other documented screenshot controls include scale behavior, masking, and background handling. These affect the bytes before Base64 encoding. If a receiving system imposes a format or size requirement, set the screenshot options to meet it before encoding rather than assuming Base64 will optimize or convert the image.
Raw Base64 versus a data URL
The examples above produce raw Base64: a string of encoded image bytes with no prefix. Some browser-facing consumers instead expect a data URL, which combines a media type, an encoding marker, and the payload. For a PNG screenshot, the form is:
const dataUrl = `data:image/png;base64,${base64}`;
Use the prefix only if the receiving interface asks for a data URL. If the screenshot format is JPEG or WebP, use the matching media type rather than image/png. The Playwright examples document encoding the screenshot bytes; they do not require a data-URL wrapper. Confirm the expected format at the point where you submit or display the string.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Or skip the browser setup
If you want a screenshot through an HTTP request instead of launching Playwright and managing a browser, ScreenshotNeo accepts a URL and returns an image or PDF. Its screenshot options include PNG, JPEG, and WebP. To capture a page, its API supports a single GET request; the code below saves the returned image bytes to a file. See the ScreenshotNeo API documentation for request details.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
To encode the response bytes in Python rather than save the response as an image file:
import base64
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
base64_string = base64.b64encode(r.content).decode("ascii")
ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. It also offers an MCP server for AI agents, including Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. For plans and account access, visit ScreenshotNeo.
Sign up for the free plan: 1,000 screenshots a month, no card required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting Base64 screenshots
- The screenshot call returns no usable value: In JavaScript, await the screenshot Promise before using the result. In Python async code, await the call; in .NET, await
ScreenshotAsync(). A screenshot operation that has not completed cannot yet be encoded. - The encoded value looks like binary or has an unexpected type: JavaScript’s Buffer method returns a string. Python’s
b64encode()returns bytes, so decode those bytes for a text field. Java and .NET return strings from the examples shown. - The receiving endpoint rejects the payload: Check whether it wants raw Base64 or a data URL, and whether it accepts the chosen image media type. Do not add a data-URL prefix unless required.
- The image is cut off or contains the wrong content: Check whether you need a full-page capture or a locator screenshot, and verify that the page has loaded into the intended state before capture. Full-page and element options are capture choices, not Base64 settings.
- The output is larger than expected: Base64 is an encoding, not image compression. Select a suitable image format and capture scope before encoding; use a format’s supported quality option where appropriate.
- An option is rejected or behaves differently: The option spelling and availability can vary by language and Playwright version. Check the API reference corresponding to the version installed in your project.
Memory, reliability, and cost considerations
In-memory encoding avoids a write-then-read cycle and is convenient for pipelines that send the image directly to another service. The screenshot and encoded string both occupy memory while both are retained, so avoid accumulating large page captures or Base64 strings unnecessarily. If the consumer accepts a file or byte stream, passing those bytes directly may be preferable to constructing a text representation.
Capture completion depends on the page and browser workflow as well as the encoding step. Base64 conversion only transforms the resulting bytes; it cannot correct a navigation failure, a page that has not reached the desired state, or a screenshot taken before dynamic content appears. Establish the correct page state and choose the right capture target before encoding. Keep the screenshots and resulting Base64 out of logs if they may contain private page content.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Playwright itself is a browser-automation approach: your application has to initialize the relevant Playwright language runtime and browser, navigate to the target, and manage capture in its own process. There is no per-screenshot price stated in the cited Playwright documentation. Hosted screenshot services instead charge according to their own plans and rules; for ScreenshotNeo, current plan amounts and billing behavior are described above and on its site.
Frequently asked questions
Does Playwright Base64-encode screenshots automatically?
No. Playwright returns screenshot bytes or a buffer; call your language’s Base64 encoder on that value.
Can I convert an existing screenshot file to Base64?
Yes. Read the file into bytes and use the same language-native encoder. Capturing directly to bytes simply avoids needing that intermediate file.
Recommended Free Tools
Does Base64 make a screenshot smaller?
No. Base64 changes binary bytes into text representation; it is not a compression format. Choose the image format and screenshot scope for the actual size and quality trade-off you need.
Which Playwright option names should I use?
Use the names documented for your language and installed Playwright version. For instance, the full-page option is spelled fullPage in JavaScript and full_page in Python.
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.

