Skip to content

Commit e43a837

Browse files
committed
handle canvas.toBlob failure
1 parent cbc80cb commit e43a837

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

web_src/js/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ export function imageBlobToPng(blob) {
115115
canvas.height = img.naturalHeight;
116116
const context = canvas.getContext('2d');
117117
context.drawImage(img, 0, 0);
118-
canvas.toBlob(resolve, 'image/png');
118+
canvas.toBlob((blob) => {
119+
if (!(blob instanceof Blob)) return reject(new Error('imageBlobToPng failed'));
120+
resolve(blob);
121+
}, 'image/png');
119122
});
120123
img.addEventListener('error', () => {
121-
reject(new Error('Image conversion failed'));
124+
reject(new Error('imageBlobToPng failed'));
122125
});
123126
img.src = await blobToDataURI(blob);
124127
} catch (err) {

0 commit comments

Comments
 (0)