Hacker News new | ask | show | jobs
by Timja 1076 days ago
Is this Capacitor specific code?

Here it seems the JS code can fetch data from any domain:

https://github.com/kaangiray26/geddit-app/blob/main/src/js/g...

Since that is not possible in the browser, is that something Capacitor provides?

2 comments

you can always fetch data from any domain, iff that server sets the correct CORS headers, unless I'm misunderstanding.

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Most servers don't set a CORS header though.

So usually it does not work in the browser.

Try this in your console while not on Reddit:

    fetch('https://www.reddit.com/.json')
CORS is a browser security measure to protect users from malicious sites. This is an app and not a web browser and is therefore allowed to send HTTP requests to any URL it wants and to parse the HTTP responses as it deems necessary.