Firefox NS_ERROR_INVALID_POINTER with innerHTML

When trying to use prettify here on Defective Semantics I ran into problems with firefox. Here are the errors from the error console:

Error: undefined entity
Error: uncaught exception: [Exception...
 "Component returned failure code: 0x80004003 
 (NS_ERROR_INVALID_POINTER) [nsIDOMNSHTMLElement.innerHTML]"  
  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"
  location: "JS frame :: hxxp://example.net/prettify.js :: 
             replaceWithPrettyPrintedHtml :: line 1414"
  data: no]

My insistence on trying to use XHTML on the blog is partly to blame. Prettify tries to add “ ” entities to the source (even if it’s a pre element) to appease Internet Explorer. This entity only semi-works in XHTML: I’ve run into similar problems with some HTML entities not being loaded, because some browsers don’t load the DTD (which in turn loads the entity sets). It also appears that while Firefox claims to support HTML latin 1 entities in a document with a PUBLIC XHTML identifier, it doesn’t actually reparse innerHTML assignments according to those rules.

My solution is to add a conditional test for XML. Having a look at the Javascript document object there doesn’t seem to be a reliable way to detect whether the browser is treating the document as XML from javascript. My best attempt was:

document.xmlVersion && (document.compatMode=='CSS1Compat');

which works for Firefox and Opera.

As a separate issue, Chrome and Safari (and presumably anything WebKit based) don’t allow assignment of innerHTML for XML documents, giving NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
Fixing prettify to use only DOM methods instead of building up a string and assigning it to innerHTML could be a lot of work. At least this exception, unlike the Firefox error, doesn’t leave the pretty-printed block in an inconsistent state.

I submitted a patch to the prettify issue tracker.

Browser wars… 2008-style

So, Firefox 3.0 and Opera 9.50 were released within 5 days of each other (June 12 and June 17 respectively). It’s good to see both browsers being progressive and targetting bragging rights such as Acid3, even if they only score 70 and 83 respectively. I notice neither of them pays due attention to deferred scripts, but I guess everyone is using AJAX nowadays instead?

As for the other browsers… I’ve got no problems with Safari. It’s a competent browser, but doesn’t have Opera’s cache/connection leverage or FF’s dev features. I doubt MSIE will even display this post and I don’t care. So, there’s the state of the art.

The firefox upgrade was weird because the RC3 “Check for Updates…” function assured me that I had the latest version. This was further confused by the lack of any RC markings or build numbers in the “About Mozilla Firefox” dialog. It became apparent that I had silent upgrades on, but I don’t recall ever being informed that FF had patched itself.

One thing I’ve noticed is that the DOM Inspector still doesn’t conform to the LnF of the updated Firefox interface. I’d assumed this was a detail that would get polished before the final.

While we’re in a browser-technologies-mood: here’s my rdb opensearch definition for rolldabeats. For all your DnB discography needs.

Opera have munged the keyboard shortcuts. The change seems to be for the better as it’s unified the Windows/UNIX/Mac sets by using guard conditions like Platform Mac. They’ve also deprecated single-key shortcuts, which is fair enough because if you had a textbox focused then they were useless and confusing.

One thing that tripped me up was the Feature ExtendedShortcuts guard, which is activated by the “Enable single-key shortcuts” checkbox in the preferences. The shift+I shortcut for toggling images between cached, all and none was under this guard—but it’s two keys, right?

launch for Mac OS X

I’m in the habit of keeping multiple profiles under firefox. It means I can have a profile for FF2 (with old plugins that haven’t been ported to FF3), a profile for development with FF3, and one for general browsing with FF3.

Despite their usefulness, profiles seem to be discouraged. The profile manager isn’t shown by default. You have to start the firefox binary with -P to get it up.

Having multiple profiles is great, but under Mac OS X it’s not easy to use them simultaneously. Trying to re-launch an application just activates the currently open instance. Aside from the (wasteful) hack of duplicating the .app directory, how do you open the same application twice under Mac OS X?

The answer is launch. It’s in fink too.

launch -m -a Firefox

Apparently Quicksilver had a “Launch a copy” action that did something similar, but I can’t find it in the current version.