B4J Question webview question

tufanv

Expert
Licensed User
Longtime User
Hello,

I have a question regarding webview. Some websites do not show data when using the webview in b4j, I think they are looking for a header or something like that and allow access when they see firefox,explorer,chrome etc..

There is a way to add headers when downoading via httpjob but i couldnt find anything for webview. is it possible?

TY
 

billzhan

Active Member
Licensed User
Longtime User
Java webview has its limitations, see this thread: https://b4x.com/android/forum/threads/webview-question.73886/

An example to get cookies from Java webview, I think it's possible to set cookie in the similar way.
https://www.b4x.com/android/forum/t...utils-and-webview-with-cookies.73783/#content

And this post : http://stackoverflow.com/questions/14385233/setting-a-cookie-using-javafxs-webengine-webview


It really depends on the pages you need to scrape. If it doesn't work, you may try tools like phantomjs or selenium.
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

Usually websites find out your browser type via the UserAgent, you can set it with the following code:

B4X:
Sub SetUserAgent(W As WebView, UserAgent As String)
  Dim JO As JavaObject = W
  JO.RunMethodJO("getEngine",Null).RunMethod("setUserAgent",Array As String(UserAgent))
End Sub


But as billzhan already mentioned this is probably not the problem here.

Jan
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
this works again with Java Object:

B4X:
Dim we,wvjo As JavaObject
we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
wvjo = WebView1
we = wvjo.RunMethod("getEngine",Null) 
Dim useragent As String=$"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"$
we.RunMethod("setUserAgent",Array(useragent))
WebView1.LoadUrl("http://www.whoishostingthis.com/tools/user-agent/")
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
this works again with Java Object:

B4X:
Dim we,wvjo As JavaObject
we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
wvjo = WebView1
we = wvjo.RunMethod("getEngine",Null)
Dim useragent As String=$"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"$
we.RunMethod("setUserAgent",Array(useragent))
WebView1.LoadUrl("http://www.whoishostingthis.com/tools/user-agent/")

tried all but these are not working as it works in the chrome. I couldnt exactly understand what phantomjs or selenium is for but i will search them on the web.
 
Upvote 0
Top