capacitor-community / background-geolocation

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

Using capacitors own HTTP module/plugin to solve the loss of location updates causes issues with the firebase sdk #101

Closed JTCorrin closed 1 year ago

JTCorrin commented 1 year ago

Describe the bug

I've an app that requires background-geolocation (so thanks for putting this plugin together!). It's a straightforward Vue3 and Capacitor setup.

I'm experiencing the "location updates fail after a certain amount of time" issue that has been mentioned in a few previous issues (here for example)

You mention here that we should use a native HTTP module to get around this.

The introduction of the native HTTP module from Capacitor seems to block firebase's js sdk from working.

Both on ios or android the error output for lots of calls looks like this:

TO JS {"url":"https:\/\/firestore.googleapis.com\/google.firestore.v1.Firestore\/Listen\/channel?database=projects%2FMY-PROJECT%2Fdatabases%2F(default)&VER=8&RID=rpc&SID=9nR2u6nG8qTh7mXxsUpXbQ&CI=0&AID=0&TYPE=xmlhttp&zx=m5em9kc4kwhr&t=1","data":"<!DOCT

⚡️  [warn] - [2023-04-22T14:51:52.422Z]  @firebase/firestore: Firestore (8.10.1): Connection WebChannel transport errored: [object Object]

⚡️  [error] - [2023-04-22T14:51:52.423Z]  @firebase/firestore: Firestore (8.10.1): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

⚡️  To Native ->  CapacitorHttp request 62249784
2023-04-22 16:51:52.475173+0200 App[6009:63443] [NSURLSession sharedSession] may not be invalidated

I recognise this is not necessarily a problem with this repo, but just wanted to see if the community had experienced anything similar or if anyone knows any fix?

I've created an issue on the capacitor main repo here

To Reproduce Simply add the following to a capacitor.config.ts file:

CapacitorHttp: {
    enabled: true,
},

Removing the above resumes normal functioning of the app (and back to background locations for 5 to 10 mins)

Expected behavior I'd expect the background geolocation to work without further config.

Desktop (please complete the following information):

kevinsimper commented 1 year ago

@JTCorrin You can use the native http module without enabling patching of fetch calls :)

https://capacitorjs.com/docs/apis/http#example