0

I have a google chrome extension. I'm trying to override the client's geolocation.

Previously, this code worked. However it's no longer working

    window.navigator.geolocation.getCurrentPosition = function(success, failure, options) { 
        const lat = parseFloat(localStorage.getItem("localLat"));
        const long = parseFloat(localStorage.getItem("localLong"));
      success({ coords: { 
          latitude: lat, 
          longitude: long,
      }, timestamp: Date.now() }); 
    }

I'm wondering if there is a way to get geolocation to work via a google chrome extension anymore or not?

Trevor Wood
  • 2,347
  • 5
  • 31
  • 56
  • This tutorial does just that. [How to make Chrome Extension 47 Get location information](https://youtu.be/tt7W5ZVf-EI) – Norio Yamamoto Nov 12 '22 at 05:30
  • You must run this code in [page context](/a/9517879) (see the link for ManifestV3 methods of doing it). The question doesn't describe where you run this code so I guess you were doing it in a script element using its textContent or innerHTML, which is incompatible with MV3. – wOxxOm Nov 12 '22 at 07:43
  • @wOxxOm thank you. Previously I created a script tag via js, added the geolocation function into the script then appended that script tag to the body of the page. Which worked, however in MV3 it no longer allows appending script tags. thanks for the resource I'll read it. If you can provide an example as an answer I'll gladly mark it correct. – Trevor Wood Nov 13 '22 at 05:30

0 Answers0