Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fetch() works on simulator but not on device: TypeError: Failed to fetch

Hi,

The following function runs fine on the simulator, but when using the developer bridge and a real device I get "Something went wrong: TypeError: Failed to fetch". Hoping this would be resolved by release 3.13, but so far no luck unfortunately. Any ideas? 

 

function storeSet(set) {
  //ToDo remove unnessecary code after csrf token balooba
  console.log("Storing set: " + JSON.stringify(set));
  fetch(sets_url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(set)
  })
  .then(()=>console.log("Set stored!"))
  .catch((err) => {
    console.log("Something went wrong: " + err);
  });
}

 

 

package.json:

{
  "name": "******",
  "version": "0.1.0",
  "private": true,
  "license": "UNLICENSED",
  "devDependencies": {
    "@fitbit/sdk": "~4.1.0",
    "@fitbit/sdk-cli": "^1.7.1"
  },
  "fitbit": {
    "appUUID": "***",
    "appType": "app",
    "appDisplayName": "***",
    "iconFile": "resources/icon.png",
    "wipeColor": "#ffffff",
    "requestedPermissions": [
      "access_internet",
      "run_background"
    ],
    "buildTargets": [
      "higgs",
      "meson",
      "gemini",
      "mira"
    ],
    "i18n": {},
    "defaultLanguage": "en-US"
  },
  "scripts": {
    "build": "fitbit-build",
    "debug": "fitbit"
  }
}
Best Answer
17 REPLIES 17

http or https?

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Same problem with both 

Best Answer
0 Votes

access_internet permission?

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Yes I've added the permission but same problem. 

Best Answer
0 Votes

What's `sets_url`? Mask anything sensitive.

Best Answer
0 Votes
Best Answer
0 Votes

Is it possible there's an issue with your server implementation? You can verify the Fitbit app companion code is working by running kWS and testing a fetch().

 

https://play.google.com/store/apps/details?id=org.xeustechnologies.android.kws&hl=en

Best Answer
0 Votes

Seems to be the same issue no matter what url I use. Even though I'm running my server in debug mode I cannot see any sight that a request is being received. 

Best Answer
0 Votes

Which version of Android are you using?

Best Answer
0 Votes
I`m on a Huawei P30 running Android 10
Best Answer
0 Votes

And you're definitely using the 3.13 Fitbit app?

How did you get on with kWS?

Best Answer
0 Votes

Yes positive :

Screenshot_20200123_230351_com.fitbit.FitbitMobile.jpg

Same thing with kws, no sign of any request being received. Do you have any tips on how to debug this programmatically? Where is the error message "Failed to fetch" thrown from? Sounds pretty generic 

Best Answer
0 Votes

Chech your device webview version: it might need to support fetch https://caniuse.com/#feat=fetch

@JonFitbit does fitbit app polyfill the fetch function?

If not, there may be Android devices stuck with chrome 38 that has no fetch.

Best Answer
0 Votes

Well, I installed the latest version of Android System Webview but same problem. I think I will try a different phone and see if things change 

Best Answer
0 Votes

Any update on this issue?  Did you get it working?  I am trying to send requests (fetch) to a local home automation server in the 10.x.x.x range.  Not working with HTTPS (self-signed) or HTTP.  Dev API documentation says it should work if by IP to local computers.

Best Answer
0 Votes

@TechFan7 No unfortunately I've not gotten it to work. Tried two different phones after the last update, Huawei P3 and an iPhone 6S but still got the same error. So I've basically given up for now. What phone and app version are you using? 

Best Answer
0 Votes

I was just about to start developing for an internal system. . .and have run into this.  I have Pixel 3a and with Android 10.  It appears I have version 3.18.

Best Answer
0 Votes