advanced-mark.js can traverse open shadow roots and same-origin iframes to find and highlight text inside them. Because these environments maintain their own DOM trees and style scopes, the library provides dedicated options for both enabling traversal and injecting custom styles that apply within those encapsulated contexts.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/angezid/advanced-mark.js/llms.txt
Use this file to discover all available pages before exploring further.
Shadow DOM
Enabling shadow DOM traversal
SetshadowDOM: true to allow advanced-mark.js to descend into shadow roots when searching for text to highlight:
Shadow DOM traversal only works with shadow roots that have
mode: 'open' and that have already been created before mark() is called. Closed shadow roots (mode: 'closed') are not accessible.Custom styles in shadow DOM
Because shadow roots use encapsulated styles,mark {} rules defined in the main document’s stylesheet do not apply inside a shadow root. Use the shadowDOM object form to inject a <style data-markjs> element directly into the shadow root:
CSS Custom Highlight API in shadow DOM
When using the CSS Custom Highlight API, add the::highlight() pseudo-element rule to the shadowDOM style property so that the highlight is styled correctly inside the shadow root:
Using inline styles as an alternative
If you need fine-grained per-element control without injecting a shared stylesheet, you can apply inline styles inside theeach callback. A shadow root is a DocumentFragment, so you can detect it by checking nodeType:
Removing shadow DOM styles
To remove an injected style from a shadow root, callunmark() with the shadowDOM style option set to any string value:
iframes
Enabling iframe traversal
Setiframes: true to allow advanced-mark.js to search inside <iframe> elements on the page:
iframe traversal only works with same-origin iframes. Cross-origin iframes are subject to browser security restrictions and cannot be accessed.
Custom styles in iframes
Like shadow roots, iframes have their own style scope. Use theiframes object form to inject a <style data-markjs> element into the iframe’s <head>:
::highlight() rule to the iframe style:
The style element is injected into every matching iframe regardless of whether that iframe contains any matches.
iframesTimeout
If an iframe is still loading whenmark() is called, the library waits up to iframesTimeout milliseconds before skipping that iframe. The default is 5000 ms:
Removing iframe styles
To remove an injected style from iframes, callunmark() with the iframes style option set to any string value: