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.
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
-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.
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).
To add the built-in viewer as the application of choice in Firefox:
- Run Firefox profile chooser and create new profile
- 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
- Firefox - Settings/Preferences
- General > Applications > Portable Document Format (PDF) - Use other... - Select Helper Application (locate where the script was saved)
- General > Applications > Portable Document Format (PDF) - Always ask
- 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).
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.