October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Canvas

How to Fix Blank Three.js canvas.toDataURL() Screenshots

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

If a Three.js scene is visible in the browser but canvas.toDataURL() returns a blank or black image, the usual cause is WebGL drawing-buffer lifetime. Three.js creates its renderer with preserveDrawingBuffer: false by default. Render the scene immediately before reading the canvas for a one-off capture. If code must read the last frame later, create the renderer with preserveDrawingBuffer: true, accepting possible performance and resize trade-offs.

This guide explains both fixes, a render-target workflow for controlled pixel reads, browser and application checks, and an API alternative when you do not want to run a browser yourself.

Why a visible Three.js canvas can produce a blank image

A WebGL canvas is not the same as a permanent bitmap. With the default preservation setting disabled, the browser may discard or invalidate the drawing buffer after the rendering function returns. The WebGL specification says that later operations such as readPixels() and toDataURL() can then have undefined results. The canvas can remain visibly correct on screen while a later capture reads cleared or empty contents. See the WebGL specification.

Three.js documents the same failure mode in its canvas screenshot guide: the reliable one-time solution is to call the rendering code immediately before capture. This is a drawing-buffer issue, not normally a PNG encoder problem.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 4x optical zoom with a 27mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen with 2 AA alkaline batteries for convenient on-the-go use

Fix 1: render immediately, then call toDataURL()

For a single screenshot, keep rendering and reading in the same function path. Use the actual renderer canvas, not a separate canvas element, and make sure the scene and camera contain the state you intend to capture.

function captureScene() {
  // Render the current scene into renderer.domElement first.
  renderer.render(scene, camera);

  // Read the buffer while it is valid for this render operation.
  const dataUrl = renderer.domElement.toDataURL('image/png');

  const link = document.createElement('a');
  link.href = dataUrl;
  link.download = 'three-scene.png';
  link.click();
}

button.addEventListener('click', captureScene);

The important ordering is renderer.render(...) followed immediately by renderer.domElement.toDataURL(...). Do not render in one callback and capture in a later timer, promise continuation, or unrelated animation frame unless you render again immediately before reading.

Animation-loop example

In an animation-driven application, factor the render operation so a capture request can invoke it with the current state:

function renderFrame() {
  controls.update();
  renderer.render(scene, camera);
}

function captureCurrentFrame() {
  renderFrame();
  return renderer.domElement.toDataURL('image/png');
}

function animate() {
  requestAnimationFrame(animate);
  renderFrame();
}
animate();

If controls, uniforms, or object transforms change just before capture, update them before the render call. A screenshot captures the completed render, not merely the values assigned to objects.

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

Fix 2: preserve the drawing buffer for later captures

When the application genuinely needs to read the last rendered frame after the render call has returned, enable preservation while creating the renderer:

const renderer = new THREE.WebGLRenderer({
  preserveDrawingBuffer: true,
});

The option is false by default in Three.js. With preservation enabled, a later call such as renderer.domElement.toDataURL('image/png') can access the retained frame. The WebGLRenderer documentation exposes this renderer option.

Rank #2
Sale
Kodak PIXPRO FZ55-BK 16MP CMOS Sensor Camera 5X Optical Zoom 28mm Wide
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 5x optical zoom with a 28mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen and a rechargeable lithium-ion battery for on-the-go use

Performance and resizing caveats

Preserving the buffer is not free. The WebGL specification warns: “While it is sometimes desirable to preserve the drawing buffer, it can cause significant performance loss on some platforms.” The cost depends on the browser and graphics hardware, so measure your own workload rather than assuming a fixed slowdown.

Three.js also notes that preservation alone is not a complete solution for drawing applications whose canvas resolution changes. If you resize the renderer, verify that the dimensions and pixel ratio are what you expect before capturing. For an occasional screenshot, render-then-capture avoids imposing preservation overhead on every frame.

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

Choosing the right capture method

Method Best fit When pixels are read Main trade-off
Render immediately, then toDataURL() One-off PNG, JPEG, or WebP capture In the same function immediately after rendering Capture code must control render timing
preserveDrawingBuffer: true Later access to the last canvas frame After the render call returns May reduce performance; resizing still needs care
WebGLRenderTarget plus Three.js read APIs Controlled pipelines, raw pixels, repeated processing From an explicit off-screen target More setup than reading the display canvas

