Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cordova 10 Android Template Serves via Https so cvdfile: webview access also no longer works here #512

Closed
3 tasks done
weareu opened this issue Feb 7, 2022 · 3 comments · Fixed by #513
Closed
3 tasks done

Comments

@weareu
Copy link

weareu commented Feb 7, 2022

Bug Report

Cordova 10 Android Template Serves via Https so cvdfile: webview access also no longer works here. So upgrading to Android 10 template for cordova you can no longer access assets via cvdfile protocol urls still provided by the file plugin. This was previously a issue with web server based plugins like ionic-cordova-webview and others. But now it is a issue for the standard cordova template.

Problem

Whilst File access remains for our logging, html/browser access via cvdfile is broken. I've seen some attempts here to change from cvdfile protocol but all unsuccessfully merged. Keeping this protocol breaks in Android 10 template, has already caused endless issues with webview plugin and ios removal. Causes CORS issues, etc etc. I know the previous attempts changed the host. This would be wrong due to CORS, but that is a silly excuse to just do nothing. This plugin is basically one for the cornerstone cordova plugins that crosses the bridge for developing non-native/native. Hacky solutions claiming all access should now be javascript is wrong.

Best solution would be to become compatible with AndroidX and change the file path (if template > 10) to utilize a "virtual folder" for cvd access. It's not breaking any rules if the access is served via the current hosting mechanisms (wether ionic-webview OR Android Template > 10 without enabling legacy file mode).

I'm going to make this change and pull. Please assist with suggestions.

Information

To reproduce. Upgrade Cordova Android > 10. Access assets via cvdfile://.... either by requesting valid url from toNativeURL or toInternalURL. Neither can render either as file: or cvdfile: because you are comming from https.

Environment, Platform, Device

Android Cordova 10 template. Android 11 or below.

Version information

Ionic:

Ionic CLI : 6.18.1 (/Users/weareu/.nvm/versions/node/v16.13.1/lib/node_modules/@ionic/cli)
Ionic Framework : ionic1 1.3.5
@ionic/v1-toolkit : 3.2.15

Cordova:

Cordova CLI : 11.0.0
Cordova Platforms : android 10.1.1, ios 5.1.1
Cordova Plugins : no whitelisted plugins (41 plugins total)

System:

Android SDK Tools : 26.0.1 (/Users/weareu/Library/Android/sdk)
ios-deploy : 1.11.4
ios-sim : 8.0.2
NodeJS : v16.13.1 (/Users/weareu/.nvm/versions/node/v16.13.1/bin/node)
npm : 7.24.2
OS : macOS Monterey
Xcode : Xcode 13.2.1 Build version 13C100

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@pietos
Copy link

pietos commented Feb 23, 2022

I had a similar issue as a workaround I load the files into a blob and then attach the blob to the html view.
First I only had to do this for IOS devices, but since the latest cordova and android updates I use the IOS condition for both Android and IOS.

Example code

// remark: rs.rows.item(0).localsrc; the store result of fileEntry.toInternalURL();
rs.rows.item(0).localsrc; (which is fileEntry.toInternalURL();)

// On IOS we have to convert the image to a blob
window.resolveLocalFileSystemURL(rs.rows.item(0).localsrc, function(fileEntry) {
  if (window.cordova.platformId == "ios") {
  fileEntry.file(function(file) {
      var reader = new FileReader();
      reader.onloadend = function() {
          if (reader.result) {
              var blob = new Blob([new Uint8Array(reader.result)], { type: "image/jpeg" });
              blob = window.URL.createObjectURL(blob);
              companylogoimgEL.src = blob;
          } else {
              companylogoimgEL.src = 'res/' + APP_SELLER + '/logo_horizontal_white_smaller.png';
          }
      };
      reader.readAsArrayBuffer(file);
  });
  // On Android we can just load the local file
  } else {
      companylogoimgEL.src = rs.rows.item(0).localsrc;
  }
}

@weareu
Copy link
Author

weareu commented Feb 23, 2022

This does not work when comming from https on Android or standard Android 10+ because localsrc will be file:// this is no longer allowed. Or am I missing something?

@pietos
Copy link

pietos commented Feb 23, 2022

This does not work when comming from https on Android or standard Android 10+ because localsrc will be file:// this is no longer allowed. Or am I missing something?

I tested it on my pixel 5 phone with android 12 from an external https source without any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants