bug: Capacitor platform detection works wrong if html and js stored in Filesystem
See original GitHub issueBug Report
I save html and js to Filesystem (html and bundled js with Capacitor dependency included), then I use location.replace('Capacitor.convertFileSrc('some_file_url.html'))
. Everything works as expected, no errors. But after location replace to on Android platform is not detected correctly. I tried different capacitor.config.json
options to fix this, but no success yet. Looks like WebView restricts something when using local files.
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 2.4.7
@capacitor/core: 2.4.7
@capacitor/android: 2.4.7
@capacitor/electron: 2.4.7
@capacitor/ios: 2.4.7
Installed Dependencies:
@capacitor/cli 2.4.7
@capacitor/core 2.4.7
@capacitor/ios 2.4.7
@capacitor/android 2.4.7
@capacitor/electron not installed
[success] Android looking great! 👌
Found 1 Capacitor plugin for ios:
capacitor-secure-storage-plugin (0.5.0)
[success] iOS looking great! 👌
Platform(s)
Android 9.x, but i believe any other version works too
Current Behavior
Capacitor.platform === 'web'
and Capacitor.isNative === false
Expected Behavior
Capacitor.platform === 'android'
and Capacitor.isNative === true
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
FileReader API not firing · Issue #1564 · ionic-team/capacitor
When building my project using Cordova, the FileReader fires ... If we take zone.js (angular/ionic) out of the equation it works fine.
Read more >Capacitor Filesystem returns error while using main functions
When using Android 11 to create a directory using the mkdir() function I get the following error: Unable to create directory, unknow reason....
Read more >Filesystem.mkdir not working right in Android Emulator
When my app initializes I check to see if the main storage folders need to be created, and create them if needed.
Read more >The Ionic Image Guide with Capacitor (Capture, Store & Upload)
Capturing, storing and uploading image files with Ionic is a crucial task inside many applications, even if it's just a small avatar of...
Read more >How to Download and Open Files with Capacitor & Ionic [v5]
Learn how to download any file from the web and open them from your device using Capacitor ! Learn Ionic faster...
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
I can’t reproduce.
A few points:
Capacitor.convertFileSrc('some_file_url.html')
just returnssome_file_url.html
, you don’t need to use convertFileSrc to redirect to a local file.some_file_url.html
has a<head>
tag, if there isn’t one Capacitor’s bridge doesn’t get injected and uses the web plugins, looks like that’s what is happening here. https://capacitorjs.com/docs/getting-started#adding-capacitor-to-an-existing-web-appThanks 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.