Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

HTML5 blocks PDF download, works only when preview is on

more options

I hate preview. Especially, when the final action is saving the PDF anyway, preview just gets in the way. But there is one banking site, that for "security reasons" blocks me from downloading the PDF except from the preview (and then the filename is just "document.pdf", instead of something with a date embedded in it). I do not want to have the preview at all, I consider it insecure. Is there some work-around for this?

Chosen solution

Yes, Ctrl+u shows the original before scripts made modifications. Their script assumes your browser has a PDF plugin, which Firefox discontinued three years ago with the release of Firefox 53.0, so you just get the dead embed tag.

At least you have a URL. If you run a snippet of code in the Web Console to put that into a link, does that let you download? You can open the Web Console in the lower part of the tab using either:

  • "3-bar" menu button > Web Developer > Web Console
  • (menu bar) Tools > Web Developer > Web Console
  • (Windows/Linux) Ctrl+Shift+k

This is the code to paste into the console (either a line at the bottom or the left panel) and either click the Run button (if present) or press Enter/Return to execute. The first time you do this, Firefox may ask you to take an action proving you understand it is difficult to run scripts from strangers -- which is true. After completing that action, you can try the script again:

// Find the embed; expect errors if there is no embed
var e = document.querySelector('embed');

// Create a link to the src of the embed with same content-type
var l = document.createElement('a');
l.href = e.src;
l.setAttribute('type', e.getAttribute('type'));

// Code the link for downloading with a usable name if possible
var p = location.pathname;
if (p.lastIndexOf('/') < p.length - 1){
  var n = p.slice(p.lastIndexOf('/') + 1);
} else {
  var n = 'unknown.pdf';
}
l.setAttribute('download', n);

// Assign link text and inject at top of document 
l.appendChild(document.createTextNode('Download ' + n));
l.setAttribute('style', 'position: fixed; z-index: 10000; min-height:1.5em; color: yellow; background: blue;');
document.body.insertBefore(l, document.body.firstChild);

Does that link work with the "blob" URL?

Read this answer in context 👍 1

All Replies (9)

more options

Hi antymat+firefox, a site has limited ability to override your preference for how to handle files sent with the "application/pdf" content type. They can force downloading (to bypass an internal viewer), but they can't prevent downloading if you have set that option.

Have you tried using the bank site with Firefox set to use an external viewer or Save File? (View PDF files in Firefox or choose another viewer) What happens?

If you still get a viewer, it's possible the bank site is using its own code for the preview instead of Firefox's built-in viewer. For example, Microsoft began doing that in Outlook Web App for PDF attachments (at least in Firefox). There aren't any Firefox settings to work around that.

Does Chromium work differently on the site? In Google Chrome, the PDF viewer can be detected as a plugin, while Firefox's not exposed as a plugin, so sites may behave differently for that reason (like Outlook Web App does).

Helpful?

more options

Hello,

To change the default reader for viewing PDF files in Firefox, follow these steps:

  1. Click the menu button New Fx Menu and click Options (Preferences for Linux or Mac).
  2. In the Options (or Preferences) tab, select the Applications panel.
  3. In the Search field, type PDF to find the Portable Document Format (PDF) entry.
  4. Use the drop-down menu for that entry under the Action column, to select your favorite PDF reader. To view PDF files in Firefox, choose Preview in Firefox.

For more information, see View PDF files in Firefox or choose another viewer.

Did this fix your problem? Please report back to us!

Thank you.

Helpful?

more options

@brisu - thanks, but this is exactly the opposite of what I want.

@jscher20 - The thing is - when the "preview in Firefox" is not selected, I see completely nothing. Empty page. There is some code in this page (can bee seen with Ctrl+u), but search shows no "PDF" anywhere there.

I've been told Chrome behaves differently - I tested with chromium, and it shows me a page with one button: "Open", when I click it, it opens a dialog to save the pdf.

How can I figure out, what is this page doing, that makes it virtually unusable for me? Or would it be less hassle just to change the bank? ;)

