npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ajuarezso/capacitor-background-geolocation-firestore

v0.1.3

Published

Capacitor plugin that combines background geolocation with native Firestore writes. The foreground service writes location updates directly to Firestore from native code (Java/Swift) using the Firebase Admin SDK, bypassing the JS bridge. This solves the A

Downloads

587

Readme

@ajuarezso/capacitor-background-geolocation-firestore

Capacitor plugin that combines background geolocation with native Firestore writes. The foreground service writes location updates directly to Firestore from native code (Java/Swift), bypassing the JS bridge — so location tracking keeps working even when the Capacitor WebView is suspended in Android 14+ background mode.

Why this plugin exists

Standard Capacitor background-geolocation plugins (@capgo/background-geolocation, @capacitor-community/background-geolocation) all deliver location callbacks through the JS bridge. On Android 14+, when the app goes to background, the WebView suspends JS execution — the native service keeps running and queues callbacks, but they don't reach JS until the WebView resumes. The result: a delivery driver's app shows no location updates for the customer until the driver re-opens the app.

The only existing solution is @transistorsoft/capacitor-background-geolocation — commercial, ~$300/year. This plugin is the free open-source equivalent: it writes location updates directly from Java/Swift to Firestore using the Firebase SDK, without going through the JS bridge.

Status

v0.1.0 feature-complete — pending physical device validation.

| Component | Status | |---|---| | TypeScript API + definitions | ✅ Done | | Web fallback (browser dev) | ✅ Done | | Package scaffold (npm/rollup/tsconfig) | ✅ Done | | Android native (Java + Firebase Firestore SDK) | ✅ Done (Plugin + Service + FirestoreWriter, validated via gradle assemble) | | iOS native (Swift + FirebaseFirestore framework) | ✅ Done (Plugin + Service + FirestoreWriter, code complete) | | Plugin↔Service wiring | ✅ Done (static singleton + 100/200/400ms retry-backoff) | | Authentication / ID token refresh | ✅ Done (delegated to Firebase Auth SDK native — auto-refresh) | | Headless mode (survives WebView suspension) | ✅ Done (native writes don't depend on JS bridge) | | README ES | ✅ Done | | CHANGELOG | ✅ Done | | MIGRATION guide (from Capgo) | ✅ Done | | Architecture doc | ✅ Done | | Troubleshooting guide | ✅ Done | | Examples (Angular delivery driver) | ✅ Done | | Unit tests (Java + Swift, 12 each) | ✅ Done | | CI workflow | ✅ Done | | Offline queue (SQLite Android / JSON iOS) | ✅ Done | | Physical device validation | 🚧 Pending | | npm publish | 🚧 Pending (token expired, regenerate to publish) |

API

import { BackgroundGeolocationFirestore } from '@ajuarezso/capacitor-background-geolocation-firestore';

// 1. Start the watcher
await BackgroundGeolocationFirestore.start({
  backgroundTitle: 'My App — Delivery in progress',
  backgroundMessage: 'Sharing location with the customer',
  distanceFilter: 5,    // Android: 5m to avoid FusedLocation rate limit
  requestPermissions: true,
}, (location, error) => {
  if (location) console.log('Foreground tick:', location);
});

// 2. Configure native Firestore writes — bypasses JS bridge
await BackgroundGeolocationFirestore.setFirestoreContext({
  docPath: 'drivers/abc123',
  locationField: 'currentLocation',
  projectId: 'my-firebase-project',
  idToken: await user.getIdToken(),
  writeThresholdMeters: 20,
});

// 3. Refresh the ID token every ~50 minutes (tokens expire at 60min)
setInterval(async () => {
  await BackgroundGeolocationFirestore.setFirestoreContext({
    ...options,
    idToken: await user.getIdToken(true),
  });
}, 50 * 60 * 1000);

// 4. When done
await BackgroundGeolocationFirestore.clearFirestoreContext();
await BackgroundGeolocationFirestore.stop();

How it works (planned implementation)

Android

  1. Foreground service with android:foregroundServiceType="location" (inherited from base plugin)
  2. LocationCallback.onLocationResult triggers on every fix
  3. Distance throttle in Java (default 20m write threshold)
  4. Firebase Firestore Android SDK (com.google.firebase:firebase-firestore) writes the doc using the stored ID token
  5. notifyListeners("firestoreWrite", ...) emits to JS for diagnostics — but the write succeeds regardless of JS state

iOS

  1. Background location authorization (Always)
  2. CLLocationManagerDelegate.locationManager(_:didUpdateLocations:) triggers on every fix
  3. Same throttle + Firebase Firestore iOS SDK pattern

ID Token refresh

The JS layer must call setFirestoreContext again before the current token expires (Firebase Auth tokens last 1 hour). The plugin doesn't auto-refresh — that's the consumer's responsibility, because token refresh requires the Firebase Auth SDK which is JS-side.

Roadmap

  • [ ] Physical device validation (Android 14+ background suspension scenario, iOS Always-authorization flow)
  • [ ] Publish to npm (token regeneration pending)
  • [ ] Geofencing native events (entered/exited zone) — fired from Java/Swift without JS bridge
  • [ ] Motion activity detection (still/walking/driving) to adapt distanceFilter dynamically
  • [ ] Integration test app (Capacitor sample driving the full lifecycle)
  • [ ] Battery telemetry diagnostics

License

MIT © Anthony Juarez Solis