sonlichao commented on issue #1564: URL: https://github.com/apache/cordova-ios/issues/1564#issuecomment-3364229076
## Alternative Approach: Leverage Existing WKURLSchemeHandler Implementation While investigating this issue, I noticed that **Cordova-iOS already has WKURLSchemeHandler implementation** (introduced in v6.0.0 via PR #781). I'm wondering if we can leverage this existing infrastructure to address the iOS 26 media file issue **without requiring data migration**. ### Background This issue is related to earlier discussions: - #415 - Support serving local content with WKURLSchemeHandler - #781 - Use WKURLSchemeHandler for serving app content - #1030 - Allow plugins to hook into the WKURLSchemeHandler ### Current Situation When using the recommended custom scheme configuration: ```xml <preference name="scheme" value="app" /> <preference name="hostname" value="localhost" /> ``` ### What works: - Media files load correctly (solves iOS 26 sandbox issue) - CORS issues are resolved ### The problem: - Origin changes: null → app://localhost - All localStorage, IndexedDB, and cookies are permanently lost - No migration path for existing user data ### Proposed Investigation Since Cordova-iOS already uses WKURLSchemeHandler to serve app content from app://localhost, could we extend this handler to also proxy access to temporary directory files (cordova.file.tmpDirectory, cordova.file.cacheDirectory, etc.)? ### Conceptual approach: **App content**: Served via existing WKURLSchemeHandler app://localhost/index.html → www/index.html (already works) **Temporary files**: Extend handler to support special path prefixes app://localhost/_tmp/video.mp4 → tmp/video.mp4 (needs implementation) app://localhost/_cache/audio.mp3 → cache/audio.mp3 (needs implementation) app://localhost/_documents/file.pdf → Documents/file.pdf (needs implementation) **File URL conversion**: Extend or create helper method ``` // Convert file:// URLs returned by cordova-plugin-file const fileURL = fileEntry.toURL(); // Returns: file:///var/mobile/.../tmp/video.mp4 const appURL = convertFileToAppScheme(fileURL); // Would return: app://localhost/_tmp/video.mp4 videoElement.src = appURL; // Works on iOS 26 ``` ### Key Benefits 1. **No data migration needed** - Storage remains accessible under `app://localhost` origin 2. **Builds on existing infrastructure** - PR #781 already implemented the foundation 3. **Similar to proven solutions** - Ionic WebView plugin uses this approach successfully 4. **Simpler for developers** - Just convert file URLs, no complex migration logic 5. **Lower risk** - Avoids cookie migration reliability issues ### Potential Challenges 1. **Security**: Need to ensure scheme handler doesn't allow access outside allowed directories 2. **Path mapping**: Need robust conversion between app:// URLs and file system paths 3. **Backward compatibility**: Existing users still need one-time data migration (but simpler than cookie migration) 4. **MIME types**: Handler must correctly identify content types for all file types ### Questions for Community 1. Is this approach technically feasible given the current CDVWKWebViewEngine implementation? 2. Are there security concerns with allowing scheme handler to access tmp/cache/documents directories? 3. Has anyone already tried extending the scheme handler for this purpose? 4. Would this be worth exploring as an official solution, or are there fundamental blockers? ### Testing Plan I plan to test this approach on: * Real iOS devices (16, 17, 18, 26) - simulator behavior differs significantly * Both scenarios: fresh installs and upgrades from `file://` scheme * Memory constraints (WKWebView has strict limits on real devices vs simulators) * All Cordova file plugin directories (tmp, cache, documents, dataDirectory) Will report findings back to this issue. **Has anyone explored this direction?** I'd appreciate any technical insights, concerns, or references to existing implementations before investing significant effort in this approach. * * * **Related Resources:** * [WKURLSchemeHandler Apple Documentation](https://developer.apple.com/documentation/webkit/wkurlschemehandler) * [Ionic WebView Plugin](https://github.com/ionic-team/cordova-plugin-ionic-webview) (uses similar approach) * [WebKit Bug #154916](https://bugs.webkit.org/show_bug.cgi?id=154916#c17) (Apple engineer recommends WKURLSchemeHandler for local content) -- 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]
