Kan een element niet vinden via JavaScript dat wel bestaat

Ah right, what you’ll want to do is add the url() part to the custom property value… so something like:

document.documentElement.style.setProperty('--profile-bg-img', `url(${userBg})`);