geolocation permission doesn't work with Manifest Version 3 Chrome Extension

780 views
Skip to first unread message

Stefan Markovic

unread,
Nov 20, 2021, 10:10:30 PM11/20/21
to Chromium Extensions
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); });

Cuyler Stuwe

unread,
Nov 20, 2021, 10:20:02 PM11/20/21
to Stefan Markovic, Chromium Extensions
My guess is this is one of those permissions they gimped to “web standards” (like how we now need to use the web notification API that requires a prompt).

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/4b0b434c-598c-43c7-99f9-98fc5fb6d11dn%40chromium.org.

Stefan Markovic

unread,
Nov 20, 2021, 10:22:51 PM11/20/21
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, Stefan Markovic
But the docs aren't updated accordingly then...

Jackie Han

unread,
Nov 21, 2021, 12:58:49 AM11/21/21
to Stefan Markovic, Chromium Extensions
navigator.geolocation is only available in web pages, not available in background workers.

background.js in MV3 is a service worker, not a web page. You can open an extension page to use it.

--

Stefan Markovic

unread,
Nov 21, 2021, 4:10:36 PM11/21/21
to Chromium Extensions, Jackie Han, Chromium Extensions, Stefan Markovic
I see... so is there a way in MV3 to have an invisible page which can access regular web page APIs?
To make it easier to understand - extension I'm working on needs constant access to geolocation, as it's used to track location of device and prevent its theft.

hrg...@gmail.com

unread,
Nov 21, 2021, 6:20:15 PM11/21/21
to Chromium Extensions, zmst...@gmail.com, Jackie Han, Chromium Extensions
The only way to use APIs that are not available in a service worker is to open a visible tab or window. This is the approach that's has been officially suggested by the Extensions Team if a service worker does not suffice.

There's also a proposal to allow MV3 extensions to open headless windows, but so far it's just that, a proposal.

Nir Nahum

unread,
Dec 4, 2021, 3:51:03 PM12/4/21
to Chromium Extensions, hrg...@gmail.com, zmst...@gmail.com, Jackie Han, Chromium Extensions
You may want to add your use case here:

Mark Fratto

unread,
Aug 16, 2022, 2:07:20 PM8/16/22
to Chromium Extensions, Nir Nahum, hrg...@gmail.com, zmst...@gmail.com, Jackie Han, Chromium Extensions
Will those like us that use google admin to deploy extension as force installed have access to these API's in the background. Also since it no longer runs in the background our Chrome fleet extension dies when all chrome tabs are closed then only starts back up when a tab is opened.
Reply all
Reply to author
Forward
0 new messages