I am downloading a file (in JavaScript), decrypting it with a library, and then I am creating a blob URL. This happens as a result of a user interaction where a user clicks a link. So I am not trying to fool anyone. To download the file after it has been decrypted, I am using the following code:
var a = document.createElement('a');
a.href = 'blob:foo';
a.target = '_blank';
a.download = 'foo.jpg';
a.click();
However, this is not always successful.
When is it always successful?
- When the user does not use an ad blocker.
When is it not successful?
- If the user uses an ad blocker that blocks blob URLs (e.g. Adblock Plus through EasyList), and does not support the download attribute.
So I want to show an alert to the user if the download is not successful. Is there any way to detect that?
My current idea is to:
- Detect if there's an ad blocker
- Check if the download attribute is supported (!window.externalHost && 'download' in createElement('a'))
- Notify the user of potential problems