Recursive function doesn't work in variant script

I wrote a script in the script manager which utilizes a recursive function to query the DOM until an outside form is loaded onto the page. I tested this and it works when I add it to a domain in the script editor. However, when I added the exact same script to the variant page, I realized that the recursive function is never called. This is pretty baffling and I can’t think of any reason why this wouldn’t work. Is there a reason a recursive function wouldn’t work on a variant script?

Here is the relevant bit of code:


function waitForEmailInput(tries = 0) {
    if (tries === 100) return;
    var emailInput = document.querySelector('[type="email"][name="email"]');

    if (emailInput) {
    } else {
        setTimeout(function() {
            // When I log the function here I see it in the console, but it is never called
            waitForEmailInput(tries + 1)
        }, 300);