-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getTypeOf() Can't infer datatype in Firefox Addon context #759
Comments
The addon works as expected on chrome though. Which is ironic, since I'm developing primarily with firefox in mind |
This issue is easy to reproduce with a UserScript. Install Greasemonkey or Violentmonkey in Firefox. Then install this script: // ==UserScript==
// @name test
// @version 1
// @include https://github.com/*
// @grant none
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.js
// ==/UserScript==
(async () => {
const zip = new JSZip();
const blob = await zip.generateAsync({type:'blob'});
try {
zip.file('test.txt', new Blob(['']));
}
catch(error) {
console.error(error);
}
try {
await JSZip.loadAsync(blob);
}
catch(error) {
console.error(error);
}
})(); Adding blob to a zip throws Both can be fixed with either #578 or #598. But then loading zip from blob throws jszip/lib/reader/Uint8ArrayReader.js Line 18 in 053d8d5
And I'm not sure how to fix that. WORKAROUNDSince I don't know when it's going to be fixed and in my case those PRs don't solve my problem I'm using this workaround: const readAsBinaryString = blob => new Promise(resolve => {
const reader = new FileReader();
reader.onload = function(event) {
resolve(event.target.result);
};
reader.readAsBinaryString(blob);
});
(async () => {
const zip = new JSZip();
const blob = await zip.generateAsync({type:'blob'});
zip.file('test.txt', await readAsBinaryString(new Blob([''])), {binary: true});
await JSZip.loadAsync(await readAsBinaryString(blob));
})(); And now it works. Related issue greasemonkey/greasemonkey#3120 |
Faced the same problem in Firefox web extension content script. const encodedText = new TextEncoder().encode('some text'); // ok
const buffer = new Uint8Array(encodedText.buffer); // ok, but seems like some security flags for new object are missing
buffer.slice(); // Error: Permission denied to access property "constructor"
buffer.subarray(0, 2); // Error: Permission denied to access property "constructor" Creating new ArrayBufferView from existing ArrayBuffer in web extension content script leads to Error: Permission denied to access property "constructor" on any method call for new object. Created a bug report here: https://bugzilla.mozilla.org/show_bug.cgi?id=1868675 |
I'm trying to save a bunch of image blob (from canvas.toBlob) into a zip for an addon I'm working on.
But I keep getting the
Can’t read the data of […]. Is it in a supported JavaScript type
error.Here's the code block I'm using
In what seems like a repetition of #151 this is the error I get
Which leads me to exports.getTypeOf. I added some console logs to it, and this is the result
2 calls, seems legit, there are 2 images being zipped. (in all trials)
According to this stackoverflow comment it might be better to use
input.constructor.name
instead ofinstanceof
. I using that in the function blocks, but while that doesn't throw an error, I don't get the download prompt either (not the console.logs in the callback function)Multiple calls, each with a different type!?
I also tried some
console.log
s to checkout the return value, and the output is even more confusionOnly 1 call to the function (a Blob?)
The text was updated successfully, but these errors were encountered: