Geolocation API in Safari 8 and 7.1 keeps asking permission
Asked Answered
R

3

15

I've built the Geolocation API into my webapp and all browsers are working fine. Except Safari 8 and 7.1. The browser keeps asking for permission after allowing or not allowing it and ends up in an infinite loop making the browser (tab) unusable. It's easily reproducible by just going to http://html5demos.com/geo in Safari.

Is there any fix for this or is this just a bug in Safari? I searched but couldn't find anything related.

enter image description here

Rosena answered 26/11, 2014 at 13:27 Comment(4)
I have two confirm dialogs - one from browser, one from system. While system is open - browser don't close. If I agree in system dialog - I can close the browser. Looks like a bug.Asuncionasunder
I think it's a bug as well. Maybe they fixed it in Yosemite?Cristalcristate
I'm experiencing this too and used the W3 school example. It'll request my location up to four times, but it's only ever the last input that takes effect. Also wrapped my function in jQuery's one() in an attempt to solve the problem.Daughtry
I'm getting this bug also, can't seem to get around this.Deodorize
H
26

Our team saw this too. At first we thought we might have been stuck inside some kind of loop that the other browsers ignored, so we instrumented the code and confirmed that the call was only happening once. We suspended JavaScript by forcing a breakpoint and the alerts kept coming (and coming, and coming...). At this point we were pretty sure the issue was not in our code.

On a whim I placed the call to the GeoLocation API inside a setTimeout (to allow the call stack to empty) and the problem went away. No idea why that would fix the issue. . .

Edit

Per request, I put up an example @ https://jsfiddle.net/r8hst2zp/1/

Hipped answered 10/2, 2015 at 16:7 Comment(6)
Came here because of a search for this issue, and this absolutely fixed the problem. Thanks!Bushelman
Ditto. I've struggled with this bug for a while (which at first was hidden behind another bug) and could never reproduce it. Turns out it was it - a team member had it happening live, so I piggybacked on it and saw that behaviour. This answer cleared it. Note that it doesn't always happen, either...Megasporophyll
Is there any better solution than this. Why hasn't safari fixed this yet.Gaullist
@Gaullist Because Safari suffers from the same thing all Apple products do - bare minimum bugfixing, improvement lifecycle or attention to issues unless forced to.Polybasite
@Chris Hi mate, are you able to put up a quick example of how you wrapped the GeoLocation within a setTimeout so I can get an idea of how to set it up?Polybasite
Yea. Added it to the answerHipped
E
1

i don't think it is a bug in safari, you can try the following example, it worked fine for me:

http://www.w3schools.com/html/html5_geolocation.asp

Epigeal answered 5/12, 2014 at 15:27 Comment(2)
I'm not getting the continuous asking for permission at that website. What happens when you go to html5demos.com/geo ?Rosena
I am getting the error on html5demos.com/geo but not here w3schools.com/html/html5_geolocation.asp. Weird...Burtonburty
B
1

Ok. So from the two answers from @MeMTn and @chris-camaratta, here is a few thoughts:

1)

On a whim I placed the call to the GeoLocation API inside a setTimeout (to allow the call stack to empty) and the problem went away. No idea why that would fix the issue. . .

I did the same in my angularjs app, and it works. Perfect!

2)

i don't think it is a bug in safari, you can try the following example, it worked fine for me: http://www.w3schools.com/html/html5_geolocation.asp

How come this works (in Safari!) without setTimeout?

In my angularjs application, the call to GeoLocation is one of the first things to happen when the page loads. I believe this is the case for almost all other applications/web pages. In the W3 example there is a clickable button that fires the call to GeoLocation when the user clicks it (which happens when the page has loaded).

By setting a timeout, we allow Safari to deal with some other stuff (that might have something to do with calling the GeoLocation API for all I know) for a few (milli)seconds.

If I set the timeout to < 10 the error is back, even on localhost. I think I will stick with 100 ms for now. But that is highly unfair for other, working browsers.

Bug or not it's clearly something with Safari.

Burtonburty answered 26/2, 2015 at 15:9 Comment(1)
Yea, this feels like a bug in Safari. Reiterating my earlier point, pausing JavaScript with a breakpoint didn't stop additional popups (as one would expect if it were an issue with our code). In our case the call stack was fairly large when we asked for location; setting the timeout effectively cleared it. The w3Schools example also had a small call stack, so whatever this is, Safari's call stack handling certainly appears to be a factor.Hipped

© 2022 - 2024 — McMap. All rights reserved.