-
Notifications
You must be signed in to change notification settings - Fork 23
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
[BUG] Firefox downloads ends up being corrupt most of the time #46
Comments
Hi there. Looks like the download stream was interrupted before all the file data could be written, and before any central repository information was written too. You don't happen to see anything interesting in the ServiceWorker's console ? Quick question : was at least one tab open with your website during the whole download ? I hear that ServiceWorkers may be shut down rather quickly by some browsers once all their client windows are closed. I haven't tried to reproduce yet. But I can already offer a suggestion for the ServiceWorker. You're going to a lot of trouble (and copying lots of data) just to rename the files in the archive, cloning the |
Thanks for the reply. I don't get any logs in the service worker in Firefox, I tried to log the filename and it shows up like this (one error that is expected): I removed the I'm quite new to the whole yield thing, but I will try that out. Thanks for the tip. |
I see. Yeah, your headers are a bit overcomplicated alright. Anyway, the point wasn't to remove your filename logic.
Your implementation clones the original Response body to make a new Response with a different Content-Disposition header, just so you can change the eventual filename in the archive. It's pretty inefficient. client-zip infers the filename from Content-Disposition when you give it a Response, but if you give it an object with a So the result would be something like this (I just changed the end of the function, but you may want to rename it since it doesn't actually replace headers anymore) : function replaceHeader(response, productName) {
const header = response.headers.get('Content-Disposition')
productName = productName.replace(
/[^\x00-\x7f]|[#|%|&|{|}|\\|\/|<|>|\*|\?|\$|!|'|"|:|@|\+|`|=]/g,
'',
)
const parts = header.split(';')
let fileName =
productName +
'/' +
parts[1]
.split('=')[1]
.replace(/[^\x00-\x7f]|[#|%|&|{|}|\\|\/|<|>|\*|\?|\$|!|'|"|:|@|\+|`|=]/g, '')
try {
decodeURIComponent(fileName)
} catch (ex) {
fileName = 'unknown_filename'
}
return { name: fileName, input: response }
} |
Thanks! Much cleaner. However, doing this did not resolve the firefox bug that we have. Doing it in browser works fine though (until we hit about 400MB of downloads, then it sometimes breaks). |
Would you mind adding a link to your website so I can try to reproduce ? |
It seems this issue is occurring on my machine as well. I have a > 1.0 GB download and it works on Chromium, but FIrefox interrupts around 80 MiB, in less than 10 seconds. Firefox always says the download is complete without showing any errors. Dev tools show that the ServiceWorker stops at the same time. I never had issues before I tested with a ServiceWorker. (I might be able to privately send a test link later if my employer agrees to it. I don't have a nice way to test this with public domain data at the moment) |
Hello, sorry for my late reply. I will try to think of a way to do this without affecting our users. |
Sorry, not my intention closing this. 😴 |
I hope the worker dies for some reason that we can fix, but without any error, I can't imagine what goes wrong. |
My experience with ServiceWorkers is limited to using client-zip, so my idea might not be perfect but.. |
There's nothing in the ServiceWorker specs about honouring keepalive headers, and anyway, the worker should be sending response data continuously to the client window when the download is started. Also, he problem here is not simply that the worker breaks the response, but that the worker itself is killed. Sending it a request after it's been killed will result in the request going straight to the network. |
By keep-alive I actually just meant this:
With this, I've been able to complete downloads on Firefox, and the ServiceWorker keeps running. |
Ah, keeping the worker alive. I am disappointed that Firefox needs such a thing to keep the worker alive. Well, whatever works… BTW, did you know you can pass function arguments to setInterval after the first two ? like this : setInterval(fetch, 4000, 'downloadZip/keep-alive', { method: 'POST' }) |
Thanks, we'll try this out. |
As a user of Firefox (on both desktop and Android) I'm quite often disappointed too. Still no IndexedDB or ServiceWorkers in Firefox private browsing mode, and there are other issues that take a long time to get fixed. I've seen that way of calling |
I'm closing this since it's a browser bug and we've got a workaround. I'm also going to add link in the README. Most developers need to know about this if they use the Service Worker to download. Some users are bound to use Firefox. |
Describe the bug
We've been using
client-zip
on our platform , we decided to not go for the streaming alternative initially since we wanted to support Safari as well. That is now fixed in recent Safari version, so we decided to use streaming instead.To Reproduce
Unable to give reproduction steps unfortunately. As our website only support this for Chrome, Safari and Edge right now. But you can try out working version by using Chrome, Safari or Edge on bimobject.com (you have to register) and click download and making sure you select multiple files.
Expected behavior
Same as Chrome, Safari and Edge.
Screenshots
Archive downloaded through Firefox gets corrupt (most of the time)
Desktop (please complete the following information):
Additional context
The user can select files from a list that they want to download. It always works in Chrome, Safari and Edge. But in Firefox, the ZIP sometimes ends up complete (~10% of cases).
I ran zipdump
python3 zipdump.py ~/Downloads/firefoxdownload.zip
and it lists only some of the files
Same set of files on a chrome download
When trying to open the file on Ubuntu, it simply says: An error occurred loading the archive.
My service worker looks like this:
and it's triggered with this Angular code
The text was updated successfully, but these errors were encountered: