15

Is there any way to force either Firefox or Chrome to interpret a loaded resource as a particular MIME type?

For example, the raw code views provided by online SCC interfaces such as Google Code send content as text/plain by default. If I'm looking at an HTML file, I'd like to be able to override this in the browser and view it as text/html.

Are there any extensions or hidden commands for Firefox or Chrome that provide "View as MIME type" functionality?

kpozin
  • 25,691
  • 19
  • 57
  • 76

3 Answers3

29

Shameless plug: I just published a (free) Chrome extension to do just what you ask. It's available on the Chrome web store. It works by listening to the chrome.webRequest.onHeadersReceived event and patching in a custom content-type HTTP header. If you'd like the build it yourself or see how it's implemented, the source is available on GitHub.

zackdever
  • 1,642
  • 1
  • 13
  • 22
Ori
  • 4,132
  • 1
  • 25
  • 27
  • 1
    Ori, this is excellent. I've been using this extension almost daily. – kpozin Mar 30 '12 at 03:20
  • 7
    Looks that you can only activate this functionality if you right click on a link and select the option "open as media type". Can I change the mime type of a file wich URL I have but I don't have a page pointing at? – Sebastián Grignoli Jul 04 '12 at 23:56
  • What a great extension! Thanks! – sanpaco Aug 28 '12 at 23:09
  • Just a minor criticism: your extension seems to remove the `filename` parameter from `Content-Disposition` if it's present, which I suspect would result in the default filename being lost if the user tries to save the page/document. – Sam Apr 22 '13 at 09:21
  • @SebastiánGrignoli I created a temporary index.html page with the links I wanted to load as HTML and then right clicked those :) Only need to do this once. – martinedwards Nov 24 '15 at 15:02
  • 1
    Your “[Chrome web store](https://chrome.google.com/webstore/detail/dpfpbhhpecfkhkmponbmaldhfollibde)” link is broken, both here and on GitHub. Searching for “force media type” in the store shows only an [extension](https://chrome.google.com/webstore/detail/modify-content-type/jnfofbopfpaoeojgieggflbpcblhfhka) called “Modify Content-Type”. Not sure if it’s yours. – Michael Allan Oct 08 '18 at 05:33
5

For Firefox, there is an add-on provides almost the function you wanted: https://addons.mozilla.org/en-US/firefox/addon/force-content-type/ . No idea if there is a Chrome extension or not.

Even if the functionality exists, I wouldn't recommend you to use it in your example: Arbitrary HTML would have access to google.com domain for cookie and script, which is really really bad in terms of security.

timdream
  • 5,914
  • 5
  • 21
  • 24
  • 1
    Very good point about security. Fortunately, it looks like Google has thought of that. All raw files are served from *projectname*.googlecode.com, which does not set or transmit any cookies. (The code browser is served from code.google.com, which does use cookies.) – kpozin Jan 26 '11 at 18:30
-4

Ubuntu 12.04 has an extension to the System Settings called Tweak. This has a FileType Manager.