bug: CORS error when loading local files in iOS with live reload
See original GitHub issueBug Report
Capacitor Version
๐ Capacitor Doctor ๐
Latest Dependencies:
@capacitor/cli: 2.4.6
@capacitor/core: 2.4.6
@capacitor/android: 2.4.6
@capacitor/electron: 2.4.6
@capacitor/ios: 2.4.6
Installed Dependencies:
@capacitor/cli 2.4.4
@capacitor/android 2.4.4
@capacitor/ios 2.4.4
@capacitor/core 2.4.4
@capacitor/electron not installed
[success] Android looking great! ๐
Found 1 Capacitor plugin for ios:
cordova-plugin-file (6.0.2)
[success] iOS looking great! ๐
Platform(s)
- Android
- iOS
- Electron
- Web
Current Behavior
The local file converted to Web View-friendly path (like capacitor://localhost/capacitor_file/โฆ) cannot be fetched because of CORS error when running app in iOS with live reload.
It seems that CORS error is occurred because the source origin is http://xxx.xxx.xx.xx:8100
in default with live reload.
Expected Behavior
I can fetch my local file in OS with live reload.
Code Reproduction
// capacitor.config.json
{
"server": {
"url": "http://192.168.11.21:8100",
"cleartext": true
}
}
const path = "captured-photos/66026da3-5098-478a-9794-be8926df96e5"
const { uri } = await Filesystem.stat({ directory, path })
const webURI = window.Ionic.WebView.convertFileSrc(uri)
// throws CORS error!
const response = await fetch(webURI)
Other Technical Details
npm --version
output: 6.14.10
node --version
output: v14.15.1
pod --version
output (iOS issues only): 1.10.0
Additional Context
Related issues
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:13
Top Results From Across the Web
Safari: "Fetch API cannot load due to access control checks ...
Only after reloading the page to send the CORS request again, I get "Fetch API cannot load due to access control checks" in...
Read more >921233 - Local Overrides fails with CORS related - Monorail
The issue seem to be that you can't locally override a script that was loaded using CORS policy without disabling CORS in Chrome....
Read more >Hybrid app subject to CORS if live reload is used, any work around ...
Hello,. When serving a jet app as a hybrid app, the application is subject to CORS restriction if live reload is allowed (i.e....
Read more >CORS Errors: Cross-Origin Resource Sharing - Ionic Framework
CORS errors happen in web apps if requests are made and servers don't return required headers. Read about Cross-Origin Resource Sharing in Ionic...
Read more >Dealing with image CORS error in Chrome, Chromium and ...
The issue comes from the way that Chromium caches the images. The way that the initial image is cached is - without the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We just modified WebViewAssetHandler.swift (under Development Pods/Cordova).
I think the npm package
patch-package
could be used to change this file undernode_modules/@capacitor/ios/Capacitor/Capacitor
and patch it automatically afternpm install
.This is still a problem with capacitor 3. Any workarounds, configuration possibilities?