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
javascript dom serialization deserialization rangy


source to share


No one has answered this question yet

Check out similar questions:

410
Detect when the browser is downloading files
2
How to properly deserialize objects when errors are encountered
2
rangy deserialize not working on webview android
1
Rangy calculates deserialized positions after adding content to DOM above rangy highlightable div
1
ServiceStack JsonServiceClient dormant during deserialization
1
Rangy highlighter - deserialized issue
1
Recover multiple choices from db using Rangy
0
Rangy - restore cursor position when replacing innerHTML
0
Assign property Readonly
0
Rangy saves and updates selection in the database



All Articles
Loading...
X
Show
Funny
Dev
Pics