How can I get Firefox to give me a prompt, -- either natively, or through a plug-in, -- which will ask me:

  • if I want to preview the PDF in the browser using pdfjs, or
  • if I want to open the PDF in external application, or
  • if I want to save the PDF as file?

This is my current behavior, Firefox 36, Ubuntu 11.04, running in --safe-mode, and with the default profile; first I look up a PDF to open


(Note: Google, when used with JavaScript, will rewrite each and every link upon mouse click, resulting with a stupid blank page when opening a PDF)

Upon click on a PDF link I get this prompt:


Notably, I can either choose an external application (also via Other), or to save the file - but there is no option to preview in browser (implying use of pdfjs).

The Edit/Preferences/Applications looks like this:


... and about:config settings related to pdf look like this (for some reason, taking a screenshot in Gnome 2 always seems to want to close the menubar, resulting with the crooked image below):


What can I do to have all three options presented as choices when I click on a PDF link?

  • 1
    If you want to preview a PDF using Firefox built-in PDF viewer set PDF as the default application to handle PDF files. You can then still use Other to your typical PDF viewer. – Ramhound Mar 2 '15 at 14:42
  • Thanks @Ramhound - but if Firefox built-in PDF viewer is set as default application, then I get no prompt whatsoever; the PDF just opens directly in Firefox when I click on it, without asking me anything in a prompt first? And what I want is to be prompted about it... – sdaau Mar 2 '15 at 14:44
  • 1
    So pick Other and then select Firefox. – Ramhound Mar 2 '15 at 14:46
  • Thanks, @Ramhound - I'll give that a try; but wouldn't that open Firefox in a new instance? I'd like the PDF opened as preview in the same instance, when I choose to do so ... EDIT: just tried it, opens in new instance (even asks for a profile choice at start with --safe-mode) - this is bound to get recursive without ever opening the PDF. – sdaau Mar 2 '15 at 14:47
  • 1
    @clearkimura I tried that app and it doesn't work as expected for me as well. – phipsgabler Nov 29 '18 at 12:20

This can be either a workaround or an answer, based on the original post asked by @sdaau and the attention brought by @phg. This is a practical solution anyway.

Direct answers

What can I do to have all three options presented as choices when I click on a PDF link? - sdaau asked Mar 2 '15 at 14:39

No, that is not possible. Firefox Addon may provide such interface but with newer addons using WebExtensions API, any direct modification to Firefox is not possible. Therefore the solution I have written here, with respect to OP, is a workaround.

I really want this, too. It's now three years and 30 versions later, has nobody come up with a solution yet? – phg Nov 28 at 10:27

Yes, that actually exist from before. Except nobody really wrote the solution until now; neither the help article for Firefox nor related SE sites had any-relevant-post with the solution yet.

Firefox limitation 1: The built-in viewer PDF.js is not an application by itself, and that makes impossible to set that as helper application within Firefox. Therefore "Preview in Firefox" can not be selected from "Open with" in the save dialog.

Hence the practical solution is to make the current profile of Firefox call another instance of Firefox that uses a separate profile that has been set to "Preview in Firefox" by default.

How it works

To understand the solution, user ought to know that:

  • User can change what Firefox does when you click on or download a file, as noted by this help article on Firefox Help
  • Firefox can run multiple instances by creating separate user profiles, as noted by this article on MozillaZine Knowledge Base
  • Script can be used to run an application, often with command line arguments, on Windows, macOS, and Linux, as noted by respective posts on SU
  • Any program, including Firefox, will most likely provide the full path to open the content, which must be parsed via command line argument (invisible to users, apparent to programmers)

Whenever the user open a link that has the content type, such as PDF, user will see the save dialog, then select other application from "Open with" and that is all.

In practice however, user may fail to choose from "Open with" because the application of choice is not listed there. Some setup is actually required, hence the missing step.

Missing step: User will have to add the application of choice. Typical help articles might not help, especially if the application of choice is a custom application or something built-in within an application like the built-in viewer of Firefox.

How to setup

To actually add the application of choice, in this case the built-in viewer of Firefox, user must do all the following beforehand:

  • Create a new user profile in Firefox, and
  • Create a script to run Firefox using the new user profile, and
  • Add the script to the settings under Applications in Firefox.

First, create a new user profile named pdfjs (any name of choice). Then create a Bash script (Linux) with only two lines as follows.

firefox -P "pdfjs" --no-remote $1

Where by:

  • -P "pdfjs" is to specify the separate user profile
  • --no-remote option to allow multiple instances of Firefox with different profiles
  • $1 is the first argument in Bash, which likely has the full path to open the content

Firefox limitation 2: Firefox can not run multiple instances of same profile. User can open new tab or window from Firefox itself, but can not do the same via command line. This limitation does not apply to the default profile that run Firefox command without any option.

The script is saved at /usr/local/bin/pdfjs (similar name with user profile, my naming choice) and the script must be marked as executable.

  • If not marked as executable, Firefox will not recognize the script as a helper application.
  • Firefox will recognize Linux shortcut '.desktop' that is made executable, but does not work.
  • Instead of a shortcut, use a script.

The following screenshot combo shows to select "Use other..." (top left) and locate the script in settings of Firefox and then change the action.

Firefox - Select helper application

If the script was successfully added, user can see the script name being listed in the "Action" column and also "Application details" (right). Finally, change the action again to "Always ask" (bottom left).

Setup summary

To add the built-in viewer as the application of choice in Firefox:

  1. Run Firefox profile chooser and create new profile
  2. Run a text editor and create a script to run Firefox using the new profile with option and command line argument (file content as above), then mark as executable
  3. Firefox - Settings/Preferences
  4. General > Applications > Portable Document Format (PDF) - Use other... - Select Helper Application (locate where the script was saved)
  5. General > Applications > Portable Document Format (PDF) - Always ask
  6. Close to finish

All relevant steps 3 until 6 are done in Firefox with default profile.

The steps 4 and 5 are done in succession to simplify the setup. These steps seem contradictory, but both indeed have own purpose each.

  • Step 4 is to add the application of choice and make available in "Open with".
  • Step 5 is to show the save dialog, so that user can select "Open with" and see the application of choice that was made available. This does not remove the added choice in step 4.
  • What seem contradictory here is related to Firefox limitation 1 explained earlier.

Other details have been explained under "How to setup".

How to use

Same as usual: Run Firefox and open a link with the content type. The save dialog will appear, then select "Open with" and select the application of choice. Click OK to run the choice.

The following screenshot combo shows Firefox with separate profile uses Dark theme (bottom) to distinguish from Firefox with default profile (top).

Firefox - Open with helper application

Limitation review: This solution allows to open PDF in Firefox with separate profile only one at a time. If the user want to open more than one, just drag and drop the link to PDF from Firefox (default profile) to the tab bar of another Firefox (separate profile) to open another PDF in a new tab.

Tested working with Firefox 63.0 and Bash script on Linux. Any release since Firefox 3.0 (three-point-zero) will do, except not tested with other scripts on Windows and macOS.

TL;DR The solution exists from before, but nobody wrote about that. Just add the application of choice. Tedious setup due to Firefox limitation. Native way is more practical than using addons.

  • 1
    This is an excellent diagnose of what's happening, and your solution is probably as good as it gets. While I won' use it, since it kind of defeats the purpuse of having a PDF open in the same tab, it answers the question. – phipsgabler Dec 5 '18 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.