I'm working on highlighting feature for one project, that in theory would work like that:
- User selects something on page and clicks a button to highlight it (for that we are using tsv.annotator that works with rangy)
- After clicking the button we call document.getSelection()
- We save the anchor and focus nodes, as well as offsets into database
- When user opens the page again we get the nodes from db and highlight it
But that doesn't work because JSON.stringify returns empty object when passed document.getSelection().
The selection object as requested:
A minimal reproducible example would be like that:
let selection = JSON.stringify(document.getSelection()); // => outputs {}