Automattic/node-canvas

`Image#src=` does not work with object URL (`onload` never called, cannot be drawn on 2d context)

Open

#2 525 ouverte le 16 juil. 2025

Voir sur GitHub
 (2 commentaires) (1 réaction) (0 assignés)JavaScript (9 524 stars) (1 140 forks)batch import
Good first issue

Description

import { Image } from 'canvas';
import { readFileSync } from 'fs';

const file = readFileSync('test.png');
const objectUrl = URL.createObjectURL(new Blob([file], { type: 'image/png' }));
const image = new Image();
image.onload = () => {
	URL.revokeObjectURL(objectUrl);
	console.log('in onload: complete =', image.complete); // never called
};
image.src = objectUrl;
console.log('immediately after setting src: complete =', image.complete); // true

If you try to draw an image with src being an object URL on a 2d context, you get Error: Image given has not completed loading.

Environment:

  • Node.js 22.14.0
  • canvas 3.1.2

Guide contributeur