Quick answer: Load the Bugnet Web SDK, call Bugnet.init() after your renderer’s canvas is in the page, and open the form with Bugnet.showWidget({ canvas: renderer.domElement }). If the screenshot comes back blank, that is the classic Three.js canvas.toDataURL blank problem: WebGL clears the drawing buffer after presenting a frame. Create the renderer with preserveDrawingBuffer: true, or call renderer.render() and toDataURL() back to back in the same task. Release pointer lock and ignore game keys while the form has focus.

A Three.js game is a web page with a canvas, which makes bug reporting both easy and slightly treacherous. Easy, because an HTML form can sit on top of the canvas with no engine work. Treacherous, because three browser behaviours get in the way: a WebGL canvas that reads back as an empty image, a locked pointer that cannot click the form, and key handlers that keep steering the camera while the player types. This guide adds a Three.js bug report form step by step and deals with each of those, then shows the same approach in react-three-fiber, Babylon.js and PlayCanvas.

Load the SDK and initialize after the canvas exists

The Web SDK is one script with no dependencies. The simplest way to use it from a bundled project is a plain script tag ahead of your module, which gives you a Bugnet global:

<script src="https://bugnet.io/sdks/web/bugnet-sdk.js"></script>
<script type="module" src="/src/main.js"></script>

If you prefer to serve it yourself, download the file (the SDK docs have a one-line installer) and put it in your static folder. Then initialize it once, after the renderer’s canvas has been added to the document:

import * as THREE from 'three';

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

Bugnet.init({
  apiKey: 'sk_live_your_key',
  gameVersion: '1.0.3',
});

The order matters for one reason: on startup the SDK looks for a canvas to record from for session replays, and warns in the console if there is none yet. Initializing after appendChild avoids that.

The key comes from your project’s Integrate tab. It is an ingestion key that is meant to be visible in client code: it can file reports and read the SDK’s settings, and it cannot read your bugs. Set gameVersion from your build so you can tell which deploy a report came from. The API accepts requests from any origin, so this works on your own domain and inside an itch.io frame. If your page sends a Content-Security-Policy header, allow https://api.bugnet.io in connect-src, and https://bugnet.io in script-src if you load the script from there.

Open the form

One call puts the form on screen:

Bugnet.showWidget({ canvas: renderer.domElement });

Always pass the canvas. Without it the SDK screenshots the first <canvas> element in the document, and in a Three.js page that is not always the game: a stats panel or a 2D HUD canvas that appears earlier in the DOM would be captured instead.

The form is an HTML overlay with a title, a description, optional steps, and category and priority dropdowns. Escape, Cancel or a click outside the panel closes it. On Submit it files the report with the browser’s user agent, the platform, the GPU string from WEBGL_debug_renderer_info, the core count, device memory where the browser exposes it, and the screen resolution. A screenshot of the canvas is added when Screenshot Capture is on for the project in the dashboard. That screenshot is where most people hit a wall.

Why the Three.js screenshot is blank

You open the form, submit a report, and the image in the dashboard is solid black, white or transparent. Nothing is wrong with the SDK call or with toDataURL. This is how WebGL works.

A WebGL context has a drawing buffer. When your requestAnimationFrame callback returns, the browser presents that buffer to the page, and by default it is then free to clear it or swap it for another one. Anything that reads the canvas afterwards, such as toDataURL, toBlob, drawImage(canvas) or readPixels, gets the cleared buffer. A click on a Submit button happens in its own task, long after the last frame was presented, so the read finds nothing.

This is the same reason a “save screenshot” button in a Three.js demo produces an empty PNG. There are two fixes, and you only need one.

Fix 1: preserveDrawingBuffer

Ask the context to keep its contents:

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

That is the whole change. The buffer now survives until you draw over it, so a read at any time returns the last rendered frame. Three.js still clears before each render by default, so nothing looks different on screen. The form’s screenshot works, and so do screenshots attached to automatically captured errors, which are taken whenever the error happens.

The cost is that the browser can no longer discard or swap the buffer after presenting it, which on some GPUs means an extra copy every frame. On desktop it is often too small to measure. On mobile, where tile-based GPUs benefit most from discarding, it can be visible. The flag is a context creation attribute, so it cannot be toggled later: decide at startup, and profile on your slowest target before you ship it.

