geolocation in XUL addon

Talk about add-ons and extension development.
Post Reply
Diamanti
Posts: 778
Joined: June 12th, 2008, 9:02 am

geolocation in XUL addon

Post by Diamanti »

When I use navigator.geolocation in web page work but non in a chrome page of XUL Firefox Addon.
How use geolocation in XUL Addon?
morat
Posts: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: geolocation in XUL addon

Post by morat »

Are you asking about WebExtensions or obsolete Legacy extensions?

Here is a WebExtension example that spoofs the navigator.geolocation object.

Geolocation (Location Guard)
http://addons.mozilla.org/firefox/addon/2699811

AMO search for Geolocation
http://addons.mozilla.org/firefox/search/?q=Geolocation
Diamanti
Posts: 778
Joined: June 12th, 2008, 9:02 am

Re: geolocation in XUL addon

Post by Diamanti »

I query for obsolete Legacy extensions.
The above link not refere to GeoLocation query but to GeoLocation setting change.
morat
Posts: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: geolocation in XUL addon

Post by morat »

The following code snippet outputs the latitude and longitude using the browser console in Firefox 95.

Code: Select all

(function () {
  new Promise(function (resolve, reject) {
    var geolocation = Components.classes["@mozilla.org/geolocation;1"].
      getService(Components.interfaces.nsISupports);
    geolocation.getCurrentPosition(resolve, reject);
  }).then(function (result) {
    console.log("latitude: " + result.coords.latitude);
    console.log("longitude: " + result.coords.longitude);
  });
})();
Instructions:

* set devtools.chrome.enabled pref to true
* open browser console (ctrl+shift+j)
* copy and paste code into browser console
* press enter to run

Browser Console command line
http://developer.mozilla.org/docs/Tools ... mmand_line
Last edited by morat on December 19th, 2021, 7:08 pm, edited 1 time in total.
Diamanti
Posts: 778
Joined: June 12th, 2008, 9:02 am

Re: geolocation in XUL addon

Post by Diamanti »

Components.classes["@mozilla.org/geolocation;1"]
work, ty.
Post Reply