I am trying to pass a Blob from a chrome extension to a javascript web application using the Chrome Message API. Inspired by a former Thread I want to convert the blob to text in order to send the content and filetype as an object via the messaging API to the website and eventually reassemble the Blob.
When executing the following snippet of code, however, I'm unable to reassemble the Blob. Basically the URL.createOjectURL() method should return valid blob:-URLs for both, blob and new_blob. While working on both objects, the new_blob URL results in a corrupted image (grey square) while the URL for blob shows the correct image. (On the receiving end the same problem occurs, of course).
fetch(request.url)
.then(r => r.blob())
.then(blob => {
var filetype = blob.type
blob.text().then(text => {
var message = {
blob: text,
url: request.url,
filetype: filetype
}
var new_blob = new Blob([message.blob], {type: message.filetype})
console.log(URL.createObjectURL(blob))
console.log(URL.createObjectURL(new_blob))
...
sendResponse(message)
})
})