RESOLVED CONFIGURATION CHANGED 97361
range.selectNode throws INVALID_NODE_TYPE_ERR unless node has Document/DocumentFragment ancestor
https://bugs.webkit.org/show_bug.cgi?id=97361
Summary range.selectNode throws INVALID_NODE_TYPE_ERR unless node has Document/Docume...
Nathan Vander Wilt
Reported 2012-09-21 14:24:29 PDT
The following code fails unexpectedly in WebKit (works in FF, haven't tested IE): var range = document.createRange(), root = document.createElement('div'); root.appendChild(document.createElement('span')); range.selectNode(root.firstChild); // throws INVALID_NODE_TYPE_ERR It is possible to `range.selectNodeContents(root)` or `range.setStart(root,0), range.setEnd(root,1)` but the `.selectNode` method specifically, errors when it should not. Reference: http://www.w3.org/TR/dom/#dom-range-selectnode — only case INVALID_NODE_TYPE_ERR should be thrown is if root.firstChild.parentNode is null...but that's unpossible! Hooking the root element into a document, or even a document fragment via e.g. `document.createDocumentFragment().append(root)`, causes the bug to no longer manifest.
Attachments
Ojan Vafai
Comment 1 2012-09-24 12:12:36 PDT
I think the simplifications that DOM4 makes to selectNode are mostly good. There's a bunch of things our code does differently though. Someone needs to evaluate what the WebKit code does now and make sure we're OK with the spec as is (e.g. is it OK for the parent of the refNode to be a DocumentFragment?). At first glance, the spec looks good to me, but I haven't taken a thorough look.
Anne van Kesteren
Comment 2 2023-12-29 03:26:32 PST
This appears to have been fixed at some point.
Note You need to log in before you can comment on or make changes to this bug.