question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

android: xhr GET request aren't working if your server URL is in `allowNavigation` config

See original GitHub issue

Description of the problem: Having your server URL in allowNavigation, won’t allow you to make simple GET xhr requests on android. Because capacitor will intercept them as navigation requests.

Affected platform

  • Android
  • iOS
  • electron
  • web

OS of the development machine

  • Windows
  • macOS
  • linux

When my API URL is being added to the allowNavigation config. E.G

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

When my app is having a GET endpoint of my server. Calling it VIA regular browser or IOS returns the proper headers and response. image But on android webView, capticator intercepts the request. image note the served from disk cache and Content-Type:text/html , Client-Via:shouldInterceptRequest headers. In browsers or IOS the response returns the correct content-type which is application/json;

Capacitor version: 1.0.0 node version: v8.11.3 npm version: 6.9.0 CocoaPods version:

Steps to reproduce:

  • Have any API with a GET request.
  • Add the API url to allowNavigation config.
  • run and build andorid project with an XHR request to the server.

I wonder if capacitor could differentiate between XHR requests and navigation requests to address this issue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jcesarmobilecommented, Nov 18, 2019

thanks for the sample project, but it was already fixed in https://github.com/ionic-team/capacitor/pull/2146

0reactions
ionitron-bot[bot]commented, Nov 13, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XMLHttpRequest cannot load XXX No 'Access-Control-Allow ...
If the HTML document the JS runs in and the URL being requested are on the same origin (sharing the same scheme, hostname,...
Read more >
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, ...
Read more >
Tracking prevention in Microsoft Edge
This includes restricting the ability for that tracker to get or set cookies as well as access storage APIs such as IndexedDB and...
Read more >
Testing Your App | Cypress Documentation
If you've started your server, then you should see your application loaded and working. Step 3: Configure Cypress. If you think ahead, you'll...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Changed URL breakpoints to also pause when an HTML attribute is set that triggers a load ... Fixed XHR CORS requests getting logged...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found