Fix intermitent Safari bug

This fixes an intermittent bug that @aadsm discovered in a particular version of Safari, as described in the comments.