Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not loading md files in firefox on OSX #6

Closed
dmarteau opened this issue Aug 29, 2017 · 20 comments
Closed

Not loading md files in firefox on OSX #6

dmarteau opened this issue Aug 29, 2017 · 20 comments
Labels
Firefox bug Caused by a bug in firefox, help by voting on the bugizlla ssue !

Comments

@dmarteau
Copy link

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)

@KeithLRobertson
Copy link
Collaborator

KeithLRobertson commented Sep 3, 2017

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
Copy link
Collaborator

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 KeithLRobertson changed the title Not loading md files in firefox Not loading md files in firefox on OSX Oct 3, 2017
@dmarteau
Copy link
Author

dmarteau commented Oct 6, 2017

#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
Copy link
Author

dmarteau commented Oct 6, 2017

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.

@KeithLRobertson
Copy link
Collaborator

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

@dmarteau
Copy link
Author

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
Copy link
Author

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.

@laurentj
Copy link

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

@dmarteau
Copy link
Author

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.

@KeithLRobertson
Copy link
Collaborator

I will check it out. Thanks!

@Cimbali
Copy link
Owner

Cimbali commented May 23, 2018

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.

@dmarteau
Copy link
Author

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

@Cimbali
Copy link
Owner

Cimbali commented May 23, 2018

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

@dmarteau
Copy link
Author

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

@KeithLRobertson
Copy link
Collaborator

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

@Cimbali
Copy link
Owner

Cimbali commented Aug 6, 2020

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 Cimbali added the Firefox bug Caused by a bug in firefox, help by voting on the bugizlla ssue ! label Aug 6, 2020
@Evidlo
Copy link

Evidlo commented Sep 16, 2021

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

@chadj2
Copy link

chadj2 commented Sep 21, 2021

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.

@Cimbali
Copy link
Owner

Cimbali commented Sep 21, 2021

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
Copy link
Owner

Cimbali commented Jan 17, 2023

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

@Cimbali Cimbali closed this as completed Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Firefox bug Caused by a bug in firefox, help by voting on the bugizlla ssue !
Projects
None yet
Development

No branches or pull requests

6 participants