Controlled captures with WebGLRenderTarget

If you need raw pixels, deterministic off-screen rendering, or a pipeline separate from the visible canvas, render into a WebGLRenderTarget. Three.js provides renderer.readRenderTargetPixels() and an asynchronous counterpart. The API documentation recommends the asynchronous read method whenever possible.

const target = new THREE.WebGLRenderTarget(width, height, {
  depthBuffer: true,
  stencilBuffer: false,
});

renderer.setRenderTarget(target);
renderer.render(scene, camera);
renderer.setRenderTarget(null);

const pixels = new Uint8Array(width * height * 4);
await renderer.readRenderTargetPixelsAsync(
  target,
  0,
  0,
  width,
  height,
  pixels
);

// pixels now contains RGBA byte values for the target.

Use the synchronous readRenderTargetPixels() method when your environment requires it, but prefer the asynchronous form to avoid blocking the main thread where supported. A render target gives you explicit control over the framebuffer instead of depending on the display canvas’s post-render lifetime.

WebGL’s lower-level readPixels() API reads a rectangular block from the current color framebuffer into a typed array or DataView; MDN documents its arguments and constraints at WebGLRenderingContext: readPixels(). In a Three.js application, the render-target methods usually provide the more direct integration.

Do not confuse clearing with buffer preservation

Three.js clears renderer buffers before rendering by default. The settings autoClear, autoClearColor, autoClearDepth, and autoClearStencil control that render behavior. They are separate from the browser’s preserveDrawingBuffer setting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Digital Camera, Latest FHD 1080P Digital Camera for Teens with SD Card Anti Shake Point and Shoot Cameras Portable 16X Zoom Compact Small Cameras for Kids Boys Girls Seniors with Wrist Strap
  • Latest Digital Camera Built-in Fill Light : This compact digital camera is paired with a powerful CMOS processor and image stabilization to help you take & record the most exciting moments in 44 MP quality images & FHD 1080P quality videos anywhere, anytime. Plus, there is also a built-in fill light to help you take high quality pictures even in low light&dark settings, making this the perfect camera for all indoors/outdoors situations.
  • Long-Lasting Battery Life & 16X Digital Zoom :This point and shoot camera will retain its battery charge even after long use. The controls and functions are easy to operate making this the perfect choice for children, teens and younger. This kids camera supports 16x digital zoom, you can zoom in or out the subject by pressing the W/T button for taking still photos to zoom in or out on distant objects and capture all the details you need.
  • Multifunctional & Portable Digital Camera: This cheap digital camera is slim enough to fit in your pocket. You'll easily be able to take it with you on all your indoor/outdoor activities and adventures and ideal for beginners, children and teenagers. This kids digital camera is equipped with 20 filters, anti-shaking, self-timer, continuous shooting, date stamp, time-lapse recording, smile capture, internal MIC and speaker (recording sound videos), great for your daily photography needs.
  • WEBCAM & PAUSE FUNCTION : More than just a FHD 1080p digital camera, it also works as a webcam for video calls and vlogging. Connect the camera to the computer, press shutter and power button at the same time and the camera will automatically turn on webcam mode for all your video calling and live streaming needs. The pause function allows you to pause when seeing playback videos.
  • A Must Have Photography Device : This digital camera with SD card made from high-quality materials, this retro camera is safe and durable. Perfect for all ages to develop & improve their photographic abilities and observation skills. Our dedicated and experienced 24/7 support team is available for all after purchase troubleshooting, questions and technical help.

Disabling clearing is therefore not the standard fix for a blank toDataURL() result. Change clear settings only when your scene deliberately relies on accumulation or multiple passes. For an ordinary screenshot, render immediately before capture first.

