I want to mirror the text selection in a contenteditable div in one browser in another browser. The simplified and relevant section of the code is:
In the source browser:
function someFunc() {
if (window.getSelection().isCollapsed)
return;
var range = window.getSelection().getRangeAt(0);
//Send range over websockets to another browser
sendToAnotherBrowser(...) //Send range
}
In the remote browser, I execute the following code:
var sel = window.getSelection();
sel.addRange(range); //Where range is the range transmitted over webSockets
I get the following error:
"Failed to execute 'addRange' on 'Selection': parameter 1 is not of type 'Range'
QUESTION: How to transmit the "Range" object over websockets? It is not a JSON object to be stringified and sent. Can I serialize it somehow, change it to base64 and then reverse the process on the receiving end?