mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Handle inlined images correctly
This commit is contained in:
parent
fe86d602e9
commit
af62018424
@ -270,4 +270,14 @@ describe('cache-storage', () => {
|
|||||||
fail('Expected result to timeout');
|
fail('Expected result to timeout');
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('addImage should add an inlined image', async () => {
|
||||||
|
const {cache} = createMockContext('http://example.com', {imageTimeout: 10});
|
||||||
|
const inlinedImg = `data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
|
||||||
|
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
|
||||||
|
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7`;
|
||||||
|
cache.addImage(inlinedImg);
|
||||||
|
|
||||||
|
await cache.match(inlinedImg);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -98,7 +98,9 @@ export class Cache {
|
|||||||
img.crossOrigin = 'anonymous';
|
img.crossOrigin = 'anonymous';
|
||||||
}
|
}
|
||||||
img.src = src;
|
img.src = src;
|
||||||
if (img.complete === true) {
|
if (/^data:/.test(src)) {
|
||||||
|
resolve(img);
|
||||||
|
} else if (img.complete === true) {
|
||||||
// Inline XML images may fail to parse, throwing an Error later on
|
// Inline XML images may fail to parse, throwing an Error later on
|
||||||
setTimeout(() => resolve(img), 500);
|
setTimeout(() => resolve(img), 500);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user