Google-chrome – How to have some type of files open directly in a chrome tab

browsergoogle-chrome

I am using google chrome 77.0.3865.90 on Ubuntu 16.04.6 and I want to make chrome open some types directly in a browser tab.

For example text files with extension .log (example out_L4PC.log) are being opened directly in a broswer tab when I use an URL like some/web/adress/out_L4PC.out.

I have different files, also containing just text, but they end in .err (example out_L4PC.err). I want them to also open directly in the browser tab.

But so far, when I use such an .err file they are being downloaded and opened with a different application. This is not what I want. I do not want these type of files opened with a different application, but directly in the browser, just like .log files.

How to do that?

Best Answer

There are different reasons for why Chrome (or any other browser) is downloading these files, instead of opening them in the browser:

  • The hyperlink you clicked uses the download attribute, or the server responds with a Content-Disposition: attachment HTTP header - in both cases this tells the browser to download the file and save it to your local disk instead of displaying it.
  • The resource you clicked returns (in the HTTP headers) a MIME type that the browser does not understand or cannot display (such as application/octet-stream).

Unfortunately, it seems Chrome itself offers no way to override this behavior.

For the first case (Content-Disposition header), you can use the Chrome extension Undisposition, which will remove this header, allowing you to display the document in the browser. Note, however, that this will affect all links as long as the extension is active - so if you do want to download something, you'll have to disable the extension (or use "Save link as" from the context menu).

For the second case, I'm not aware of any method to disable Chrome's behavior.

You could, however, use Mozilla Firefox :-). For Firefox there's an extension which does what you want, Open in Browser. If you click on a link that would normally trigger a download, it will pop up a dialog asking if you want to download or view in browser.