Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background Geolocation / Geofencing + postMessage demo #496

Open
FluorescentHallucinogen opened this issue Jan 28, 2025 · 1 comment
Open

Comments

@FluorescentHallucinogen

As you may know, background geolocation doesn't work on the web.

The problem is that the Web Geolocation API immediately stops working as soon as the page goes from foreground to background (the
tab is closed / not focused or browser / installed PWA minimized or closed).

Moreover, Geolocation API isn't available in Service Workers.

Without background geolocation, a whole bunch of apps simply can't be implemented as PWAs! :(

Is it possible to implement background geolocation natively and use postMessage (https://developer.chrome.com/docs/android/post-message-twa)
to pass coordinates data from Android native code to JavaScript (the page code or service worker)?

I've tried to combine the https://github.com/GoogleChrome/android-browser-helper/tree/main/demos/twa-post-message demo with official demos from Android docs:

but, unfortunately, so far without success. :(

I'm not an Android developer. The problem is that postMessage demo is written in Java, but official demos from Android docs are written in Kotlin.

What about creating a demo for Background Geolocation / Geofencing + postMessage?

The result demo could be published in the https://github.com/GoogleChrome/android-browser-helper/tree/main/demos/
as a very useful sample of "hybrid" TWA app that would help the whole community a lot!

Ideally, this should be a plug-in (module/extension) for Bubblewrap (https://github.com/GoogleChromeLabs/bubblewrap) that can be enabled/disabled in options like other features in Bubblewrap.

BTW, Bubblewrap is written in Java, not Kotlin.

Maybe it's possible to combine them into one demo without rewriting them into one language? Although all 3 demos are small.

@FluorescentHallucinogen
Copy link
Author

And the main question: is it possible at all to receive "message" events generated with postMessage in TWA (and send messages back to native code), in Service Worker instead of Window (if the page is closed)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant