miagi-anhph opened a new issue, #1658: URL: https://github.com/apache/cordova-ios/issues/1658
# Bug Report ## Problem ### What is expected to happen? When `<preference name="scheme" value="https" />` is set in `config.xml`, WKWebView should use `https://localhost` as the origin, allowing CORS requests to external APIs to work as they did in cordova-ios 7. ### What does actually happen? cordova-ios 8 ignores the `scheme` preference when set to `https` because `CDVWebViewEngine.m` checks `[WKWebView handlesURLScheme:scheme]` — which returns `YES` for `https` — and falls back to `app://localhost`. This causes all XHR/fetch requests to external APIs to fail with: ``` Failed to load resource: Origin app://localhost is not allowed by Access-Control-Allow-Origin. Status code: 204 ``` The app is stuck on the splash screen because the initial API call fails due to CORS rejection. The relevant code in `CDVWebViewEngine.m` (line ~181): ```objc if(scheme == nil || [WKWebView handlesURLScheme:scheme]){ scheme = @"app"; self.viewController.appScheme = scheme; } ``` This means there is **no way** to set a scheme that external servers will accept via CORS, since: - `https` is rejected by WKWebView (already handled internally, cannot register custom URLSchemeHandler — causes crash) - `app` is a custom scheme that most servers don't include in `Access-Control-Allow-Origin` - Any other custom scheme (e.g. `ionic`) has the same CORS problem as `app` I also tried applying the fix from [#1632](https://github.com/apache/cordova-ios/pull/1632/files) (re-adding the deprecated `shouldOverrideLoadWithRequest:navigationType:` selector), but it was already present in cordova-ios 8.0.1 and does not resolve the CORS issue. ## Information ### Command or Code `config.xml`: ```xml <preference name="scheme" value="https" /> <preference name="hostname" value="localhost" /> ``` API calls are made via jQuery `$.ajax` (XMLHttpRequest) to external HTTPS endpoints. All requests fail at the CORS preflight stage (OPTIONS returns 204 but rejects `Origin: app://localhost`). ### Environment, Platform, Device - Device: iPhone SE 2nd gen (iPhone12,8), iOS 18.7.9 - macOS: 15.7.5 - Xcode: 26.2 (Build 17C52) ### Version information - Cordova CLI: latest - cordova-ios: 8.0.1 - cordova-plugin-inappbrowser, cordova-plugin-fcm-with-dependecy-updated, and other standard plugins - jQuery 3.6.0, AngularJS 1.7.8 (for HTTP calls) ## Checklist - [x] I searched for existing GitHub issues - [x] I updated all Cordova tooling to most recent version - [x] I included all the necessary information above -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
