You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some websites block image requests made from canvas, for example Wikipedia. From Googling around it may be due to missing or invalid headers, e.g. User-Agent. Is there a way to set them currently? If not, please consider setting sane default headers or allowing the user to specify them for individual requests.
Steps to Reproduce
constImage=require('canvas');asyncfunctiongetImage(src){returnnewPromise(resolve=>{constimg=newImage();img.onload=()=>resolve(img);img.onerror=err=>{console.log(err);resolve(null);};img.src=src;});}// will be null, and 403 error printed out to the consolevarimg=awaitgetImage("https://upload.wikimedia.org/wikipedia/commons/4/48/Daala_Rainbow_Vomit_Tiger.png");
Your Environment
Version of node-canvas (output of npm list canvas or yarn list canvas): canvas@2.9.3
Environment (e.g. node 4.2.0 on Mac OS X 10.8): node v14.17.3 on Windows 10
The text was updated successfully, but these errors were encountered:
Almost think that a http library and Image shouldn't be part of the canvas core anymore
Think we should have a createImageBitmap function instead.
the way you would do it instead would be to:
import{OffscreenCanvas,createImageBitmap}from'canvas'// using NodeJS v18 fetch, undici or node-fetch. or fetch-blob/from.js to get a blobconstblob=awaitfetch(url).then(res=>res.blob())constbitmap=awaitcreateImageBitmap(blob)// draw bitmap to a new offscreen canvas.constcanvas=newOffscreenCanvas(bitmap.width,bitmap.height)// ...
This way you can make any request you like, changing user agent, Method, credentials etc. also changing accept header to allow for any image/*
Issue or Feature
Some websites block image requests made from canvas, for example Wikipedia. From Googling around it may be due to missing or invalid headers, e.g. User-Agent. Is there a way to set them currently? If not, please consider setting sane default headers or allowing the user to specify them for individual requests.
Steps to Reproduce
Your Environment
npm list canvas
oryarn list canvas
): canvas@2.9.3The text was updated successfully, but these errors were encountered: