-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
PDFs are downloaded (creating duplicates) rather than opening in the browser inline #763
Comments
@cjohnsto-nz In Kiwix JS we simply use the standard file download API, or else use the code for downloading files that is defined in the ZIM. As you know from kiwix/kiwix-js-pwa#194, it's a bit more complicated there because we have to use UWP APIs and we could (potentially) use the File System Access API in the PWA version (currently that is no different than it is in the Extension). I think that without using the File System Access API, we can't change the filename here in Kiwix JS. The API is unfortunately not supported by Firefox (it does work in Chrome and Edge). Supporting it is something we're considering -- see #656. |
I think I understand, but I am still a bit confused. If the mime type gets picked up correctly as a PDF (or any other file type the browser can open inline) for displayFileDownloadAlert(), could you handle the file differently. I'm trying to piece together where you would add the Content-Disposition: inline; header, in order to open PDFs natively in the browser. This would avoid "downloading" them altogether, and the browser would handle the storage of the file in a temp directory. |
OK, here I have to explain that the Chromium (Edge/Chrome) browser extension (and the UWP/PWA versions) operate in two modes: The frist mode is the one you're currently using, called "jQuery" mode. This mode manipulates the DOM, and in this particular case it intervenes when a user clicks on a downloadable file type (PDF/EPUB), and adds some code to make it possible for the extension to trigger a download. However we can't change Response headers in this mode. We just tell the browser it is downloading a non-HTML file and let it do the rest. This mode is feature frozen in Kiwix JS, and only being bugfixed. The second mode uses a Service Worker. In this case, the app simply executes whatever download code is defined in the ZIM, and doesn't intervene at all. It would be possible in theory to do what you ask in SW mode (see Expert Settings in Config) by changing the Response header to add the Content-Disposition header (the code would need to be added in It would be possible for you to ask for this functionality to be supported in the ZIM's source code (I can tell you where to ask for that, or move this issue, if you tell me which ZIM you are using). But I don't think implementing this in the app would be supported here in Kiwix JS. In Kiwix JS PWA/Electron/Windows, I am forced to intervene (in both modes) because I have to use UWP APIs, Electron APIs, etc., so there is more scope for customization there than in the browser extensions here. |
Gotcha. I'm not particularly familiar with the ZIM format. Would it be possible to add response headers, or something that would achieve the desired results, through post processing of the ZIM? I'm generating the ZIM, and would happily customize it to make it more convenient for our users, especially if it can be automated. You are an absolute legend by the way :) |
Mate, it opens inline natively in service worker mode. I didn't even think to try. |
That's good to know! But I imagine it still creates duplicate version, right? |
I don't think so. I used voidtools Everything just to monitor the filesystem while I accessed the file. It looks like, if the browser opens inline, it creates a .tmp file in C:\Users*\AppData\Local\Temp, and destroys it when the Window is closed. Perfect for my usecase. |
Tested on Edge. When opening an attached PDF, it downloads a copy (1), (2), etc. The wiki I am accessing contains large technical documentation that users will be opening many times a day. These duplicates will quickly fill the entire computer.
Would it be possible to have the browser extensions attempt to open PDF files inline.
https://stackoverflow.com/questions/6293893/how-do-i-force-files-to-open-in-the-browser-instead-of-downloading-pdf
The text was updated successfully, but these errors were encountered: