RESOLVED FIXED290307
CSS Custom Highlight fails for some document structures
https://bugs.webkit.org/show_bug.cgi?id=290307
Summary CSS Custom Highlight fails for some document structures
weijarz
Reported 2025-03-24 06:39:11 PDT
For example: ```html <div id=idDiv>Webkit<div>!</div></div> <style> body { font-size: 80px; } ::highlight(my-highlight) { background-color: #ffa; } </style> <script> const range = new Range() range.setStart(idDiv.firstChild, 0) range.setEnd(idDiv.firstChild, 1) const highlight = new Highlight(range) CSS.highlights.set("my-highlight", highlight) </script> ``` This script will highlight the first letter ‘W’. But it fails on webkit (checked on iOS 18.3.2). But delete the `<div>!</div>` and it works again!
Attachments
Radar WebKit Bug Importer
Comment 1 2025-03-31 06:40:14 PDT
Oleksandr
Comment 2 2026-01-19 09:36:59 PST
Thanks for the report! We're facing a similar issue in our app, too. The workaround we found was wrapping the text node in a `span`: ```html <div id=idDiv><span>Webkit</span><div>!</div></div> <style> body { font-size: 80px; } ::highlight(my-highlight) { background-color: #ffa; } </style> <script> const range = new Range(); range.setStart(idDiv.firstElementChild.firstChild, 0); range.setEnd(idDiv.firstElementChild.firstChild, 1); const highlight = new Highlight(range); CSS.highlights.set("my-highlight", highlight); </script> ``` Sandbox - https://developer.mozilla.org/en-US/play?id=qdi5DuY0K0d8V2ZaDTowgUEPF1MQBtZmh2X4bQoVP%2F7q%2FydeZZ5yHDUuHbI3rFFBr5fmwgDlC0cc74kH
Karl Dubost
Comment 3 2026-08-17 00:09:12 PDT
*** Bug 320445 has been marked as a duplicate of this bug. ***
Vitor Roriz
Comment 4 2026-10-12 13:56:09 PDT
Vitor Roriz
Comment 5 2026-10-12 14:04:29 PDT
EWS
Comment 6 2026-10-13 09:29:27 PDT
Committed 323588@main (ab4c4fa09297): <https://commits.webkit.org/323588@main> Reviewed commits have been landed. Closing PR #76332 and removing active labels.
Vitor Roriz
Comment 7 2026-10-20 10:51:11 PDT
Submitted web-platform-tests pull request: https://github.com/vitorroriz/wpt/pull/1
Tim Nguyen (:ntim)
Comment 8 2026-10-20 15:54:42 PDT
Note You need to log in before you can comment on or make changes to this bug.