How to store response in indexed db during a fetch event
When objects are stored in Indexed DB they are serialized, which is basically the first half of what used to be called the "structured clone" algorithm, described here: https://html.spec.whatwg.org/multipage/structured-data.html#safe-passing-of-structured-data
The error is telling you that a Response
object can't be cloned (serialized/deserialized) - you can also get that error with this code:
window.postMessage(new Response)
... which means that Response
objects don't support serialization. To postMessage()
or store a Response
in IndexedDB you'll need to extract the properties you want to serialize into an object that can be serialized. e.g. a plain JS object holding the headers and response body as a Blob