-
-
Save jayantbh/059a25368ac9b8ecc3ad478e572db24a to your computer and use it in GitHub Desktop.
offscreen-canvas-polyfill.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!window.OffscreenCanvas) { | |
window.OffscreenCanvas = class OffscreenCanvas { | |
constructor(width, height) { | |
this.canvas = document.createElement('canvas'); | |
this.canvas.width = width; | |
this.canvas.height = height; | |
this.canvas.transferToImageBitmap = () => { | |
const ctx = this.canvas.getContext('2d'); | |
if (!ctx) return; | |
return ctx.getImageData(0, 0, this.canvas.width, this.canvas.height); | |
}; | |
this.canvas.convertToBlob = () => { | |
return new Promise((resolve) => { | |
this.canvas.toBlob(resolve); | |
}); | |
}; | |
return this.canvas; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment