0

I am trying to build a chrome webb extension that takes a user’s position and scans a database for values.

I currently have the popup appear and the button is clickable, but I do not have any place to collect the geolocation information.

I tried running it as an inline script, but that failed and I moved it to a .js file.

Does anyone know if this is possible?

Edit, code below:

   {
    "manifest_version": 2,
    "name": "test app",
    "version": "1.0",
    "permissions": ["activeTab", "geolocation"],
    "content_scripts": [
      {
        "matches": [
            "<all_urls>"
        ],
        "js": ["jquery-3.4.1.min.js", "geolocation.js"]
      }
    ],

    "browser_action": {
    "default_icon": "images/cart16.png",
    "default_popup": "popup.html"
    },
 "content_security_policy": "script-src 'self' https://example.com; object-src 'self'"
}

// Geolocation.js

    function getLocation(){
     if(navigator.geolocation)
        navigator.geolocation.getCurrentPosition(function(position){
          alert(position);
        });
      else
          console.log("geolocation is not supported");
};

//html

    <!DOCTYPE html>
<html>

<!-- <p>Click the button to get your coordinates.</p>

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

<p id="demo"></p> -->
<head>
    <title>Test</title>

</head>

<body>
    <h1>Test App</h1>
    <button id="scan">Check Now!</button>
    <script src="geolocation.js"> </script>

</body>
</html>
Xaldwyn
  • 7
  • 4
  • Can you show us your code? – Lajos Arpad Feb 25 '20 at 13:58
  • Added code. I have a content and background.js but they aren't connected to my extension right now. – Xaldwyn Feb 25 '20 at 14:30
  • 1
    Currently, this is your problem: https://stackoverflow.com/q/13591983/934239 You haven't completed the switch from inline code to separate file - you can't have an `onclick` attribute. – Xan Feb 25 '20 at 14:52

0 Answers0