How can I make Google Chrome display a plain text HTTP response, rather than downloading it in a file?

Posted on

Problem :

There’s a web site I visit that includes a document which is returned with content type text/plain and my version of Google Chrome used to display it in the browser window, as plain text. I like it that way. However, it has started to download the document now when I visit it, instead, meaning I have to open it with a text editor to view it. How can I make Chrome return to the old behaviour?

Solution :

The reason is most likely that the server is telling the client (browser) to download the file. This is controlled (usually) via the HTTP header

Content-disposition: attachment

(optionally with a filename).

Check if the server serves your document with this header. To view the headers, you can download the page using a tool that preserves HTTP headers (e.g. wget --save-headers), or use an online service, e.g. http://web-sniffer.net/ .

Then post the headers here, or even better, the document’s URL (if you can).

You could try doing

view-source:http://example.com/the-text-document.txt

Which should let you see the document in chrome regardless of the headers

Can you verify that the Content-Type is actually ‘text/plain’? You can do so in by going to View -> Developer -> Developer Tools and viewing the response headers on the file. I’ve seen situations where the Content-Type is unrecognized (i.e. ‘plain/text’), and therefore causes the file to be downloaded rather than displayed.

I strongly recommend that you check your url with other browser if it’s working so may be you are facing this google Chrome issue
Here is an example URL showing the issue: http://uselesstrash.com/test.txt
Try this URL with Firefox, then Chrome and you’ll see the behavior is different because of the hidden “^G”:
test^Gtext.

If your text is utf-8 encoded but has some lower-ascii chars in it (e.g., ESC) that might be triggering the issue.

If other browsers act the same as Chrome you have to check if the MIME type really is plain/text, use a web sniffer to verify the header content.
Just do a “CTRL + SHIFT + i” in Chrome, then go to the “Network” tab.

Leave a Reply

Your email address will not be published. Required fields are marked *