remove unneeded fetch

This commit is contained in:
Simon Knott 2024-10-15 15:04:46 +02:00
parent 6d0f0bed3f
commit e19f0ee735
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -305,23 +305,21 @@ function snapshotScript(screenshotURL: string | undefined, ...targetIds: (string
const canvases = root.querySelectorAll('canvas'); const canvases = root.querySelectorAll('canvas');
if (canvases.length > 0 && screenshotURL) { if (canvases.length > 0 && screenshotURL) {
fetch(screenshotURL).then(response => response.blob()).then(blob => { const img = new Image();
const img = new Image(); img.onload = () => {
img.onload = () => { for (const canvas of canvases) {
for (const canvas of canvases) { const context = canvas.getContext('2d')!;
const context = canvas.getContext('2d')!;
const boundingRect = canvas.getBoundingClientRect(); const boundingRect = canvas.getBoundingClientRect();
const xStart = boundingRect.left / window.innerWidth; const xStart = boundingRect.left / window.innerWidth;
const yStart = boundingRect.top / window.innerHeight; const yStart = boundingRect.top / window.innerHeight;
const xEnd = boundingRect.right / window.innerWidth; const xEnd = boundingRect.right / window.innerWidth;
const yEnd = boundingRect.bottom / window.innerHeight; const yEnd = boundingRect.bottom / window.innerHeight;
context.drawImage(img, xStart * img.width, yStart * img.height, (xEnd - xStart) * img.width, (yEnd - yStart) * img.height, 0, 0, canvas.width, canvas.height); context.drawImage(img, xStart * img.width, yStart * img.height, (xEnd - xStart) * img.width, (yEnd - yStart) * img.height, 0, 0, canvas.width, canvas.height);
} }
}; };
img.src = URL.createObjectURL(blob); img.src = screenshotURL;
});
} }
{ {