markdown-viewer icon indicating copy to clipboard operation
markdown-viewer copied to clipboard

Not loading md files in firefox on OSX

Open dmarteau opened this issue 8 years ago • 19 comments

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)

dmarteau avatar Aug 29 '17 19:08 dmarteau

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.

KeithLRobertson avatar Sep 03 '17 00:09 KeithLRobertson

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?

KeithLRobertson avatar Oct 03 '17 02:10 KeithLRobertson

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.

dmarteau avatar Oct 06 '17 13:10 dmarteau

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 avatar Oct 06 '17 13:10 dmarteau

@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.

KeithLRobertson avatar Oct 15 '17 17:10 KeithLRobertson

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.

dmarteau avatar Nov 14 '17 09:11 dmarteau

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.

dmarteau avatar Nov 14 '17 10:11 dmarteau

I created the bug : https://bugzilla.mozilla.org/show_bug.cgi?id=1417022

laurentj avatar Nov 14 '17 10:11 laurentj

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.

dmarteau avatar Nov 14 '17 10:11 dmarteau

I will check it out. Thanks!

KeithLRobertson avatar Nov 30 '17 04:11 KeithLRobertson

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.

Cimbali avatar May 23 '18 11:05 Cimbali

It seems that some supports for content handlers has been impelemented: https://bugzilla.mozilla.org/show_bug.cgi?id=1356397

dmarteau avatar May 23 '18 13:05 dmarteau

It rather seems it is not implemented but tracking moved to bug 1457500.

Cimbali avatar May 23 '18 14:05 Cimbali

yes, you are right. But things seems to go it the good direction.

dmarteau avatar May 23 '18 14:05 dmarteau

@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.

KeithLRobertson avatar Dec 15 '18 21:12 KeithLRobertson

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:

  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

Cimbali avatar Aug 06 '20 12:08 Cimbali

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

Evidlo avatar Sep 16 '21 15:09 Evidlo

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:

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.

chadj2 avatar Sep 21 '21 16:09 chadj2

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.

Cimbali avatar Sep 21 '21 17:09 Cimbali

Fixed in v2 (#99) by opening ext+view-markdown/to/file.md and confirming local file access, which bypasses Firefox mime-type handling.

Cimbali avatar Jan 17 '23 16:01 Cimbali