Pass JS value to Hubspot embedded form

Hi, I have a hidden field in my JS form called “urlprefill”.

I want to pass the following JS value from my landing page to the form: window.__CONVERDY__.dkiDefaults[“url”];

I have tried adding different things to the hbspt.forms.create() function but none of them worked. How can I pass the value to the form?

My latest code:

<script charset=“utf-8” type=“text/javascript” src=“//js.hsforms.net/forms/embed/v2.js”></script>
<script>
function createForm() {
hbspt.forms.create({
region: “na1”,
portalId: “XXXXXXX”,
formId: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,
onFormReady: function (form) {
console.log(‘form ready’);
if(window.__CONVERDY__ && window.__CONVERDY__.dkiDefaults){
form.querySelector(‘input[name=“urlprefill”]’).value = window.__CONVERDY__.dkiDefaults[“url”];
}
}
});
}

var retries = 0;
function retryCreatingForm() {
if (retries >= 10) {
console.log(“Error: Could not create form after 10 retries”);
return;
}

if (window.__CONVERDY__ && window.__CONVERDY__.dkiDefaults) {
createForm();
console.log(“Form created”);
console.log(window.__CONVERDY__.dkiDefaults[“url”]);
} else {
retries++;
console.log("Retrying to create form: Attempt " + retries);
setTimeout(retryCreatingForm, 1000);
}
}

window.addEventListener(“load”, retryCreatingForm);
</script>