I found it confusing to have the onload handler defined above in a completely different context. I'd suggest you put the topImage.onload = function() {...} right here inside of startShare().