[Bug] Impossible to download the file
Describe the bug
With some web sites downloading file does not work.
For instance with the CAF's site: https://www.caf.fr/, there is not error message but the expected PDF file is never downloaded.
There is the same issue trying to download the vaccination certificate from the state website: https://attestation-vaccin.ameli.fr/
How to Reproduce
- Go to: https://www.caf.fr/ and connect yourself to your account
- Select the link to download your last attestation (in french in the text: “Télécharger ma dernière attestation“)
- Rapidly, 2 intermediate white pages are shown with only: a. first: the mention telling that loading is ongoing (in french in the text: “Chargement en cours… “) b. last: the link suggesting to click on the link if the document is not shown (in french in the text: ”Cliquer ici si le document ne s’affiche pas”)
Finally no document has been saved neither in the DDG's Downloads section, nor in the Android's file system.

Expected behavior
After both intermediate white pages have been shown, the PDF file should be available from the DDG's Downloads section.
By using another Web browser as Google Chrome, both intermediate Web pages are displayed too but then the PDF file is well saved and can be opened.
Environment
- DDG App Version: 5.144.0
- Device: Galaxy S10+ / Samsung SM-G975F/DS
- OS: Android 11
Hello. After a first code analysis, it appears that the url to download the file is blob: based. The problem causing the file not to be downloaded could be due to the intermediate blank pages being loaded after the user touched the link to download.
The convertBlobIntoDataUriAndDownload function from BlobConverterInjector.kt is well called allowing the injected Javascript code to be executed.
However the convertBlobToDataUri function from BlobConverterJavascriptInterface.kt is never called.
Furthermore the following error message is displayed in Logcat:
[INFO:CONSOLE(21)] "Uncaught (in promise) ReferenceError: BlobConverter is not defined", source: about:blank (21)
This could be due to the fact that loading another Web page during the download process is causing the BlobConverter interface to be undefined too early.
Can you give me a hint to help me fix this issue? Thanks
@anikiki could take a look at this issue and see if this is a known thing?
Similar to my comment in https://github.com/duckduckgo/Android/issues/2598, we need a site where we can try to reproduce the issue. If the site requires an account or valid credentials, sadly that's not something we can use for testing.
So far I have reproduced this problem only with sites which require a valid credentials.
Unfortunately theses sites are currently used in French.
@anikiki Good news. I found a testing URL where the problem can be reproduced without authentication.
The test page can be found here: https://codepen.io/keff/pen/ExPVjWz Just touch the button: "Save Test File"
It become from the article: https://dev.to/nombrekeff/download-file-from-blob-21ho
I don't know if it's the same issue that for the caf.fr site exactly, but it's due to blob file.
Let me know if I can help in any way
@bonninf Thanks for providing us with an easy to reproduce example.
When I tried to save the file you mentioned I noticed this in the console, coming from the webview:
chromium com.duckduckgo.mobile.android.debug I [INFO:CONSOLE(1)] "Not allowed to load local resource: blob:https://cdpn.io/25236f71-bb63-4ac8-b239-2f11fc3b668d", source: https://cpwebassets.codepen.io/assets/packs/js/vendor-9f2837b2439764b0665a.chunk.js (1)
The way this specific blob download is handled should be similar to this other URL, which works: https://eligrey.com/demos/FileSaver.js. If you want to check, just tap the "Save" button for one of the file types.
If you'd like to dig into it, have a look at the below files / lines: https://github.com/duckduckgo/Android/blob/develop/app/src/main/java/com/duckduckgo/app/browser/downloader/BlobConverterInjector.kt#L54 https://github.com/duckduckgo/Android/blob/develop/app/src/main/java/com/duckduckgo/app/browser/downloader/BlobConverterInjector.kt#L68 https://github.com/duckduckgo/Android/blob/develop/app/src/main/res/raw/blob_converter.js
@anikiki thanks for your response and apologize about the delay of mine
When trying to download the file from the testing URL https://codepen.io/keff/pen/ExPVjWz, I also see the error message "Not allowed to load..."
However when trying to download from the "caf.fr" site, I don't notice this error. The only error I see is this:
2023-01-27 16:33:17.297 27186-27186 chromium com.duckduckgo.mobile.android.debug I [INFO:CONSOLE(32)] "Uncaught ReferenceError: BlobConverter is not defined", source: about:blank (32)
I assume it's due to the fact the site is opening a new blank page which is in charge to download the blob file whereas the DDG app is injecting the 'blob-converter' js code in the previous page. So that when the injected js code is executed then the BlobConverter interface is no longer defined.
If that can help I attached a text file with the log from the console. CAF_Download_Error.txt
Hi @anikiki , @cmonfortep , I identified this repository which provides a webview-based browser too: https://github.com/hazuki0x0/YuzuBrowser
With the Yuzu browser downloading file from the caf.fr site is working fine. It could be due to the fact the Yuzu browser is using the DOM content loaded event to know when to inject the blob-converter js code into the webview.
I think a good entry point in the source code is the onDomContentLoaded function in WebClient.kt
What do you think about that?
If you need I could temporarily provide you my caf.fr's credentials such as you can reproduce the issue.
Hi @anikiki , @cmonfortep , I've been able to fix the issue. Could you consider to integrate the pull request into DuckDuckGo? Thanks by advance