diff --git a/src/core/__tests__/cache-storage.ts b/src/core/__tests__/cache-storage.ts index 7ea4dce..7844fa0 100644 --- a/src/core/__tests__/cache-storage.ts +++ b/src/core/__tests__/cache-storage.ts @@ -270,4 +270,14 @@ describe('cache-storage', () => { fail('Expected result to timeout'); } 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); + }); }); diff --git a/src/core/cache-storage.ts b/src/core/cache-storage.ts index 2be98ed..d935330 100644 --- a/src/core/cache-storage.ts +++ b/src/core/cache-storage.ts @@ -98,7 +98,9 @@ export class Cache { img.crossOrigin = 'anonymous'; } 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 setTimeout(() => resolve(img), 500); }