It looks like changing the above to ```element = element.parentNode``` fixes the issue with ShadowDom