6

When running capacitor for android, GET requests to my API aren't working, and I am getting weird headers (Client-Via:shouldInterceptRequest) as well as the fact that the request is served from disk cache. also the request is having incorrect Content-Type of Content-Type:text/html instead of JSON enter image description here Using capacitor ionic V1.0.0

While running the request from the browser, or capacitor IOS it's working totally fine and the request is being served from the network as well with the correct headers.

Browser response: enter image description here

Any idea of why my webview requests are being intercepted like this? Thanks.

BarakD
  • 538
  • 8
  • 18

1 Answers1

6

Managed to find the solution, and decided to post the question & answer for others to come across this issue.

The root cause was that my server URL was also in my capacitor.config.json under the allowNavigation config.

Thus GET requests were intercepted by capacitor. Removing my server URL from allowNavigation solved the issue. before:

{
  "appId": "app.com",
  "appName": "app",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "dist",
  "server": {
    "allowNavigation": [
        "my-server-url.com",
      ]
  },
  "android": {
    "allowMixedContent": true
  }
}

the corrected config:

{
  "appId": "app.com",
  "appName": "app",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "dist",
  "server": {
    "allowNavigation": []
  },
  "android": {
    "allowMixedContent": true
  }
}
BarakD
  • 538
  • 8
  • 18
  • 1
    You save my day! On a similar problem. To be able to Catch `Deep Links /App links` for HTTP(s) schema, the host URL must not be in allowNavigation. – sl45sms Aug 26 '20 at 13:16