[3.4.0.24][J1] GPS not working in native browser (while working in other applications)

REPRODUCIBILITY (% or how often): 100%
BUILD ID = OS VERSION (Settings > About product): 3.4.0.24
HARDWARE (Jolla1, Tablet, XA2,…): Jolla 1
UI LANGUAGE: FR
REGRESSION: (compared to previous public release: Yes, No, ?): Yes, it was working with 3.3.

DESCRIPTION:

The native sailfish browser seems unable to get a GPS position. I tried different websites. Each time, it is the same, the prompt ask for permission, I accept, the GPS is starting (blinking GPS icon on home screen), the GPS position is found (GPS icon stop blinking), but nothing happened on the website (no position on the map for example). If I use Fennec from F-Droid and connect to the same website, it works as expected. If I open Jolla Maps, it works as expected too.

So the phone can get a GPS position, but it seems that the native sailfish browser can not get it.

PRECONDITIONS:

I am not using data for positioning, only the GPS equipment in the phone (something like Device only-mode in the location parameters).

STEPS TO REPRODUCE:

  1. Authorize GPS
  2. Open the native sailfish browser
  3. Go to https://www.openstreetmap.org
  4. Click on the icon to get your position
  5. Accept that openstreetmap.org can access to your position
  6. Wait until a fix is found (GPS icon stop blinking)

EXPECTED RESULT:

The map should show your current location.

ACTUAL RESULT:

Nothing is happening. On some websites, the loader icon continue to spin.

ADDITIONAL INFORMATION:

(Please ALWAYS attach relevant data such as logs, screenshots, etc…)
I don’t know how to get the sailfish browser logs, or the console.log() from the web pages. If you tell me what to do, I’ll be glad to help and provides them to ease debugging.

Have a nice day!

1 Like

I tested the following code, taken from w3schools:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>TEST GPS</title>
    </head>
    <body>
        <h1>Testing the GPS</h1>

        <button onclick="getLocation()">Try It</button>

        <p id="demo"></p>
    </body>

    <script>
        var x = document.getElementById("demo");
    
        function getLocation() {
          if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition, showError);
          } else {
            x.innerHTML = "Geolocation is not supported by this browser.";
          }
        }
    
        function showPosition(position) {
          x.innerHTML = "Latitude: " + position.coords.latitude +
          "<br>Longitude: " + position.coords.longitude;
        }
    
        function showError(error) {
          switch(error.code) {
            case error.PERMISSION_DENIED:
              x.innerHTML = "User denied the request for Geolocation."
              break;
            case error.POSITION_UNAVAILABLE:
              x.innerHTML = "Location information is unavailable."
              break;
            case error.TIMEOUT:
              x.innerHTML = "The request to get user location timed out."
              break;
            case error.UNKNOWN_ERROR:
              x.innerHTML = "An unknown error occurred."
              break;
          }
        }
    </script>
</html>

And… it works! If I click on the button and give the permission, my GPS coordinates are displayed.

So, what’s wrong on open street map?

I found a way to get some logs on this page: I used EMBED_CONSOLE=1 sailfish-browser.

This is what I get on openstreetmap.org:

ContentPermissionPrompt.js on message received: top:embedui:permissions, msg:{                                                                                                                                                                                                              
    "allow": true,                                                     
    "checkedDontAsk": false,                                           
    "id": "www.openstreetmap.org geolocation"
}                                                                      