Fix 2: render, then capture in the same task

If you do not want the flag, capture at a moment when the buffer is known to be valid: immediately after a render call, before control returns to the browser. The natural moment is when the player asks for the form, which is also the frame they want to show you:

let pendingFrame = null;

function openBugReport() {
  renderer.render(scene, camera);                             // draw a fresh frame now
  pendingFrame = renderer.domElement.toDataURL('image/png');  // same task: buffer is intact

  if (document.pointerLockElement) document.exitPointerLock();
  keys.clear();                                               // the held-key set, defined below
  Bugnet.showWidget({ canvas: renderer.domElement });
}

If you render through an EffectComposer, call composer.render() there instead, so the capture includes your post-processing.

The form itself cannot use that image as its screenshot, but the SDK can attach it to the report once the report has been accepted. Register the callback when you initialize:

Bugnet.init({
  apiKey: 'sk_live_your_key',
  gameVersion: '1.0.3',
  onBugReported(bugId) {
    if (!pendingFrame) return;
    Bugnet.uploadAttachment(bugId, {
      filename: 'frame.png',
      mime_type: 'image/png',
      data: pendingFrame,
    });
    pendingFrame = null;
  },
});

uploadAttachment accepts a data URL as data, so the string from toDataURL goes in unchanged. The image appears on the report as an attachment. With this approach, switch Screenshot Capture off in the dashboard so you do not also store an empty one.

The same trick works for reports you file from code. Render, read the canvas in the next statement, and send the image as an attachment:

renderer.render(scene, camera);
Bugnet.reportBug('Shadow map flickers at dusk', 'Seen on the harbor level.', {
  category: 'visual',
  attachments: [{
    filename: 'frame.png',
    mime_type: 'image/png',
    data: renderer.domElement.toDataURL('image/png'),
  }],
});

If you use Three’s WebGPU renderer, there is no preserveDrawingBuffer option to reach for. Use render-then-capture and check the resulting image before relying on it.

Pointer lock, keyboard and the game loop

A first-person Three.js game has usually locked the pointer, and a locked pointer has no cursor to click a form with. Release it before the form opens, as openBugReport() does above. If you use PointerLockControls, controls.unlock() does the same thing. Browsers only grant pointer lock again from a user gesture, so let your existing “click to resume” handler take it back when the form closes.

The keyboard needs a guard too. Your keydown listener on window still receives every key the player types into the form, so without a check, a description containing “w” walks the camera forward. Ignore events that come from form fields:

const keys = new Set();

function isTyping(event) {
  const el = event.target;
  return el instanceof HTMLElement &&
    (el.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName));
}

window.addEventListener('keydown', (event) => {
  if (isTyping(event)) return;
  if (event.code === 'F2') {
    event.preventDefault();
    openBugReport();
    return;
  }
  keys.add(event.code);
});

window.addEventListener('keyup', (event) => keys.delete(event.code));

That check is independent of the SDK, so it also protects any other HTML input you add later, such as a chat box or a seed field. Clearing keys when the form opens stops a key that was held at that moment from staying pressed.

Finally, stop simulating while the form is up but keep rendering. The form’s overlay element has the id bugnet-overlay, so one line tells you whether it is on screen:

const clock = new THREE.Clock();
const formOpen = () => document.getElementById('bugnet-overlay') !== null;
let wasOpen = false;

renderer.setAnimationLoop(() => {
  const dt = clock.getDelta();          // always read, so time does not pile up
  const open = formOpen();
  if (wasOpen && !open) pendingFrame = null;   // form was cancelled
  wasOpen = open;

  if (!open) update(dt);
  renderer.render(scene, camera);
});

Reading the clock every frame matters: if you skip getDelta() while paused, the first frame after the form closes gets one huge time step and physics objects tunnel through the floor.

Send renderer stats with the report

For a 3D game, “it got slow in the forest” is far more useful with numbers. Three.js already counts them in renderer.info, and reportBug takes a free-form metadata object:

function renderStats() {
  const info = renderer.info;
  return {
    three: THREE.REVISION,
    drawCalls: info.render.calls,
    triangles: info.render.triangles,
    geometries: info.memory.geometries,
    textures: info.memory.textures,
    programs: info.programs ? info.programs.length : 0,
    pixelRatio: renderer.getPixelRatio(),
    size: renderer.domElement.width + 'x' + renderer.domElement.height,
    camera: camera.position.toArray().map((n) => +n.toFixed(2)),
  };
}

Bugnet.reportBug('Frame rate drops in the forest', 'Around 20 fps near the river.', {
  category: 'performance',
  metadata: renderStats(),
});

A steadily climbing geometries or textures count across reports is the signature of a leak from undisposed resources. The render counters reset on every render call, so with several passes per frame, set renderer.info.autoReset = false and call renderer.info.reset() yourself once per frame to get whole-frame totals.

Keep the title fixed for a given problem and put the numbers in the metadata. Reports with exactly the same title are stacked onto one bug as extra occurrences, which is what you want for something like context loss:

renderer.domElement.addEventListener('webglcontextlost', () => {
  Bugnet.reportBug('WebGL context lost', 'The browser dropped the WebGL context.', {
    category: 'crash',
    priority: 'high',
    metadata: renderStats(),
  });
});

Context loss is not a JavaScript error, so no error handler ever sees it. To the player it is a frozen or black canvas. Reporting it explicitly is the only way to learn how often it happens and on which GPUs.

What the SDK captures on its own

With the default autoCaptureErrors: true, the SDK listens for the window error event and for unhandledrejection. Each distinct error is filed once per session as a critical report with the message, file and line, the stack, and the last 50 console lines, up to 20 automatic reports per session. That covers a thrown exception in your loop and a rejected promise from a failed model load. It does not cover context loss, as above, or problems that only log a warning. The differences between the two events, and what each one misses, are covered in window.onerror vs unhandledrejection: Catching Every JavaScript Error in an HTML5 Game.

react-three-fiber, Babylon.js and PlayCanvas

Everything above is WebGL behaviour, not Three.js behaviour, so it carries over.

In all three, the pointer lock and keyboard guards are identical, because they are plain DOM code.

Where the reports go

Each report lands in your Bugnet project with the screenshot or attached frame, the renderer stats, the GPU string, the browser and your game version. Identical titles stack with an occurrence count, so one shader bug hit by three hundred players is one item with a number next to it. You can sort by platform, get a Discord or Slack message for new reports, and publish a public tracker for players. The free plan covers one project and up to 100 bug reports, enough to see what a web release actually breaks on. The Web SDK docs list every option, and Bugnet for web games has the overview.

Frequently asked questions

Why is canvas.toDataURL blank or black in Three.js?

WebGL clears the drawing buffer after each frame is presented unless the context was created with preserveDrawingBuffer set to true. Reading the canvas later, for example from a click handler, returns the cleared buffer. Create the renderer with preserveDrawingBuffer: true, or call renderer.render and toDataURL back to back in the same task.

Does preserveDrawingBuffer hurt performance in Three.js?

It can. The browser has to keep the frame’s contents instead of discarding or swapping the buffer, which costs a copy on some GPUs and is most noticeable on mobile. Many desktop games will not measure a difference, so profile before deciding, and use render-then-capture if it matters.

How do I take a screenshot of a Three.js scene without preserveDrawingBuffer?

Render and read in one synchronous block: call renderer.render(scene, camera), then immediately call renderer.domElement.toDataURL. The buffer is still intact because the browser has not presented the frame yet. If you use an EffectComposer, call composer.render in place of renderer.render.

How do I stop WASD keys moving the camera while typing in a form over a Three.js game?

In your keydown handler, return early when the event target is an input, textarea, select or contenteditable element. Also release pointer lock with document.exitPointerLock before showing the form, since a locked pointer cannot click on it.

Does the same bug reporting setup work with Babylon.js and PlayCanvas?

Yes. Both draw to a WebGL canvas, so the Web SDK and the screenshot rules are the same. Babylon.js takes preserveDrawingBuffer in its engine options and PlayCanvas takes it in graphicsDeviceOptions or as a project rendering setting.

A WebGL screenshot is only valid in the same task that drew the frame. Either keep the buffer with preserveDrawingBuffer or render and capture back to back.