Mozilla サポートの検索

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.

詳しく学ぶ

このスレッドはアーカイブに保管されました。 必要であれば新たに質問してください。

Setting to automatically 'Save File' for PDFs is stored in handlers.json instead of prefs.js

  • 4 件の返信
  • 2 人がこの問題に困っています
  • 2 回表示
  • 最後の返信者: ccraig

more options

I have tried to set various prefs.js values to tell a clean install of Firefox 57.0.3 to automatically handle applications with .pdf by "Save File".

After some digging, I found that changing the setting Menu>Options>Applications- Content Type|"Portable Document Format (PDF)" Action|"Save FIle" only makes a difference in the profile found in %APPDATA%/Roaming/Mozilla/Firefox/Profiles/abcdef12.default by changing the some values in "handlers.json". I expected the change to be stored in "prefs.js".

The value in question is:

{"defaultHandlersVersion":{"en-US":4},"mimeTypes":{"application/pdf":{"action":2,"extensions":["pdf"],"ask":true}}}

{"defaultHandlersVersion":{"en-US":4},"mimeTypes":{"application/pdf":{"action":0,"extensions":["pdf"],"ask":false}}}

Is there a way to store this change in the handlers.json file in prefs.js?

A few like: browser.helperApps.alwaysAsk.force = false browser.helperApps.neverAsk.saveToDisk = application/pdf

seem to be important, but they don't do it. I have set several other preferences such as the download directory and the setting to use it. I have tried dozens of others, but after recording the profile and changing just that setting, then getting the difference in the profile I found that prefs.js is not changed at all so I gave up looking.

I have tried to set various prefs.js values to tell a clean install of Firefox 57.0.3 to automatically handle applications with .pdf by "Save File". After some digging, I found that changing the setting Menu>Options>Applications- Content Type|"Portable Document Format (PDF)" Action|"Save FIle" only makes a difference in the profile found in %APPDATA%/Roaming/Mozilla/Firefox/Profiles/abcdef12.default by changing the some values in "handlers.json". I expected the change to be stored in "prefs.js". The value in question is: {"defaultHandlersVersion":{"en-US":4},"mimeTypes":{"application/pdf":{"action":2,"extensions":["pdf"],"ask":true}}} {"defaultHandlersVersion":{"en-US":4},"mimeTypes":{"application/pdf":{"action":0,"extensions":["pdf"],"ask":false}}} Is there a way to store this change in the handlers.json file in prefs.js? A few like: browser.helperApps.alwaysAsk.force = false browser.helperApps.neverAsk.saveToDisk = application/pdf seem to be important, but they don't do it. I have set several other preferences such as the download directory and the setting to use it. I have tried dozens of others, but after recording the profile and changing just that setting, then getting the difference in the profile I found that prefs.js is not changed at all so I gave up looking.

この投稿は ccraig により に変更されました

選ばれた解決策

Firefox would only download PDF files automatically when the builtin PDF Viewer is disabled or the file is send with a content type other than application/pdf. JSON is data stored in a specific object notation format. JavaScript is code that can be run like a program. In case of prefs.js this file is actually parsed and only user_pref lines are allowed to set pref in the three valid data types (Boolean, Number/Integer, String). A String pref can have its content set to JSON data, see for instance browser.uiCustomization.state that stores the toolbar customization. But like I wrote, prefs.js is not meant and suitable to store a large amount of data and is only updated when you close Firefox.

この回答をすべて読む 👍 1

すべての返信 (4)

more options

handlers.json and previously mimeTypes.rdf have always stored file actions you may see under Applications. You can't store such settings in prefs.js, so it's no use to try this. The prefs.js file is used to store Firefox and extensions settings, but not to store data like file actions. You can see prefs.js as a JavaScript file and such a file isn't suitable for storing a large amount of data.

You can check out the comments in this file:

more options

Hmm, I'm not an expert on my Firefox history but I'm fairly certain this isn't true and at the very least it's not reasonably stated.

First of all, before Firefox 48 I know that without touching handlers.json I was able to set the default action for opening a .pdf file, such that any pdf would automatically download to my downloads folder without asking the first time. I'm 99% certain that it was a setting stored in prefs.js. I'm also pretty sure that the 2 preferences I listed in the original question are all that need to be set for Firefox to understand what I want to happen when I click a link that contains something tagged with "content-type" "application/pdf".

browser.helperApps.alwaysAsk.force = false - Don't always ask what to do with files

browser.helperApps.neverAsk.saveToDisk = application/pdf - If the content-type is application/pdf then never ask me what to do and just use save to disk.

So we've told Firefox it doesn't need to always launch the helper app that pops up when you click a download, and if it's a pdf, don't ask and save it to disk. Why would Firefox still be asking? Well, it seems like the handler has one more thing. It has settings for something with a mimeType application/pdf. The setting that seems to be needed is the "action:0". There is already a preference "pdfjs.previousHandler.preferredAction" and it takes an integer value (seems like 0-4). So telling me there can't be another "defaultHandler.pdf.action" that can be set to 0 is a little odd.

Also what do you mean JavaScript files aren't suitable for storing large amounts of data.

handlers.json is a 1KB whereas prefs.js is a 17 KB. So, what, is there a limitation of 17KB for JavaScript files that I'm not aware of? People have programmed entire video games in JavaScript. See [this response](https://stackoverflow.com/a/14615519/2347135). They are talking about Gb files, and the link in the answer refers to at the very least MB files. The handlers.json had 923 characters in it. Please take a look at the values stored in "dom.ipc.cpows.allow-cpows-in-compat-addons" which for me is 1921 characters. From this it seems to me the entirety of handlers.json could be stored in a single preference.

Please explain with a little more detail why a default action needs to be stored in javascript object notation and not in the javascript. I'm pretty sure any JSON is also valid as JavaScript. But again, I'm not an expert in these things. I simply know that before this was working and now it's not. It seems like something from prefs.js is either not being read or is being overwritten by handlers.json.

more options

選ばれた解決策

Firefox would only download PDF files automatically when the builtin PDF Viewer is disabled or the file is send with a content type other than application/pdf. JSON is data stored in a specific object notation format. JavaScript is code that can be run like a program. In case of prefs.js this file is actually parsed and only user_pref lines are allowed to set pref in the three valid data types (Boolean, Number/Integer, String). A String pref can have its content set to JSON data, see for instance browser.uiCustomization.state that stores the toolbar customization. But like I wrote, prefs.js is not meant and suitable to store a large amount of data and is only updated when you close Firefox.

more options

Based on

"Firefox would only download PDF files automatically when the builtin PDF Viewer is disabled..."

I set the pdfjs.disabled preference to true and was able to get the file to download automatically. Thank you for pointing that out. I still think the values I set before should be enough to handle the PDF. Apparently, the builtin PDF Viewer gets to say whether or not it wants to handle a PDF before the other preferences are taken into account. Whether this is intended or not is really not an issue to me anymore.

Thank you for your assistance.

For clarity if anyone finds this when trying to get PDFs to download automatically using prefs.js:

Setting 'browser.helperApps.alwaysAsk.force = false' & 'browser.helperApps.neverAsk.saveToDisk = application/pdf' as well as the browser.download.* preferences does not force a download to occur, you must also tell Firefox not to use pdfjs ('pdfjs.disabled=true'). 'plugin.state.nppdf'=0 does not do this, neither does "plugin.disable_full_page_plugin_for_types='application/pdf'".