capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
180 stars 56 forks source link

Add support for web location tracking #31

Open antonioberetini opened 3 years ago

antonioberetini commented 3 years ago

Is your feature request related to a problem? Please describe. There is no reason why this plugin is not supporting browser location tracking via service worker as well

Describe the solution you'd like If a user is using capacitor app in a browser, user should be able to give permission to track location to the application. If permission is granted, service worker continues collecting locations in the background.

Describe alternatives you've considered This is a standard so no need for alternatives

Additional context iOS Safari supports this only while app is used. Soon it may add support for service worker background updates too.

diachedelic commented 3 years ago

Interesting! Can you point to me to any implementations which use this approach?

antonioberetini commented 3 years ago

I would suggest reading this as it explains how background synchronization api works. To my know ladge some browsers require to have one windows open to be able to consistently track location but I am hearing that it now it works in most browsers even when the browser is not opened at all.

https://dzone.com/articles/how-to-build-a-progressive-selfies-web-app

From: @.> Sent: Wednesday, July 14, 2021 8:20 PM To: @.> Cc: Tony @.>; @.> Subject: Re: [capacitor-community/background-geolocation] Add support for web location tracking (#31)

Interesting! Can you point to me to any implementations which use this approach?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/capacitor-community/background-geolocation/issues/31#issuecomment-880315665, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APUUMICTTHH3JQAYXYFJC53TXYZVVANCNFSM5ALT4NPA.

diachedelic commented 3 years ago

The example you posted does not appear to use the Geolocation API from a service worker. May I ask you where you heard this is possible? Background geolocation in the browser is a huge point of contention, which I would not expect to be quietly resolved.

antonioberetini commented 3 years ago

Both edge and chrome support always on feature so you don’t really need a service worker to run this in the background. As long as the browser is running in the background location tracking works even if the browser is not in focus. I am happy to test this out for you. https://itigic.com/prevent-edge-chromium-running-in-the-background/

Get Outlook for iOShttps://aka.ms/o0ukef


From: diachedelic @.> Sent: Thursday, July 15, 2021 10:02:49 PM To: capacitor-community/background-geolocation @.> Cc: Tony Beretini @.>; Author @.> Subject: Re: [capacitor-community/background-geolocation] Add support for web location tracking (#31)

The example you posted does not appear to use the Geolocation API from a service worker. May I ask you where you heard this is possible? Background geolocation in the browser is a huge point of contention, which I would not expect to be quietly resolved.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/capacitor-community/background-geolocation/issues/31#issuecomment-881141294, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APUUMIHBFLLK5OD2TG4KWT3TX6ONTANCNFSM5ALT4NPA.

diachedelic commented 3 years ago

Oh I see, that's useful. Could you please link me to the documentation for that browser feature?

antonioberetini commented 3 years ago

There is nothing really to link to, it’s a feature called startup boost which is enabled by default. A user can disabled it but it ships with it enabled. https://winaero.com/enable-or-disable-startup-boost-in-microsoft-edge/

Get Outlook for iOShttps://aka.ms/o0ukef


From: diachedelic @.> Sent: Friday, July 16, 2021 12:14:42 AM To: capacitor-community/background-geolocation @.> Cc: Tony Beretini @.>; Author @.> Subject: Re: [capacitor-community/background-geolocation] Add support for web location tracking (#31)

Oh I see, that's useful. Could you please link me to the documentation for that browser feature?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/capacitor-community/background-geolocation/issues/31#issuecomment-881183068, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APUUMIGHGQISHNFQJDPVAVDTX654FANCNFSM5ALT4NPA.

ecofriend commented 2 years ago

this feature would be helpful for prototyping and troubleshooting as well as I'm not sure where the console.log in the example prints out to.

HarelM commented 1 year ago

I'm not sure this is possible yet unfortunately, I've been waiting for this for a long time... See here: https://github.com/w3c/geolocation-api/issues/13 https://github.com/w3c/geolocation-api/issues/74 https://github.com/w3c/geolocation-sensor/issues/44

Having said that, we could implement a web API that follows the plugin's API and allow "regular" location with the same API of this plugin (using navigator under the hood). In time and as the browsers implement (hopefully) the relevant required behavior we could implement the needed features so that users of this plugin won't need to change their code.

This is just a thought. Feel free to correct me or suggest otherwise. BTW, in theory, if the webview implements this, there might not be an actual need for this plugin, but that's a different story. I like the original idea behind Cordova that the main goal is not to exist in the end since browsers should simply implement the relevant native APIs :-)

diachedelic commented 1 year ago

It might be worth testing to see if any browser/device combination actually does support geolocation in the background using navigator.geolocation. If it turns out to be possible, I would consider adding web support to the plugin. But I am yet to hear a persuasive use case for adding foreground-only web support to this plugin.

HarelM commented 1 year ago

Besides the background ability, there's the consistent API requirement, from my point of view. The following is my code to get location in my app which is running as a web site and as a capacitor app: https://github.com/IsraelHikingMap/Site/blob/034010910e30ea97315c809a4ca63ecf733179d0/IsraelHiking.Web/src/application/services/geo-location.service.ts This code is littered with if capacitor statements which will be redundant in case this plugin would also support the web platform. In theory this plugin can implement the navigator w3c spec and thus aligning the implementation with web standards, but that's a whole different story. :-)