Attached are the screenshots of the PDF download page in Chromium and Firefox.

Helpful?

more options

Oh thanks, that's helpful. I suspect even though the address bar has .pdf, since Firefox didn't download it, it might actually be an HTML page with an embedded/framed PDF.

Could you right-click in the blank area and check for a This Frame entry on the context menu? If you have that, expand that sub-menu and try Save Frame As. Does Firefox understand that the framed page is a PDF or does it try to save as HTML?

Even if that works, it probably doesn't help with the file naming issue.

Helpful?

more options

@jscher2000 - It is not a frame. It looks (I'm guessing) more like some "clever" javascript going on a power trip. But there is something to the plugin story - when I try to open it in Konqueror, it says it cannot find the plugin.

How would you debug this? I mean - some one is apparently trying to do something non-standard, and the users be damned, but I would like to know, what is going on there. :)

Helpful?

more options

Hi antymat+firefox, if anything loading there in Firefox? If you open the Page Inspector tool using either

  • Ctrl+Shift+i, then click Inspector if needed
  • "3-bar" menu button > Web Developer > Page Inspector
  • (menu bar) Tools > Web Developer > Page Inspector

is there any HTML for the tab beyond an empty <body> tag?

Note: if you wanted to share HTML, you could use a site like Pastebin that won't destroy the tags (or Google Drive/OneDrive/Dropbox), but please remove any paths that look like they point to confidential documents.

Helpful?

more options

Hi jscher2000,

There actually is something in the <body> tag (i.e. between <body> and </body>; I've changed the UUID string ;), yeah, that's all there is, nothing between the </body> and the </html>): <embed src="blob:https://amazon.lbb.de/01234567-89ab-cdef-4567-0123456789ab" type="application/pdf" width="100%" height="100%"> This looks to me as a botched attempt to display a pdf...

Funnily enough, when inspected with Ctrl+u, I could not find a "pdf" string in the text... Why does the content in the inspector and in the page source differ? Do I assume correctly this to be the result of the javascript?

Helpful?

more options

Chosen Solution

Yes, Ctrl+u shows the original before scripts made modifications. Their script assumes your browser has a PDF plugin, which Firefox discontinued three years ago with the release of Firefox 53.0, so you just get the dead embed tag.

At least you have a URL. If you run a snippet of code in the Web Console to put that into a link, does that let you download? You can open the Web Console in the lower part of the tab using either:

  • "3-bar" menu button > Web Developer > Web Console
  • (menu bar) Tools > Web Developer > Web Console
  • (Windows/Linux) Ctrl+Shift+k

This is the code to paste into the console (either a line at the bottom or the left panel) and either click the Run button (if present) or press Enter/Return to execute. The first time you do this, Firefox may ask you to take an action proving you understand it is difficult to run scripts from strangers -- which is true. After completing that action, you can try the script again:

// Find the embed; expect errors if there is no embed
var e = document.querySelector('embed');

// Create a link to the src of the embed with same content-type
var l = document.createElement('a');
l.href = e.src;
l.setAttribute('type', e.getAttribute('type'));

// Code the link for downloading with a usable name if possible
var p = location.pathname;
if (p.lastIndexOf('/') < p.length - 1){
  var n = p.slice(p.lastIndexOf('/') + 1);
} else {
  var n = 'unknown.pdf';
}
l.setAttribute('download', n);

// Assign link text and inject at top of document 
l.appendChild(document.createTextNode('Download ' + n));
l.setAttribute('style', 'position: fixed; z-index: 10000; min-height:1.5em; color: yellow; background: blue;');
document.body.insertBefore(l, document.body.firstChild);

Does that link work with the "blob" URL?

Helpful?

more options

Hi jscher2000,

Sorry to reply so late.

This worked! Thanks!

So - basically - they just didn't care to code this properly? And then force users to do their job for them and enable preview?

Anyway - thanks again; I will try to make it a bit more convenient, even if only putting it in the tampermonkey ;).

Helpful?

Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.