A practical diagnostic checklist

  • Confirm the canvas: capture renderer.domElement, the canvas Three.js actually renders into.
  • Render in the capture path: call renderer.render(scene, camera) directly before toDataURL().
  • Check dimensions: inspect renderer.domElement.width and height, not only its CSS size. A zero drawing-buffer dimension produces no useful image.
  • Check camera and scene state: verify the camera sees the objects, materials are visible, and any animation or controls update occurs before rendering.
  • Check asynchronous loading: wait for textures, models, and fonts that affect the frame. Capturing before resources finish can produce an apparently empty scene even when buffer lifetime is correct.
  • Check renderer errors: inspect the browser console for WebGL context loss, shader compilation failures, or security errors.
  • Check cross-origin assets: images and textures loaded without appropriate CORS permission can prevent a canvas from being read. Fix the asset server’s headers and loading mode rather than trying to bypass browser security.
  • Use preservation only when needed: if render-then-capture works, avoid enabling preservation for every frame without measuring the cost.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure modes and fixes

The image is transparent or entirely black

First test the immediate render-and-capture sequence. If it succeeds, the previous code was reading the buffer too late. If it still fails, confirm that the scene is visible from the active camera and that the renderer canvas has non-zero dimensions.

The capture runs after a timeout

A delay does not make the drawing buffer safer. Replace the delayed read with a fresh render immediately before toDataURL(), or enable preservation when delayed access is a real requirement.

The screenshot shows an earlier frame

Render again after applying the latest object, camera, control, and uniform changes. In an animation loop, do not assume the next scheduled frame has already run when a button handler executes.

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.

Preservation was enabled but output is still wrong after resize

Update the renderer and camera for the new size, verify drawing-buffer dimensions, then render and capture. Three.js’s guidance treats resizing as a separate concern from retaining the buffer.

Raw pixel reads are slow or stall the page

Use a render target and the asynchronous read method where possible. Read only the rectangle you need, and avoid performing large synchronous reads on the main thread during interaction.

Rank #4
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 5x optical zoom with a 28mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen and a rechargeable lithium-ion battery for on-the-go use

Or skip the browser setup

If your goal is a clean image of a public webpage rather than a browser-side Three.js debugging session, ScreenshotNeo provides a website screenshot API. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.

One GET request is enough:

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 all options, including full-page lazy-image loading, CSS-selector element capture, device presets, retina scale, PDF output, custom CSS and JavaScript, click actions, waits, request blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, caching, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage data, and the OpenAPI specification. Parameter names used by other screenshot APIs are accepted to simplify migration.

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.

Python

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()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const image = Buffer.from(await res.arrayBuffer());
require('fs').writeFileSync('shot.webp', image);

ScreenshotNeo also has an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Create a free ScreenshotNeo account.

Recommended decision

Use render-then-capture for the normal one-off Three.js screenshot. Enable preserveDrawingBuffer only when later access is required and its performance cost is acceptable. Use a render target when your application needs explicit framebuffer control or raw pixel processing. These choices address different timing and data requirements; changing clear flags alone does not solve the underlying drawing-buffer lifetime issue.

Frequently Asked Questions

Does calling toDataURL() before the first render work?

No. The canvas must contain a completed render. Call the renderer with the intended scene and camera first, then read the canvas immediately.

Which image formats can a canvas export?

The examples use PNG. Browsers commonly support PNG and may support JPEG or WebP; pass the MIME type to toDataURL() and verify the browser’s result for your target environment.

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

Should I set preserveDrawingBuffer on an existing renderer?

No. It is a renderer-creation option. Recreate the renderer with the option enabled, or redesign the capture path to render immediately before reading.

Quick Recap

SaleBestseller No. 1
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
Kodak PIXPRO FZ45 Digital Camera, 16MP Point & Shoot (Black)
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$99.99
SaleBestseller No. 2
Kodak PIXPRO FZ55-BK 16MP CMOS Sensor Camera 5X Optical Zoom 28mm Wide
Kodak PIXPRO FZ55-BK 16MP CMOS Sensor Camera 5X Optical Zoom 28mm Wide
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$139.99
Bestseller No. 4
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
Kodak PIXPRO FZ55-RD 16MP Camera 5X Optical Zoom 28mm Wide Angle 1080p
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$139.99

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.

Leave a Reply

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

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

Read next

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.