Fetch() not working on Android

I’m using fetch() to get web pages, which I then display. This works fine on iOS and in Chrome on the desktop. But using the Android emulator, I can’t seem to get web pages. The fetch returns without error, but when I try to access the returned data, I can’t. If I do a simple console.log() of the response.text(), the log entry never shows up in Android Studio (if I surround that line with other console.log() lines, those do show up). I can display the length of the response, but I can’t see/do anything with the data. Again, this all works on iOS and Chrome on the desktop. I’m using the Pixel_3a_API_30_x86 emulator in Android Studio.

EDIT: The network call never appears to happen.

Is this a permissions issue? I’m using https for the calls.

Following up on this. The problem was as follows. I was setting the server.hostname in the capacitor.config.json file to the domain of our service. On iOS, xhr calls into that domain would succeed. On Android, however, those calls would always just return our local index.html file.

In the end, I switched to using the HTTP community plugin and now everything works as expected.

1 Like