Just changing
if velocity.x < 0: sprite.set_flip_h(true)
else : sprite.set_flip_h(false)
to
if velocity.x < 0: sprite.set_flip_h(true)
elif: velocity.x > 0: sprite.set_flip_h(false)
This caused me no issues in all of my testing, and only seems to be an issue in browser