MAUI WebView problem with rendering AngularJS - webview

My website is not loading properly inside MAUI WebView on Android - templates are not rendering.
Fallowing similar problem Issues in loading Angular JS website in Android Webview how I can enable below setting in MAUI project ?
webView.Settings.JavaScriptEnabled = true;
webView.Settings.AllowFileAccess = true;
webView.Settings.SetSupportMultipleWindows(true);
webView.Settings.DatabaseEnabled = true;
webView.Settings.DatabasePath = "/data/data/" + "/databases/";
webView.Settings.DomStorageEnabled = true;
webView.Settings.SetAppCacheEnabled(true);
webView.Settings.SetAppCacheMaxSize(1024 * 1024 * 8);
webView.Settings.SetAppCachePath("/data/data/cache/");
webView.ClearCache(true);
It could be issue is not related above setting, but then why MAUI WebView rendering is different from regular Chrome browser?

Related

How can i access elements in a iframe of a cordova WKWebview ios app?

I want to access elements of our website that is embedded in a iframe of our ios App.
It has the same problem as file access.
SecurityError: Blocked a frame with origin "file://" from accessing a cross origin frame...
The file access problem is solved through this plugin https://github.com/globules-io/cordova-plugin-ios-xhr.
But access in a iframe is not solved.
How can i access elements in a iframe of a cordova WKWebview ios app?
I've run into a similar issue in my Cordova apps with WkWebView. You'll need to get the iframe to run under the "same-origin" of your app. This is the only workaround I've found. It involves writing content directly to the iframe, rather than giving it a src="...". This way, iframe runs as same-origin as parent. (Anything loaded via src="file://..." is treated as unique-origin in WkWebView, so blocks any cross-frame JavaScript.)
function frameEl_injectHtml(frameEl, injectHtml) {
// frameEl must exist in DOM before its contentWindow is accessible.
if (!frameEl.contentWindow) { alert("frameInjectHtml() but frameEl not (yet or anymore) in DOM."); return; }
frameEl.contentWindow.document.open('text/htmlreplace');
frameEl.contentWindow.document.write(injectHtml);
frameEl.contentWindow.document.close();
}
// Create <frame>, insert into DOM, and inject content.
var frameHtml = "<html><head></head>" +
"<body style='background-color:#eee; color:#000;'>" +
"iframe body" +
"<script>window.parent.alert('iframe even same-origin as parent.');</script>" +
"</body></html>";
var frameEl = document.createElement('iframe');
frameEl.src = "about:blank";
document.body.appendChild(frameEl);
frameEl_injectHtml(frameEl, frameHtml);
You'll have to load the contents of the website pages somehow outside of this workaround, e.g. with an ajax call.

IOS Localstorage not working

We are working on an IOS app that has been developed in swift.
This consists of a webview where in the initial pages are native and then we are moving to webview.
During the transition from the native pages to the webview we need to store some values in the LocalStorage so those can be used in the webview.
This is working in Android but we are facing some problems in IOS. The Android code is as follows:-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
wv_content.evaluateJavascript("localStorage.setItem('" + key + "','" + value + "');", null);
else
wv_content.loadUrl("javascript:localStorage.setItem('" + key + "','" + value + "');");
https://developer.apple.com/icloud/documentation/data-storage/index.html
https://forums.cocoon.io/t/system-save-load-and-local-storage-do-not-work-after-compile-with-cocoon-io-to-ios-webview-mode/3319/49
PhoneGap iOS 7 and localStorage
But none of them has been successful for me. I have googled around and there were no perfect code samples that could have been used to display the way it can be done.
Please help me with a code sample of doing the same with enabling the needed preferences.
Thanks for help.
UPDATE
Below is the IOS code I am using and this way is not working for me.
web_browser.delegate = self
let javaScript = "localStorage.setItem(\"user\", \"\(jsonString!)\")"
web_browser.stringByEvaluatingJavaScript(from: javaScript)
web_browser.loadRequest(URLRequest(url: url!))

Android webview jwplayer7 cannot read property 'jwplayer.volume' of null

I have an app that is using a webview to launch an html that loads JWP7 and throws an error Uncaught TypeError :cannot read property 'jwplayer.volume' of null
The same page is loading perfectly on mobile and desktop browsers.
I tried to add in the javascript of the html after the jwplayer.js is being called and before the setup, the following code:
if (typeof jwplayer.volume == "undefined" || typeof jwplayer.volume == null )
jwplayer.volume = 10;
I do see the new volume property using a desktop/mobile browser but it doesn't changes the TypeError in the webview, probably because the TypeError is thrown while running the jwplayer.js script, before it reaches my javascript check.
When i'm Using the JWP6 everything is working perfectly.
Any suggestions on how to fix it?
I inspected the jwplayer.js code.
And saw that it reads the last settings of Volume (jwplayer.volume) and Mute (jwplayer.mute) from the LocalStorage; instead of from cookie.
(Probably JWPlayer 6 was using cookies.)
So, you need to enable LocalStorage access in your WebView; like you do for JavaScript.
Sample code below.
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true); // This will allow access
webView.setWebViewClient(new WebViewClient());
/* WebView.setWebContentsDebuggingEnabled(true); // This is to inspect your WebView from desktop Chrome. (>= API 19) You may not want to include this in production. */
webView.loadUrl(url);
JW Player doesn't support using the web player in Android or iOS webview; however, there are native mobile SDKs available to support in-app video: developer.jwplayer.com/android-sdk

PDF file download not working only for iPad specific browsers

A PDF file is generated on server side and pushed to client end for download. While the download works in all browsers on windows , fails on IPAD.
Please advise.
Specification : OS 6, Safari 6.1 , Chrome 23.0.1271.100
Please note: In this application pdf is not downloaded on to a new url (NO REDIRECTION).
General behavior: IPad browser (safari / chrome) does not support the download window, hence its expected to open the pdf and provides option to view in pdf compatible apps. Which is not currently happening.
When i debug the below servlet action code for download, the pdf file is successfully generated on server but browser on Ipad does not show :-(
Code sample :
/** Setting response Header **/
response.setHeader("Content-Type", "application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=sample.pdf");
response.setHeader("Connection", "close");
response.setHeader("Cache-Control","cache");
response.setHeader("Pragma","cache");
response.setDateHeader ("Expires", dt.getTime() + 100000);
/** Writing to output **/
InputStream stream = info.getInputStream();
OutputStream os = response.getOutputStream();
try {
response.setContentType(contentType);
copy(stream, response.getOutputStream());
}
finally {
if (stream != null) {
stream.close();
}
}
After testing, the download action code pasted above appeared to be working fine as the issue was BROWSER specific.
Andriod Tablet - Firefox browser downloads the pdf onto pop up window.
IPad : Safari - FIX: Forced the content to open up in a new tab, something like this :
window.open(print_url);
where print_url is the baseurl+action.do+additional_parameter.
To display a pdf instead of asking the browser to save it, use "inline" instead of "attachment".
response.setHeader("Content-Disposition", "inline;filename=sample.pdf");
Also, you're setting content type twice, once in the header and once using setContentType().
I'm not sure if those two headers interact or cancel each other out, so can't say for sure that it's a source of error, but it seems like something to consider changing.

Apache Cordova 2.0 show infinite input text when load the web page

I have follow this guideline to embed a Cordova web application in my iOs app:
CDVViewController* viewController = [CDVViewController new];
viewController.wwwFolderName = [NSString stringWithFormat:
#"/data/volumes/%#",
self.book.code];
viewController.startPage = #"index.html";//#"gallery.html";
viewController.useSplashScreen = NO;
viewController.view.frame = self.view.frame;
[self.view addSubview:viewController.view];
all works good but when the CDVViewController load the html page (the test index.html proposed on the howto) the app show infinite input text box, with different strings
any idea?
problem solved:
In the Phonegap library every OS have own cordova-2.0.0.js, I was loading the Android version :)

Resources