B4A Library WebViewExtras

JohnC

Expert
Licensed User
Longtime User
OK, I found a bug, don't know if its a WVE bug or it's another example of why you can't use MsgBox2 in an event sub.

(This bug seems like it might be related to another bug I found: https://www.b4x.com/android/forum/threads/weird-webview-and-msgbox2-conflict.83602/#post-529656)

Basically,

If I use this code on the first page of this thread:

B4X:
Sub MyEventName_GeolocationPermissionsRequest As Int
   Dim Response As Int
   Response=Msgbox2("Allow the webpage to use device geolocation features?", "Permission required:", "Allow", "", "Disallow", Null)
   If Response=DialogResponse.POSITIVE Then
      ToastMessageShow("Permission granted", True)
      Return MyWebViewExtras.GEOLOCATION_PERMISSION_ALLOW
   Else
      ToastMessageShow("Permission denied", True)
      Return MyWebViewExtras.GEOLOCATION_PERMISSION_DISALLOW
   End If
End Sub

After I click "Allow", the webpage seems like it can NOT run javascript reliably on it anymore.

However, if I simply have:
B4X:
Return wve.GEOLOCATION_PERMISSION_ALLOW
In the above sub, then the webpage acts correctly after I click Allow.
 

John Woodsmall

Active Member
Licensed User
Longtime User
i have simple html page (that works in desktop crome). It saves the input varibles
and then later wants to retrieve them.

does not seem to work under /files ???

var equ = document.getElementById('Equip_Mod').value ;
window.localStorage.setItem("Equip_Mod",equ);
--
var wag = document.getElementById('Cust_name') ;
wag.value= window.localStorage.getItem("Cust_name");
 

magarcan

Active Member
Licensed User
Longtime User
Hi!!

I'm working from your example here.
The fact is WebView1_PageFinished Event is triggered before the site has been fully loaded. I've set un a Delay before executing the Javascript and it works, but don't think this is the best way.

Any idea?

Thanks!!!
 

warwound

Expert
Licensed User
Longtime User
The fact is WebView1_PageFinished Event is triggered before the site has been fully loaded. I've set un a Delay before executing the Javascript and it works, but don't think this is the best way.

Any idea?

PageFinished means that all resources on the webpage have been loaded from the server, it does not mean that those resources have been fully rendered within the WebView.

Do you have control over the webpage?
If so then you can add a javascript event listener that will execute when the webpage has been fully rendered and that javascript can call a b4a sub via a JavascriptInterface.
Look here for more info: https://www.w3schools.com/jsref/event_onload.asp

If you have no control over the webpage then the only thing i can think of is to inject some javascript into the webpage and that injected javascript creates an onload event listener and calls a b4a sub via a JavascriptInterface.
 

Derek Johnson

Active Member
Licensed User
Longtime User
hi all

The following URL open without any issue in browser but not rendering with webview

http://ambiotinfotech.com/pos

login credentials:

demo / demo

tried with webviewextras but failed

need some support, Thanks in advance.

You should probably post this as a separate question, however I changed the URL in the WebView Extras demo code and got this on my Nexus 5X. What is the issue? (It was slow to load however).
 

Attachments

  • Pos.png
    19.6 KB · Views: 283

Derek Johnson

Active Member
Licensed User
Longtime User
Srikanth,

I did spot this error after I logged in and it did take 10-20 seconds to finish loading after the page finished event in WebView.

 

Srikanth.pendru

Member
Licensed User
Longtime User
B4X:
WebViewExtras1.Initialize(WebView1)
    websettings.setAppCacheEnabled(WebView1,True)
    websettings.setSavePassword(WebView1,True)
    websettings.setDOMStorageEnabled(WebView1,True)
 
    Dim WebChromeClient1 As DefaultWebChromeClient
    WebChromeClient1.Initialize("WebChromeClient1")
  WebViewExtras1.SetWebChromeClient(WebChromeClient1)
WebViewExtras1.AddJavascriptInterface(WebView1, "B4A")
    WebViewExtras1.JavaScriptEnabled=True
    WebView1.Height=100%y
    WebView1.Width=100%x
    WebView1.LoadUrl("http://ambiotinfotech.com/pos")

by adding this to webview the page rendered correctly

Thank you Derek Johnson
 

Neojoy

Member
Licensed User
Longtime User
1. You should always create a new thread instead of posting to old threads.
2. You can add a javascript interface and inject javascript and add resposible javascript code to the page to communicate with your app.

My apologies!

Ok, so I got to change my page to talk with my app.

Is there some exemple?

Thanks!
 

Neojoy

Member
Licensed User
Longtime User
Dont expect me to do the forumsearch for you. Search for javascript interface

I dont asked for this, i would like to know if you knew some exemple.
Yes or not would be enough!

Thanks, I solved.

Have a nice day!
 

JohnC

Expert
Licensed User
Longtime User

Just a suggestion....I think it would be very helpful to include the newer webviewsextras2 lib download and reference documentation links in the first post of this thread because doing a search for "Webviewextras2" did not return a "Library" thread for v2. It did return a download link thread for v2 that first had a broken link, then a good link. But I could not figure out who wrote or was supporting the never version 2 because the first post of this thread only mentioned v1. And because I have become use to library threads on this forum to at least have a link to a more recent version of a lib in the first post of an older lib, it gave me the impression v2 was written by someone else and I had no idea who.

It wasn't until I happen to accidently stumbled upon the above post which let me know that warwound did write version 2 and that documentation exists for the lib (wouldn't it also be helpful to have the link for the reference documentation of this lib to be on the first post too?)

Just sayin'
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Hi Warwound,

As you can see in this thread:

https://www.b4x.com/android/forum/t...port-a-native-file-upload.103331/#post-647863

Erel came up with a way to intercept the "Browse" button on a webpage (https://www.b4x.com/android/forum/threads/upload-files-with-webview.98623/) which allows us b4a developers to now do various things before uploading a file, and it has the benefit of not having to make any changes or add a webpage to the website in order to upload a file - it is compatible with the standard "browse" button on webpages.

But because his method is incompatible with your WVE lib and because my app uses various features of WVE, Erel being the very helpful guy that he is, is trying to help me manually implement the needed WVE features one-by-one into his implementation of the chromeclient. But this can become time consuming if I need more features from WVE and seems like it's reinventing the wheel you already wrote.

So, I was wondering what the chances were for you to implement Erel's browse/file upload ability into your lib to solve this situation.

Any thoughts?
 

Highwinder

Active Member
Licensed User
Longtime User
When I try to use this library to clear the webview cache, my app crashes. It also crashes when I use the following code without using the library:

Dim o As Reflector
o.Target = WebView1
o.RunMethod2("clearCache","True","java.lang.boolean")

Any ideas?
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User

Hello my friend,

Is possible to get all elements of page from WebE?

mDocument = WebE.GetDocument

and how I can submit a click on a button of a page? in your example ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…