Error: Can't read the data of 'the loaded zip file'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ? jszip.js:3483:17
My goal was to get image files from a zip file (with
As a copy and paste into console, everything works fine.
As a content script of an extension, jszip gives the above error.
manifest.json
{
"author": "[email protected]",
"manifest_version": 2,
"name": "debug jszip",
"version": "1.0",
"description": "fetch-zip => jszip-open => fails",
"permissions": ["file:///*"],
"content_scripts": [
{"matches": ["file:///*"],
"js": ["jszip.js","debug.js"]
}
]
}
content script debug.js
async function fetchAsync (url) {
console.log('url:'+url)
let response = await fetch(url);
console.log('response status:'+response.status)
let ffile = await response.blob();
console.log('file object type:'+ffile.type)
let unzip = await JSZip.loadAsync(ffile) //it fails here!
console.log('unzip script:'+unzip.toString())
}
window.addEventListener("contextmenu", function(e){
if(e.ctrlKey && e.button ==2){
fetchAsync(e.target.href)
};
});
Some frustrating things I learned.
var dataType = "arraybuffer"; at jszip.js:3480 was my best attempt at happiness.I got it to work by changing
reader.readAsArrayBuffer(data);
to
reader.readAsBinaryString(data);
Where is your "reader"?