21 Oct 2008

Firefox3 and Genshi trouble

Posted by ged

A few weeks ago, I finally upgraded my laptop to Ubuntu Hardy (8.04). I had already upgraded my Desktop computer on the day of the release but given the numerous issues I had with the new version, I didn’t switch my laptop (on which I work) yet. In my opinion, this was one the single most problematic release of Ubuntu ever (and I’ve been an Ubuntu user since its very first release). Since I had not seen any issue with my desktop computer for a while, and that I wanted firefox 3 (mainly for its increased javascript execution speed), I’ve given the current version a spin.

The upgrade went quite smoothly. I only wish the upgrade manager asked all questions (mostly about changes in system config files, most of them I didn’t even do myself) at the beginning then work in the background without interrupting me.

Now with the actual title of this post… So, after the switch to Firefox 3, I soon discovered that one javascript application I’m working on (the client for OpenHexperience) didn’t work anymore. I had a blank page, that’s it. No error whatsoever. I soon found out that my javascript code wasn’t called at all. Inline javascript worked fine but any code included in an external file was just silently ignored. After 3 hours of hair-pulling debugging, I finally understood the issue. It turns out it was Firefox 3’s new pickiness at closing tags. It didn’t like the way my script tag was closed in my simple html (not xhtml) bootstrap page.

<script type="text/javascript" src="/script/ohxp.js"/>

It wants an explicit closing tag, as in:

<script type="text/javascript" src="/script/ohxp.js"></script>

I’m all for respecting standards, and I’ve often bitched at IE for accepting
totally invalid markup, but hell, introducing such a change without any error anywhere is almost a crime to humanity.

Now, what made this issue especially hard to debug was that I tried the correct version in my template very early in my debugging process, but it didn’t fix my problem, leading me to search elsewhere. The culprit here was my memory… I completely forgot Genshi serialized to xml by default, and diligently replaced the empty script tag (with the explicit closing tag) by the shortcut syntax for empty tags… Exactly what Firefox doesn’t want. As is often the case, once understood, fixing this issue was dead simple. One of the possible solutions is simply to tell Genshi to serialize to html, by changing:

return tmpl.generate(**data).render(doctype="html")


return tmpl.generate(**data).render("html", doctype="html")

Leave a Reply