Fixing browser location api infinite loop