Javascript download pdf instead of open

I'm updated to v62.0.3, and have autoupdating enabled.

However, the last few updates (apparently) have reset something regarding PDF files.

Now, when I open one (such as Federal Communications Commission actions), the PDF.js viewer (standard with FF) doesn't load, even though "Preview..." is selected for PDFs in about:preferences; instead the file is downloaded.

I only use two extensions, Video DownloadHelper with its "co-app" and Bookmark Dupes. It doesn't appear that either of these were recently updated, and neither appears to be having any issues.

What else should I check that could have been amended as far as options or config?

dL

I'm updated to v62.0.3, and have autoupdating enabled. However, the last few updates (apparently) have reset something regarding PDF files. Now, when I open one (such as Federal Communications Commission actions), the PDF.js viewer (standard with FF) doesn't load, even though "Preview..." is selected for PDFs in about:preferences; instead the file is downloaded. I only use two extensions, Video DownloadHelper with its "co-app" and Bookmark Dupes. It doesn't appear that either of these were recently updated, and neither appears to be having any issues. What else should I check that could have been amended as far as options or config? dL

Chosen solution

Thanks for the link. The server sends the Content-Type application/octet-stream which indicates a generic kind of binary content. (Screenshot of Browser Console attached.) Firefox doesn't detect/treat that as a PDF (the content type application/pdf triggers that).

Read this answer in context 👍 0

All Replies (14)

this is not a firefox issue on the site off .js the html binds a script inside a html tag "hack", this is common and problematic as browsers have also addon functions so if ya open a pdf the extension can put in the todo api of firefox ,like a mailto: call would open your mail system, but in case a pdf is opened through the webserver html code the browser will execute the .js script sadly these are open source projjects on Git,and in Jquery as piece offf ducktape hackataons try to fool the browser by using html tags and execute scripts, that's why firefox is the first header sign called "Mozilla" as Netscape and Firefox don't run stuff behind your back, but it also opens the "true" reality that since 2015 W3C and browsers have no relation anymore, don't forget a pdf is an product from adobe and Oracle is the company, the conflict with Microsoft ,Google against Adobee is hyge, and by definition a violation off the open source community by stealing the product, like windows runs in .NET framework which is open source, a PDF generator as such can be included on the site you visit, but if the browser updates and the "hack" beccomes obsolete the site is the fault in this, as coder i wrote my own webserver and forked also pdf's inside the WEB but then the browser runs it inside the server,else it opens a new tab with the pdf , as user sadly but also needed to become back a standard and no hidden stuff , the browser is not an OS but the OS like windows runs a shell inside a browser so becomes the border where is the content and you, today 99/100 the external IP request isn't your public but a cloud internal so rendering becomes only visual the data stays on the peer and no data streams to your WAN but you re part off that system, press F12 and check the network tab, the header shows all the info that explains why this happens, rgds marc (coder-zero"

I assume you checked the PDF actions in "Options/Preferences -> General -> Applications".

Is the builtin PDF Viewer enabled?

  • https://support.mozilla.org/en-US/kb/view-pdf-files-Firefox

You can check the handlers.json file in the profile folder to see if there is an action specified. You can use the button on the "Help -> Troubleshooting Information" (about:support) page to go to the current Firefox profile folder or use the about:profiles page.

  • Help -> Troubleshooting Information -> Profile Directory:
    Windows: Show Folder; Linux: Open Directory; Mac: Show in Finder
  • http://kb.mozillazine.org/Profile_folder_-_Firefox

