Hi @metalheart ,
You can add the "defer" element to the page to specify that the script is executed after the page has finished parsing:
<script src="my-script.js" defer></script>
This is specified here: https://learn.microsoft.com/en-us/azure/active-directory-b2c/javascript-and-page-layout?pivots=b2c-custom-policy
Or you could use <body onload="script();">
There are some other solutions noted here, which you could leverage as well.
Let me know if this helps and if you run into any issues.
If the information helped you, please Accept the answer. This will help us and improve searchability for others in the community who may be researching similar questions.