emeryberger/CSrankings

Failure to load when Geolocation is disabled in Firefox

yechs opened this issue · 0 comments

yechs commented

Observation

Gets stuck on "Computing ranking."

Console prints "navigator.geolocation is undefined"

Console output
Uncaught (in promise) TypeError: navigator.geolocation is undefined
    geoCheck https://csrankings.org/csrankings.js:1397
    CSRankings https://csrankings.org/csrankings.js:303
    fulfilled https://csrankings.org/csrankings.js:11
    promise callback*step https://csrankings.org/csrankings.js:13
    fulfilled https://csrankings.org/csrankings.js:11
    promise callback*step https://csrankings.org/csrankings.js:13
    fulfilled https://csrankings.org/csrankings.js:11
    promise callback*step https://csrankings.org/csrankings.js:13
    fulfilled https://csrankings.org/csrankings.js:11
    promise callback*step https://csrankings.org/csrankings.js:13
    fulfilled https://csrankings.org/csrankings.js:11
    promise callback*step https://csrankings.org/csrankings.js:13
    __awaiter https://csrankings.org/csrankings.js:14
    __awaiter https://csrankings.org/csrankings.js:10
    CSRankings https://csrankings.org/csrankings.js:287
    CSRankings https://csrankings.org/csrankings.js:340
    <anonymous> https://csrankings.org/csrankings.js:1802

Similar to (but different causes): #718

Steps to Reproduce

  1. Go into about:config in Firefox
  2. Set geo.enabled to false
  3. Visit https://csrankings.org/

Speculated cause

In Firefox, when geo.enabled is set to false, navigator.geolocation returns null.

Although not specified in the MDN API Doc, this behavior is introduced in a commit in 2011.

Possible solution

Surround the following code block with a if "geolocation" in navigator.
Or use optional chaining navigator.geolocation?.getCurrentPosition

CSrankings/csrankings.ts

Lines 1709 to 1726 in c7d9aeb

navigator.geolocation.getCurrentPosition((position) => {
const continent = whichContinent(position.coords.latitude, position.coords.longitude);
let regions = (<HTMLInputElement>document.getElementById("regions"));
switch (continent) {
case "northamerica":
return;
case "europe":
case "asia":
case "southamerica":
case "africa":
regions!.value = continent;
break;
default:
regions!.value = "world";
break;
}
CSRankings.getInstance().rank();
});