JavaScript error: https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js, line 7: Error: Invalid LatLng object: (NaN, NaN)
CONSOLE: {"logLevel":3,"timeStamp":1604513555218,"message":"[JavaScript Error: \"Error: Invalid LatLng object: (NaN, NaN)\" {file: \"https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js\" line: 7}]\nS@https://www.openstr
eetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:11950\nk@https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:12173\nT.prototype.extend@https://www.openstreetmap.org/
assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:30062\nT@https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:11835\nC@https://www.openstreetmap.org/assets/application-f9e3c9c78
8a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:11893\nS.prototype.toBounds@https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:8:258\nHn<._handleGeolocationResponse@https://www.openstreetmap.org/assets/app
lication-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:8:13700\n","debug":0,"info":1,"warn":2,"error":3}


JavaScript error: https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js, line 7: Error: Invalid LatLng object: (NaN, NaN)
CONSOLE: {"logLevel":3,"timeStamp":1604513556145,"message":"[JavaScript Error: \"Error: Invalid LatLng object: (NaN, NaN)\" {file: \"https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js\" line: 7}]\nS@https://www.openstr
eetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:11950\nk@https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:12173\nT.prototype.extend@https://www.openstreetmap.org/
assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:30062\nT@https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:11835\nC@https://www.openstreetmap.org/assets/application-f9e3c9c78
8a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:7:11893\nS.prototype.toBounds@https://www.openstreetmap.org/assets/application-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:8:258\nHn<._handleGeolocationResponse@https://www.openstreetmap.org/assets/app
lication-f9e3c9c788a9c5fc4e78fc331240f47a594532c9a12aa671d2509f9062fabbc6.js:8:13700\n","debug":0,"info":1,"warn":2,"error":3}

[...]

The first part of the log is the permission prompt. Then, the error message is looping indefinitively. It seems that the coordinates are not parsed correctly.

Wrong format? Empty data? I don’t know yet. If someone has a clue or another test to propose, I am listening.

1 Like

Copied the code from @bananaMixer in a text file and named it GPS.html , copied on the phone and loaded with the SF browser. Result is, on screen appears
Testing the GPS
Try it
Geolocation is not supported by this browser.

Conditions: GPS running and have position fix, GPS info shows 12/32 satellites and the correct position.

TL;DR: Gelocation accuracy is NaN while it should be null or a double value. Help is needed to confirm the regression (test accuracy with the provided file on Sailfish 3.3 or before).


After some hours of debugging, I finally found the problem.

Openstreetmap.org and others web sites I was testing have one thing in common. They are all using Leaflet, which is a popular JS library for interactive maps. In the geolocation event callback, Leaflet is using three properties of the GeolocationCoordinates object: latitude, longitude and accuracy (sources). Unfortunately, accuracy is NaN, leading to the previously posted error when trying to compute the map bounds.

According to MDN, accuracy could be null, but should not be NaN.

I made some local test with the Leaflet library and was able to make it work correctly by changing the lines where the accuracy is used by a ternary operator: isNaN(pos.coords.accuracy)?0:pos.coords.accuracy*2.

Here is a simple page to test the geolocation API. It is almost the same as the previous one. I added the accuracy in the displayed information:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>TEST GPS</title>
    </head>
    <body>
        <h1>Testing the GPS</h1>

        <button onclick="getLocation()">Try It</button>

        <p id="demo"></p>
    </body>

    <script>
        var x = document.getElementById("demo");
    
        function getLocation() {
          if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition, showError);
          } else {
            x.innerHTML = "Geolocation is not supported by this browser.";
          }
        }
    
        function showPosition(position) {
          x.innerHTML = "Latitude: " + position.coords.latitude +
          "<br>Longitude: " + position.coords.longitude +
          "<br>Accuracy: " + position.coords.accuracy;
        }
    
        function showError(error) {
          switch(error.code) {
            case error.PERMISSION_DENIED:
              x.innerHTML = "User denied the request for Geolocation."
              break;
            case error.POSITION_UNAVAILABLE:
              x.innerHTML = "Location information is unavailable."
              break;
            case error.TIMEOUT:
              x.innerHTML = "The request to get user location timed out."
              break;
            case error.UNKNOWN_ERROR:
              x.innerHTML = "An unknown error occurred."
              break;
          }
        }
    </script>
</html>

On Sailfish browser 3.4, it is giving NaN for accuracy (while giving 0 on Fennec F-droid) . Can someone test it on Sailfish browser 3.3 or before to confirm there is a regression here?

To test, save the file as index.html in your home directory (/home/nemo/ for many people, /home/defaultuser/ for others) and open the following URL in your browser: file:///home/nemo/index.html.

In advance, thanks for your help!

@Seven.of.nine I am sorry to read that your GPS is not working. However, the problem seems different (here, GPS works, only accuracy seems to have a problem).

2 Likes

I’m also seeing the problem with GPS accuracy values being bonkers in Jolla1, even though GPS is locked and accurate.

I had a look at the dbus traffic on J1 when gpsinfo is running. The NaN values originate from geoclue-provider-hybris-hal GPS provider, which is closed source AFAIK. These are then propagated through QtPosititioning to sailfish apps (the browser might get the values directly from Dbus?).

Unless Jolla (the company) wakes up and fixes this, the problem could be possibly helped by changing the NaNs to nulls in QtPositioning. This would entail compiling a custom version of Qt, which is … blah.

1 Like