Getting chrome to open "text" files in a tab

When I look at code samples on the web that are linked to as a .c, .cpp, .h etc file, chrome will download it for me as a file.

Is there a way to get it to open the file (which is really just a text file with a different extension, and chrome does open text files in a tab window) in a tab window?

I would rather not have my downloads folder littered with all of these small code files.

I have looked in the chrome preferences, but have not found anything that relates to this.

Running the dev build of chrome, but I would take the option in any current build of the browser.

EDIT: Is there a way to change the way that chrome handles some mime types like text/x-chdr or others?


I did a bunch of tests and found that some types always trigger a download from remote location. For example, .bat files always try to download while the similar .cmd type opens as text. Likewise, .cpp files always trigger a download while my own .inc type which is an identical copy of the .cpp with the “cpp” changed to “inc” opens as text.

I haven’t checked the source, but I suspect it’s a built-in behavior. They must figure that if it’s a local file (file:///…), you already have it so it is assumed to be trusted, so open it. If however it is a remote file, don’t open it, instead download it so that any anti-virus software on the system can have a look to be safe.

Surprisingly there do not seem to be any other complaints about this on the Chrome bug tracker. o.O I have submitted a report, so we’ll have to see what they say.


Great question.

I can be achieved via an extension:

  • For Chrome, load undisposition
  • If the file loading is ASCII then colour coding may be desirable, that can be done via the Syntaxtic extension
  • btw, for Firefox load the InlineDisposition add-on

I used to use Syntaxtic! for Chrome, worked for me. It opens source code in a new tab and then applies syntax highlighting.