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.

WKWebView - http://localhost same origin policy

See original GitHub issue

With ionic capacitor the used webview is fixed to WKWebView. This leads to the fact that the App is served internally via http://localhost if i understood this right. We did face some CORS issues, but so far we were able to solve them by configuring the servers which were owned or using JSONP API in case of the external Instagram API that was being used.

But we are facing now some issues regarding Google Ads, they get integrated via dynamic iframes, until now this wasn’t an issue. The iframes created by the ads seem to have some workarounds regarding Same Origin Policy (SOP). But lately a lot of the shown ads had shown some SOP error messages and the ads couldn’t be displayed correctly anymore.

Blocked a frame with origin "http://localhost:8237" from accessing a frame with origin "http://tpc.googlesyndication.com". Protocols, domains, and ports must match.

Are there some workarounds or configurations using the WKWebView that can be used to allow those iframes and requests? Or could it be possible to get rid of the localhost origin serving?

Some interesting WKWebView options regarding this topic that some one did point out: https://stackoverflow.com/questions/36013645/setting-disable-web-security-and-allow-file-access-from-files-in-ios-wkwebvi

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ryaacommented, Jan 3, 2019

I checked with the latest beta.13 and this is still problem on both iOS and Android. I noticed that on iOS the scheme to load the app resources is capacitor://localhost but on Android this is still http://localhost.

On Android the CORS error is as follows: Access to XMLHttpRequest at '<API_URL>' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

0reactions
ionitron-bot[bot]commented, Nov 11, 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

iOS WKWebView: Origin http://localhost:12344 is not allowed ...
I get the following error message: Origin http://localhost:12344 is not allowed by Access-Control-Allow-Origin.
Read more >
WkWebview local site Access Origin - Stack Overflow
I tried the exact same code with your folder structure and this worked for me so I think this error originates from the...
Read more >
Origin http://localhost:8080 is not allowed by Access-Control ...
Hi, I get a known error on implementing a http call to a json-file on a remote server. Using ionic serve works oke....
Read more >
Disable Same Origin Policy in iOS WKWebView with private API
Safari's Web Inspector has an option (Develop -> Disable Cross Origin Restrictions) to disable the same-origin policy for debugging.
Read more >
Using OAuth 2.0 for Web Server Applications | Authorization
These endpoints must adhere to Google's validation rules. ... ensure that the request and response originated in the same browser, ...
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