markdown-viewer
markdown-viewer copied to clipboard
Not loading md files in firefox on OSX
When trying to open a local .md file, FF ask what to do with the file. The extension does not bypass default file handler.
Firefox 55.0.3 System: OSX (El capitan)
No, indeed it doesn't, but it should if you set up a mime type for it. See Issue #2 for the solution on Linux (Ubuntu). You'll have to do something similar on OSX; the same solution might even work. Please post here and let us know either way.
Hi @dmarteau, Keep in mind that the addon does not control FF; FF has control of the addon. So it's not valid to expect the addon to bypass the default file handler. Rather, we need to make the FF file handler hand the file over to the addon. That is not happening now, so the addon never sees it. That is a FF issue.
Can you please try the configuration steps mentioned previously for Linux to see if they work on OSX?
https://github.com/KeithLRobertson/markdown-viewer/issues/2 is not working on OSX (there is no update-mime-database command)
Also modifying the mimeTypes.rdf is useless since it is regenerated when firefox start.
According to https://support.mozilla.org/en-US/kb/applications-panel-set-how-firefox-handles-files it should be possible for an extension to register file types handlers. I know that the link is outdated but I would be very surprised if that the api has changed so much that it not possible to register content handlers anymore.
@dmarteau The page you linked says nothing about extensions registering file type handlers. It is about how you, the user, can tell the browser how to handle various file types.
Up to know If have found no solutions to make that extension work in OSX since I have found no way to tell Firefox to handle specific kind of files - all solutions that seems to apply to linux does not work.
As it seems and after some discussions with extension developper, there is no API that expose something like the nsIHandlerService in webextension: your hack for determining the kind of file loaded implies that the file has already been loaded.
Actually Firefox mime type handler depends on some system spécifications: this will definitely prevent all extensions using the same hack has to work on some platforms.
It seems that there the only solution is to open an issue on https://developer.mozilla.org/fr/docs/Mozilla/Bugzilla and ask for exposing a mime type handler API.
I created the bug : https://bugzilla.mozilla.org/show_bug.cgi?id=1417022
you should have a look at https://addons.mozilla.org/en-US/firefox/addon/open-in-browser/.
It seems that this extension inspect the request before FF decides what to do with the file: by changing the mime-type/content-disposition in the header it changes the behavior of FF.
I will check it out. Thanks!
They use the webrequest.onHeadersReceived, with "blocking" and "responseHeaders" to modify headers.
This allows to add Content-Disposition: inline and maybe change mime types if necessary. This is also where we could strip Content Security Policy headers if we wanted to.
However after some testing the onHeadersReceived does not seem to fire for local files, so it can't be used to solve this bug.
It seems that some supports for content handlers has been impelemented: https://bugzilla.mozilla.org/show_bug.cgi?id=1356397
It rather seems it is not implemented but tracking moved to bug 1457500.
yes, you are right. But things seems to go it the good direction.
@dmarteau, have you tried Simeon Velichkov's Markdown Viewer? https://addons.mozilla.org/en-US/firefox/addon/markdown-viewer-chrome/?src=search
I believe he's using an approach like you describe. (His extension is much more complete in support of various stylings and features.) However, I also find it extremely quirky. One minute my .md is styled, then when I refresh, it's a blank page and is forever after blank. So I'm afraid to go that route with this viewer.
I’ve just added another workaround to the README, which should work on macOS as well as on Linux. It’s the one I am using myself now, on FF 78. It uses a mime.types file to tell Firefox that markdown files are to be handled as text (and doesn’t mess with the rest of your system).
It works in 3 simples steps:
- Create an empty
mime.typesfile (the usual value is~/.mime.types) or edit that file if it exists, and add the following line to this file:type=text/plain exts=md,mkd,mkdn,mdwn,mdown,markdown, desc="Markdown document" - Go to
about:configin your Firefox, and make sure the value forhelpers.private_mime_types_fileis the file from step 1 (so normally~/.mime.typesor whichever other file you used instead). - Restart Firefox
For others looking into this, after following a chain of duplicate bugs, the correct FF bug is here: https://bugzilla.mozilla.org/show_bug.cgi?id=1457500
I’ve just added another workaround to the README, which should work on macOS as well as on Linux. It’s the one I am using myself now, on FF 78. It uses a
mime.typesfile to tell Firefox that markdown files are to be handled as text (and doesn’t mess with the rest of your system).It works in 3 simples steps:
1. Create an empty `mime.types` file (the usual value is `~/.mime.types`) or edit that file if it exists, and add the following line to this file: ``` type=text/plain exts=md,mkd,mkdn,mdwn,mdown,markdown, desc="Markdown document" ``` 2. Go to `about:config` in your Firefox, and make sure the value for `helpers.private_mime_types_file` is the file from step 1 (so normally `~/.mime.types` or whichever other file you used instead). 3. Restart Firefox
I tried this in MacOS Catalina with Firefox 92.0 and it does not work. I will note that the helpers.private_mime_types_file config key did not exist and so I created it.
Too bad − thanks for the feedback @chadj2. It works on Linux but I’m not sure what the right way would be on macOS then, and I don’t have access to a machine on which to test it.
Fixed in v2 (#99) by opening ext+view-markdown/to/file.md and confirming local file access, which bypasses Firefox mime-type handling.