Getting an error to deserialize a position randomly when using the rangy library

I was having problems with rangy.

received error:

Error: Error in Rangy Serializer module: deserializePosition () failed: node "does not have a child with index 3, 5"

I am getting this error when I pull the serialized highlights from the database and try to deserialize them in the webpage. The really weird thing most of the time is highlighting that the highlights are just fine and appear on the page, but sometimes they accidentally disappear and I get the above error.

I have used the chrome javascript debugger to track down the issue and

function deserializePosition(serialized, rootNode, doc) {
    if (!rootNode) {
        rootNode = (doc || document).documentElement;
    }
    var parts = serialized.split(":");
    var node = rootNode;
    var nodeIndices = parts[0] ? parts[0].split("/") : [], i = nodeIndices.length, nodeIndex;

    while (i--) {
        nodeIndex = parseInt(nodeIndices[i], 10);
        if (nodeIndex < node.childNodes.length) {
            node = node.childNodes[nodeIndex];
        } else {
            throw module.createError("deserializePosition() failed: node " + dom.inspectNode(node) +
                    " has no child with index " + nodeIndex + ", " + i);
        }
    }

    return new dom.DomPosition(node, parseInt(parts[1], 10));
}

      

in this block of code for some reason at line

var node = rootNode;

      

although rootNode = html, the node variable is sometimes set to "text" and this causes node.childNodes.length to be 0 and an error occurs. Any help would be greatly appreciated, thanks.

+3


source to share





All Articles