FIxing text/plain HTML in Firefox

Firefox, correctly but annoyingly, displays HTML pages served as text/plain as the raw HTML rather than as rendered HTML. Someone has come up with a very useful bookmarklet called Force HTML which fixes this. It’s pretty clever; it just reads the text from the page into a string and then document.write()s it back into the page. I would not have thought of this!
I’d like to make this a GreaseMonkey script, so that I’m never bothered by this problem again, but there are two small issues with that. Issue 1 is that I can’t work out how to discover what the content-type a page was served as from JavaScript. (This isn’t a major issue; I could check for the document element being pre and the page content containing lt and gt characters and guess from that that it’s HTML being served as text/plain, probably.) Issue 2, a bit more seriously, is that when I do implement it as a GreaseMonkey script it crashes the browser. I am guessing that this is because GM runs before proper page load, and replaces the content of the page with a totally different page using document.write(). This probably screws things up. Once I’ve narrowed this down to a test case I’ll submit it as a GM bug, although I suspect Jeremy and Aaron and crew will say: don’t use document.write() to make the whole page disappear when you’re still in the middle of rendering that page.

I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)