The Highlight API
Most annotation tools wrap highlighted text in extra elements. That works until the page re-renders: a framework that owns the DOM throws the wrappers away, or trips over nodes it didn't create. penciled leaves the page alone and paints highlights with the CSS Custom Highlight API instead.
The browser keeps a registry of named highlights, each a set of ranges. A stylesheet then styles them with the ::highlight() pseudo-element, much like it styles a selection. Nothing is added to the document, so nothing can be thrown away.
Finding the text again after a reload is the harder part. Each annotation stores the quoted text, some context on either side and its position. When the page changes, penciled looks for the quote, compares the context, and only highlights a match it is confident about.