Skip to content

feat: Add shadow DOM support to ANDI#275

Draft
jasonday wants to merge 6 commits intoSSAgov:masterfrom
jasonday:master
Draft

feat: Add shadow DOM support to ANDI#275
jasonday wants to merge 6 commits intoSSAgov:masterfrom
jasonday:master

Conversation

@jasonday
Copy link

@jasonday jasonday commented Dec 2, 2025

Caution

This pull request is for informative purposes/communication only.

Proof of concept for adding Shadow DOM support to ANDI. I have not ironed out all of the kinks, but do have ANDI providing information about elements (such as form fields) within shadow roots. I haven't tested across all ANDI functionality, nor all types of shadow DOM components.

Testing

javascript:void((function(){andiHost='https://work.jasonbyday.com/';andiScript=document.createElement('script');andiScript.src=andiHost+'ANDI/andi.js';document.body.appendChild(andiScript);function andiCSPcheck(){if (typeof andiVersionNumber === 'undefined')alert('This page has a Content Security Policy that blocks scripts like ANDI. For help, visit the ANDI Help FAQ page.');window.open(andiHost+'andi/help/faq.html#csp');};document.addEventListener('securitypolicyviolation',andiCSPcheck);setTimeout(function(){document.removeEventListener('securitypolicyviolation',andiCSPcheck),100});})());

URL

https://staging.va.gov/mock-form-patterns/name-and-date-of-birth

shadow DOM component

<va-text-input label="First name" maxlength="30" minlength="1" name="root_fullName_first" required="true" uswds="true" autocomplete="given-name" value="" type="text" class="rjsf-web-component-field hydrated" show-input-error="">
    <template shadowrootmode="open">
        <div class="input-wrap">
            <label for="inputField" id="input-label" class="usa-label ANDI508-relatedLaserTarget" part="label" data-andi508-relatedlaserindex="0">First name<span class="usa-label--required"> (*Required)</span></label>
            <slot></slot><span id="input-error-message" role="alert" class=""></span>
            <div class="">
                <input class="usa-input ANDI508-element ANDI508-highlight ANDI508-element-active" id="inputField" type="text" aria-invalid="false" maxlength="30" name="root_fullName_first" autocomplete="given-name" required="" part="input" data-andi508-index="13">
            </div>
        </div>
    </template>
</va-text-input>

ANDI-update screenshot

shadow DOM - first name is focused

google-labs-jules bot and others added 6 commits December 2, 2025 15:16
This change updates the ANDI bookmarklet to correctly identify and inspect elements located within a shadow DOM.

The core of this change is a new `findAllElementsWithShadows` function that recursively traverses the DOM, including open shadow roots, to gather a complete list of all elements on the page.

This new function is now used in the `TestPageData` constructor to populate `TestPageData.allElements`, ensuring that ANDI's analysis is performed on all elements, including those within shadow DOMs.

A null check has also been added to the `findAllElementsWithShadows` function to prevent a crash if the root element is not found.
Add shadow DOM support to ANDI - Proof of concept. There are still some things not being reported, but it is returning information about elements within the shadow DOM. 

See screenshots in comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant