-
-
Notifications
You must be signed in to change notification settings - Fork 296
Node Canvas Adapter
David Ortner edited this page Jun 2, 2026
·
1 revision
@happy-dom/node-canvas-adapter makes it possible to use node-canvas as a canvas adapter for Happy DOM.
npm install canvas @happy-dom/node-canvas-adapterimport { Window } from 'happy-dom';
import { CanvasAdapter } from '@happy-dom/node-canvas-adapter';
const window = new Window({
settings: {
canvasAdapter: new CanvasAdapter(),
// Optionally, enable image file loading (e.g. for <img> elements)
enableImageFileLoading: true
}
});
const canvas = window.document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.width = 200;
canvas.height = 200;
// Now you can use canvas context
context.fillStyle = 'red';
context.fillRect(0, 0, 100, 100);
// Get data URL
const dataUrl = canvas.toDataURL();
// Output the data URL
console.log(dataUrl);
Help Packages