cor-el: I went to the preferences, and changed the entry for PDFs to "Use... Reader (default)", and it opened a link I selected in a separate Reader window (as it should) Then I changed it back to "Preview..." and selected another link from the same page, and it opened with the internal viewer. In handlers.json I then noticed "mimeTypes":{"application/pdf":{"action":3,"extensions":["pdf"]} What would the "3" mean, internal viewer or external Reader window?

vdbm2: Your response sailed waaaaaay over my head. I haven't coded in over 30 years.

dL

Modified October 11, 2018 at 8:01:01 AM PDT by Bob Jersey

Action 3 means that Firefox will handle internally.

  • saveToDisk = 0;
  • alwaysAsk = 1;
  • useHelperApp = 2;
  • handleInternally = 3;

Note that Firefox comes with a builtin JSON viewer that should kick in when you open handlers.json in a tab.

  • https://developer.mozilla.org/en/Tools/JSON_viewer

Dale_Latimer said

cor-el: I went to the preferences, and changed the entry for PDFs to "Use... Reader (default)", and it opened a link I selected in a separate Reader window (as it should) Then I changed it back to "Preview..." and selected another link from the same page, and it opened with the internal viewer.

Your instinct to turn it off and back on again is something that helped another user earlier this month. That is always worth a try before trashing handlers.json.

jscher2000 said

Your instinct to turn it off and back on again is something that helped another user earlier this month. That is always worth a try before trashing handlers.json.

It didn't help. The other day I changed the Downloads setting to 'always ask where to save'. Then today I opened another FCC file from the link in their daily digest. I got asked where to save the file.

Any other ideas, or am I stuck to have to clean out %USERPROFILE%\Downloads periodically b/c using Reader is, in fact, the default, and something else is unadjustably set to default?

dL

Modified October 11, 2018 at 8:14:19 PM PDT by Bob Jersey

Action = 4 would be to use the system default application. If the action for PDF is still set to 3 in handlers.json and to Preview in Firefox in Applications then this would suggest that the builtin PDF Viewer isn't working properly and Firefox tries to fallback to an external application.

The two links you just gave, worked appropriately, although downloading a fresh package of the pdf.js from https://mozilla.github.io/pdf.js/ may have helped...

jscher2000 said

I don't know why the FCC would do that unless it was the type of document that should be opened in a more sophisticated viewer (e.g., a fillable form). Can you give the link?

https://docs.fcc.gov/public/attachments/DOC-354486A1.pdf

I've also notified the applicable Commission staff of the issue.

dL

Modified October 12, 2018 at 10:32:00 AM PDT by Bob Jersey

Chosen Solution

Thanks for the link. The server sends the Content-Type application/octet-stream which indicates a generic kind of binary content. (Screenshot of Browser Console attached.) Firefox doesn't detect/treat that as a PDF (the content type application/pdf triggers that).

The interesting twist here is, MSIE displays it properly. (Chrome saves the file to disk.)

dL

Modified October 14, 2018 at 3:44:37 PM PDT by Bob Jersey

MSIE has a number of nonstandard behaviors. ;-)

Most importantly for current purposes, MSIE does some content sniffing and will override the Content-Type indicated by the server when it feels like doing so. I'm not aware that the algorithm is documented.

I can now close this. The FCC has remedied the issue, and PDF files there open in the viewer as expected. Thanks for all your help.

In case this comes up again, I created an extension that can help with this problem. I suggest leaving it off until you run into a problem, and only turning it on (using its toolbar button) while you are downloading files that need it. Otherwise, because it intercepts every response from every web server, it may slow down your browsing.

https://addons.mozilla.org/firefox/addon/content-type-fixer/

If anyone tries it, let me know how it goes.

How do I get a PDF to download instead of opening?

To Make Google Chrome Download PDF Files Instead of Opening On the right, go to the Content section, and click on Additional content settings. Click on PDF documents. On the next page, turn on (enable) the Download PDF files instead of automatically opening them in Chrome option. You are done.

How do I force my browser to download instead of open?

Click on "Settings" and you'll see a new page pop up in your Chrome browser window. Scroll down to Advanced Settings, click Downloads, and clear your Auto Open options. Next time you download an item, it will be saved instead of opened automatically.

How do I get HTML to automatically download PDF?

You can use with the file url passed as "f" querystring parameter. (/folder/download.

How can I download a PDF from a URL using Javascript?

download = 'file. pdf'; link. dispatchEvent(new MouseEvent('click')); } var fileURL = "link/to/pdf"; var fileName = "test. pdf"; download(fileURL,fileName);