0

Is it possible to change the content-type from within the browser?

Use-case: bitbucket & github both allow you to view the "raw" form of documents stored in the repositories. These are returned with Content-type: text/plain. However, sometimes these are HTML documents and I'd like to view them rendered as HTML in this case.

The important point is that I can't change how the server returns Content-type.

(this answer gives a workaround for github, but not for bitbucket)

Community
  • 1
  • 1
keflavich
  • 18,278
  • 20
  • 86
  • 118

2 Answers2

1

I tried something similar some time ago. I used JQuery to parse text as Json or html. In case of HTML I appended it to directly to the DOM.

check parseHTML()

sailingthoms
  • 900
  • 10
  • 22
  • I can't use jquery since it's not loaded on the page, and I think the fact that it's https means I can't use this solution: http://stackoverflow.com/questions/7474354/include-jquery-in-the-javascript-console (the bookmarklet & script both fail with `[Blocked] ... ran insecure content...`) – keflavich Jun 28 '13 at 21:31
  • Was able to get jquery running with `var script = document.createElement('script');script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";document.getElementsByTagName('head')[0].appendChild(script);`, but I don't really know enough jquery to do any better than `$('body').replaceWith($.parseHTML($("html").html()))`, which doesn't work. – keflavich Jun 28 '13 at 21:39
  • My idea was using JQuery ajax calls or loading the requested page as ` – sailingthoms Jun 28 '13 at 21:55
1

Yes, just use the browser plugin, such as Requestly or Modify Headers for Google Chrome™" for Chrome (or similar for other browsers, just search for "modify headers" add-on).

For particular URL, you'll want to change Content-Type to text/html and possibly also change the Content-Security-Policy as well (try default-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src * 'unsafe-eval';).

Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
revelt
  • 2,312
  • 1
  • 25
  • 37