Javascript not executing in Shopify theme customiser Custom Liquid sections

I’m fairly new to developing in the Shopify environment. Although the issue I’m currently encountering doesn’t seem particularly complicated, but it has me stumped.

The theme in use is Dawn, although I don’t think that should make any difference.

I have some JS I wanted to run on pages that use a particular template (product.warranty.json), which has been constructed in the theme customizer.

I added the JS using a “Custom Liquid” section in the template, via the customizer.

The original JS I tried adding was executing, but wasn’t identifying the target of the trigger, so I started adding in some console.log debug checks, yet nothing was appearing in the console.

I’ve now put together some debugging code to figure out what’s going on. But that’s not executing either. For instance, Debug script loaded doesn’t output to the Console.

What am I overlooking?

<script>
    console.log('Debug script loaded');

    document.addEventListener('DOMContentLoaded', function() {
        console.log('DOM fully loaded and parsed');

        function checkElementAvailability() {
            const formSelector = 'form[data-id="50018"]';
            const submitButtonSelector = "#globo-formbuilder-50018 > div > div > div > form > div.globo-formbuilder-wizard > div > div.gfb__footer.wizard__footer > button.action.next.submit.flat-button.wizard__submit";

            let startTime = Date.now();

            function logStatus() {
                const currentTime = Date.now();
                const elapsedTime = currentTime - startTime;

                const form = document.querySelector(formSelector);
                if (form) {
                    console.log(`[${elapsedTime}ms] Form with data-id 50018 found`);

                    const submitButton = form.querySelector(submitButtonSelector);
                    if (submitButton) {
                        console.log(`[${elapsedTime}ms] Submit button found`);
                    } else {
                        console.log(`[${elapsedTime}ms] Submit button not found yet`);
                    }
                } else {
                    console.log(`[${elapsedTime}ms] Form not found yet`);
                }

                setTimeout(logStatus, 50);
            }

            logStatus();
        }

        checkElementAvailability();
    });
</script>