🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@happy-dom/node-canvas-adapter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@happy-dom/node-canvas-adapter

Pluggable canvas adapter for happy-dom using node-canvas.

latest
Source
npmnpm
Version
20.10.6
Version published
Maintainers
1
Created
Source

Happy DOM Logo

Pluggable canvas adapter for Happy DOM using node-canvas.

Installation

npm install canvas @happy-dom/node-canvas-adapter

Documentation

You will find the documentation in the Happy DOM Wiki under Node Canvas Adapter.

Usage

import { 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);

Happy DOM

Documentation | Getting Started | Setup as Test Environment | GitHub

Keywords

canvas

FAQs

Package last updated on 17 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts