Cannot find an element via JavaScript which does exist

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})`);