How can I edit Chrome MIME type mappings?
Asked Answered
P

5

28

I opened a image/x-png type image in new tab, but Chrome just downloaded it. I googled it and found that Chrome doesn't interpret image/x-png as image file.

So, I want to edit my Chrome's MIME type mappings. Is it possible?

Papen answered 30/11, 2011 at 9:49 Comment(3)
I have an idea, but need test data. Please add some URLs with bogus response headers (image/x-png) to your question.Morose
finally found some test images bugs.adobe.com/jira/browse/SDK-32051 thanks to https://mcmap.net/q/328677/-chrome-downloads-png-image-links-i-want-them-to-open-for-viewing-in-a-new-tab-how-do-i-make-chrome-do-that/962091Ethiopia
For me those images are normal image/png, so I tested with a local web server (misconfigured on purpose).Morose
M
19

Too bad you have not answered my comment, so I forgot about your question and lost the bounty. I guess my answer is even a little easier to use for you because you do not need to click any context menus in order to see the PNGs directly in the browser:

Chrome extension Redirector can be configured to replace HTTP response headers. I created a rule replacing the Content-Type header for any URL ending with ".png":

Paste this JSON code into a text editor, save as png_rule.json and then in Redirector settings go to Rules Manager, click Files to open im-/export options and import the rule version 1:

[{"name":"x-png -> png","match":{"str":"\\.png$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1}]

From now on all your PNG files should be fine.

Update: replaced the simple pattern match by a stricter regex match as suggested by the author or Redirector.


Update 2: There are systems like Trac which produce URLs for PNG attachments ending in ".png", but really being HTML pages which only embed the PNG as part of the page. In this case we need to blacklist the hosts because otherwise the HTML page's content type would be set to image/png even though it should remain text/html. Because of Redirector's limitation that headers can just be overwritten for matched URLs and partial replacement, e.g. only png instead of x-png, is impossible, we need to use a rather ugly approach of explicitly excluding certain hosts in the regex match. E.g.

^https?://(?!([^/]+\.)?(?:trac\.edgewall\.org|freetz\.org)/).*\.png$

would exclude URLs containing either host name trac.edgewall.org or freetz.org. The full JSON to be imported into Redirector is rule version 2:

[{"name":"x-png -> png","match":{"str":"^https?://(?!([^/]+\\.)?(?:trac\\.edgewall\\.org|freetz\\.org)/).*\\.png$","type":0,"modi":true},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1}]

Two test URLs failing (i.e. showing empty "images" instead of HTML pages) with the previous version of the rule without blacklisting and now functioning with the new rule including blacklisting are:

It is easy to add other URLs if you know a little regex or just play around.

By the way: For Trac URLs a good alternative would be to use the common part "/attachment/ticket/" for blacklisting. This way you could blacklist all Trac installations worldwide instead of a fixed hosts list. So this is rule version 3:

[{"name":"x-png -> png","match":{"str":"^https?://(?!([^/]+)?/attachment/ticket/).*\\.png$","type":0,"modi":true},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1}]

Update 3: Redirector is no longer available in Chrome store, but historic versions can be downloaded from the old Redirector home page.

Morose answered 2/9, 2012 at 12:24 Comment(5)
The link above to 'Redirector' appears to be broken. Would you be able to recommend another?Taste
User @Mardok has answered the question where to find (old versions of) Redirector. I repeat: code.google.com/p/chrome-redirector/downloads/listMorose
Since Redirector doesn't exist anymore, https://mcmap.net/q/328677/-chrome-downloads-png-image-links-i-want-them-to-open-for-viewing-in-a-new-tab-how-do-i-make-chrome-do-that might helpChacha
@sachinjain024, firstly, the extension is not working as expected for my sample URL. The corresponding PNG image is always downloaded. Secondly, you are obviously the extension author,. so you should be able to tell me why the extension wants to have full access rights to see all my data on all websites and why I have to save my rules online on your website instead of locally. IMO that extension is just a big data collector and I will certainly not use it, having to pay with all my private surfing data.Morose
@Morose Could you please provide more details about the site and the png URL here - github.com/requestly/customer-support/issues and I'd be happy to investigate this. Since, the app works on the rules defined by the user there's no way we can limit the app to be used on specific domains. We don't collect data as you are thinking, infact we store all the rules in local storage. Here is the privacy policy - requestly.io/privacyChacha
E
15

It seems that you can't edit your MIME type mappings, see "View As MIME Type" in Chrome or Firefox

This answer https://mcmap.net/q/331434/-quot-view-as-mime-type-quot-in-chrome-or-firefox-closed is of particular interest. The author has made and open sourced a Chrome extension to open files as different MIME types via an added menu item on right-click, though it does not provide a global handling mechanism.

EDIT:

The extension by default only has the options to open as text/html and text/plain, but you can add any extensions you like, including image/png, in the extensions settings. Here's a test image.

This bug was moved to Untriaged on August 13, 2012 in the Chromium bug tracker, so hopefully this will be fixed soon in Chrome as well.

Ethiopia answered 27/8, 2012 at 17:34 Comment(0)
H
3

There is a Chrome extension that can change the content-type and the disposition for any pattern, so it can be used to force png to display instead of download (but it is good for many other cases, I am using it to render txt as HTML): Modify Content-Type Chrome Extension

Halfmast answered 7/6, 2017 at 15:27 Comment(0)
S
2

For some reason they have removed redirector from chrome web shop. You can find any version of redirector here

Here is json for .jpg .gif and .png formats:

[{"name":"x-png -> png","match":{"str":"\.png$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1},{"name":"x-jpg -> jpg","match":{"str":"\.jpg$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/jpg","decode":false},"enabled":1},{"name":"x-gif -> gif","match":{"str":"\.gif$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/gif","decode":false},"enabled":1}]

Spalding answered 10/7, 2014 at 13:23 Comment(0)
P
2

Apparently, Chrome does not have its own mime-handling database, but uses that of your desktop environment.

In my XFCE4-based environment, for example, the settings are controlled through the xfce4-settings app (xfce4-mime-settings specifically).

On a Windows desktop, you'd go through the "Default Programs" part of the "Control Panel", as described in (painful) detail here.

Pratfall answered 4/5, 2020 at 14:26 Comment(1)
And for MacOS used to be the helpful tool, now defunct RCDefaultApp. SwiftDefaultApps github.com/Lord-Kamina/SwiftDefaultApps is a good replacement.Dulaney

© 2022 - 2024 — McMap. All rights reserved.