How to fix “Error: NAMESPACE_ERR: DOM Exception 14” in Chrome

The only references I’ve found online are to an old bug in Chrome.

Error: NAMESPACE_ERR: DOM Exception 14

I generated this with the following xpath expression generated by Firebug:

id('content')/x:div[2]/x:div[3]/x:div[1]/x:h2[2]

This causes this javascript line to fail:

document.evaluate("id('content')/x:div[2]/x:div[3]/x:div[1]/x:h2[2]", document, null, XPathResult.ANY_TYPE, null)

The fix is very simple: remove the namespaces – the “x:”, like so:

id('content')/div[2]/div[3]/div[1]/h2[2]

And then the JS code will work:

document.evaluate("id('content')/div[2]/div[3]/div[1]/h2[2]", document, null, XPathResult.ANY_TYPE, null)