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.

bug: iosScheme 'file' is not used as origin

See original GitHub issue

Bug Report

Capacitor Version

npx cap doctor output:

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 1.4.0

  @capacitor/core: 1.4.0

  @capacitor/android: 1.4.0

  @capacitor/ios: 1.4.0

Installed Dependencies:

  @capacitor/cli 1.3.0

  @capacitor/core 1.4.0

  @capacitor/ios 1.4.0

  @capacitor/android 1.4.0


[success] Android looking great! 👌
  Found 0 Capacitor plugins for ios:
[success] iOS looking great! 👌

Affected Platform(s)

  • Android
  • iOS
  • Electron
  • Web

Current Behavior

When migrating from a vanilla Cordova application (non-Ionic) to Capacitor, the device loses all localStorage and indexedDB data that is bound to the origin scheme.

Cordova binds these resources to the file:// scheme by default. Inside the IOS file storage these can still be found inside the WebKit cache under the IndexedDB file__0 directory.

However, when file is used as the scheme, it does not override the capacitor scheme that is used.

  "server": {
      "iosScheme": "file"
  }

Expected Behavior

Setting iosScheme to file, binds the apps resources to the file:// origin and allows users to migrate from a vanilla Cordova app to a Capacitor app.

Sample Code or Sample Application Repo

Reproduction Steps

Other Technical Details

npm --version output:

node --version output:

pod --version output (iOS issues only):

Other Information

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adamhannigancommented, Jan 17, 2020

For those interested. We achieved an IOS IndexedDB migration using the capacitor FileSystem plugin.

Example.

import { Capacitor, Plugins, FilesystemDirectory } from '@capacitor/core'

const { Filesystem, Device } = Plugins

function migrateCordovaToCapacitor() {
		const cordovaDirectory = 'file__0'
		const capacitorDirectory = 'capacitor_localhost_0'

		// FilesystemDirectory does not support WebKit directory so go to sibling first
        const cacheFilePath = await Filesystem.getUri({
            path: '',
            directory: FilesystemDirectory.Cache,
        })

        // Remove the Cache path to get to the WebKit parent directory
        const libraryPath = cacheFilePath.uri.slice(0, -9)

        // Grab all the content inside of the old directory
        const oldDirectoryPath = `${libraryPath}/WebKit/WebsiteData/IndexedDB/v1/${cordovaDirectory}/0E8427A40831C384F7F1DE368BF96DF520C1559C6EF19FD7211E5971849679FD`
        const directoryContents = await Filesystem.readdir({
            path: oldDirectoryPath,
        })

        const newDirectoryPath = `${libraryPath}/WebKit/WebsiteData/IndexedDB/v1/${capacitorDirectory}/0E8427A40831C384F7F1DE368BF96DF520C1559C6EF19FD7211E5971849679FD`

        // Copy all the old content into the new directory
        await Promise.all(directoryContents.files.map(async (file) => {
            await Filesystem.copy({
                from: `${oldDirectoryPath}/${file}`,
                to: `${newDirectoryPath}/${file}`,
            })
        }))
}

For Android, Google’s implementation of LevelDB makes it a little difficult to copy the cached files.

https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/181#issuecomment-516602506

From the comments, one option is to open up a WebView on the old scheme and copy the data across.

Example gist

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

WebView origin not correctly set when using custom scheme ...
Implementations can set different origins for "file" and unknown schemes, but my "ionic" scheme is known to the WebView. Do you think this...
Read more >
cordova-plugin-ionic-webview - custom scheme not working ...
NOTE: This config works fine on iOS. On Android I can't use this plugin due to this Hostname/Origin issue.
Read more >
cordova-handle-ssl-error - npm
A Web View plugin for Cordova, focused on providing the highest performance experience for Ionic apps (but can be used with any Cordova...
Read more >
Capacitor Configuration | Capacitor Documentation
The Capacitor configuration file is used to set high-level options for Capacitor tooling. Example​. This is an example capacitor.config.ts file: import { ...
Read more >
Config.xml - Apache Cordova
When using the CLI to build a project, versions of this file are passively copied into various platforms/ subdirectories. For example:.
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