cordova-plugin-ionic-webview icon indicating copy to clipboard operation
cordova-plugin-ionic-webview copied to clipboard

Canvas and Cors

Open elvisgraho opened this issue 5 years ago • 10 comments

Im trying to load local images into canvas (openlayer) and prevent my canvas from getting tainted in the process.

I cannot load "file:///..." urls because it is not allowed.

And I cannot request it from localhost (this.webview.convertFileSrc) hence CORS.

How can I solve the CORS issue that is requesting files locally?

elvisgraho avatar Jun 22 '20 13:06 elvisgraho

can you provide more information about the issue? in which platforms do you get the problem? how do you run the app? can you provide a sample app?

jcesarmobile avatar Jun 22 '20 14:06 jcesarmobile

same issue here with canvas and canvas need crossOrigin="anonymous" to work even cors (*) is enable at s3 bucket when you place crossOrigin="anonymous" in img element you will get cors error

Edit: creating small application to reproduce

Edit1: Don't know whats going on its working fine in sample application but not in actual application i copied same component over there.

indraraj26 avatar Jun 23 '20 11:06 indraraj26

same from server team they have created cloudfront and map to s3 hosted image. now i am getting proper response header from access origin *

indraraj26 avatar Jul 03 '20 13:07 indraraj26

https://stackoverflow.com/questions/57440211/how-to-load-an-image-into-a-canvas-without-cors-issues-for-ionic-ios-hybrid-app

use cordova native http, or cordova-plugin-wkwebview-file-xhr.

xiazhe avatar Sep 11 '20 09:09 xiazhe

@xiazhe Still an issue, because I need to provide "path" or "url" to an image.

elvisgraho avatar Feb 08 '21 07:02 elvisgraho

CORS

elvisgraho avatar Feb 08 '21 08:02 elvisgraho

Anybody found a solution? Have the same issue here

rnschulenburg avatar Feb 27 '21 11:02 rnschulenburg

I was trying to do canvas.toDataURL to images with "file:///" schemes on iOS in Cordova, and getting various errors, including: "Origin null is not allowed by Access-Control-Allow-Origin."

The solution that worked for me involved two steps:

  1. Add to the <platform name="ios"> section of config.xml:
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />

as documented here: https://cordova.apache.org/announcements/2020/06/01/cordova-ios-release-6.0.0.html

  1. Update the filename returned in the Success callback from navigator.camera.getPicture(), from the "file:///" scheme to your new "app://" scheme using:
imageFileName = window.WkWebView.convertFilePath( imageFileName )

as (kind of) documented here: https://github.com/apache/cordova-plugin-camera/issues/622#issuecomment-659357799

Michael-Stanford avatar Mar 05 '21 19:03 Michael-Stanford

@Michael-Stanford thank you. The project was probably created before the release of 6.0, that is maybe the reason for lack of complaints. Changing config.xml would probably require generating new project, and I assume it adds/changes something in info.plist file (iOS). Would be nice if somebody knew the right config for the "bugfix". (As with linked issue, it appears only in live reload mode)

elvisgraho avatar Mar 08 '21 11:03 elvisgraho

Is there an update?

passwhl avatar Apr 23 '21 00:04 passwhl