I want to develop an Chrome Extension which would be compatible with Manifest Version 3, but I run into problem with getting current user's geolocation coordinates, which works with Manifest Version 2, but for Manifest Version 3 it throws that navigator.geolocation
is undefined.
Here are my manifest.json and background.js files:
manifest.json:
"name": "Chrome Extension MV3",
"description": "Learning all about Chrome Extensions Manifest Version 3!",
"version": "0.1.0",
"manifest_version": 2,
"background": {
"service_worker": "background.js"
},
"permissions": ["geolocation"]
}
background.js:
navigator.geolocation.getCurrentPosition((position) => {
const { latitude, longitude } = position.coords;
console.log(latitude, longitude);
});
Exact same thing is happening to me.
Works fine in chrome f12 console just not in extension i get the exact same error.
var getlocale = function() {
var geoSuccess = function(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
console.log(latitude);
console.log(longitude);
};
navigator.geolocation.getCurrentPosition(geoSuccess);
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.