Skip to main content

Module browser

Module browser 

Source
Expand description

The most simplest of location mechanism that uses the native browser to fetch location info about current device. This module provides __location__, a versatile function that works with both sync and async contexts.

The browser will prompt the user for location permission upon acceptance, the location data will be returned back.

  1. Binds a temporary HTTP server on a random localhost port using the socket-server module.
  2. Opens the system’s default browser to a consent page served by that server (using the webbrowser crate — works on macOS, Windows, and Linux).
  3. The browser prompts the user for location permission via the standard navigator.geolocation.getCurrentPosition Web API.
  4. On success the browser POSTs the coordinates back to the local server, which shuts itself down and returns the data to the caller.

Structs§

LocationData
Geographic coordinates returned by the browser Geolocation API.

Enums§

LocationError
Errors that can be returned by __location__.
PageTemplate
Controls what the user sees in the browser when __location__ is called.

Functions§

__location__
Capture the user’s geographic location by opening the browser to a local consent page.
__location_async__
Async version of __location__.