cordova-plugin-wkwebview-engine icon indicating copy to clipboard operation
cordova-plugin-wkwebview-engine copied to clipboard

Cannot set base64 image on WKWebview using evaluateJavascript method iOS platform

Open varavindraj opened this issue 3 years ago • 0 comments

I have a HTML file which contains local resource files such as css, js files inside its content. These local resource files are in zip format. My app uses Cordova's WKWebView to display this html file on wkwebview. I m trying to upload an image in one of the html image element on WKWebView which is saved locally and is converted to base64 string but its not updating the image. I have a html image tag in local html like this.

<img id='image' style='display: block; height: 100%; width:100%; margin:0 auto;' /> I update the image using evaluateJavascript method of WkWebView like below

NSData *imageData = UIImagePNGRepresentation(image);
NSString *base64Str = [imageData base64EncodedStringWithOptions:0];     
NSString *js = [NSString stringWithFormat:@"document.getElementById('image-id').src='data:image/png;base64,%@'",base64Str];
[self.wkWebView evaluateJavaScript:js completionHandler:nil];

This is suppose to add the image on the image tag element but it does nothing. I tried this in normal WKWebView and it updates the image without any problem.

This in iOS, Objective C code. We are seeing this issue in all apple devices.

I am using Cordova version 5.0.0

varavindraj avatar Feb 11 '21 14:02 varavindraj