Android Question OverrideUrl not raised for WebkitWebView1

ShadTech

Member
Licensed User
hello all
I can't handle or catch the override event of the webkit View
B4X:
Sub Globals
 
    Public WebkitWebView1 As  WebkitWebView
 
    
End Sub
Sub Activity_Create(FirstTime As Boolean)
 
    Private pp As B4XView = xui.CreatePanel("")
    pp.SetLayoutAnimated(0,0,0, 100%x, 100%y)
    pp.LoadLayout("Page1")
 
    iniwebv(WebkitWebView1,"1")
    WebkitWebView1.WebView.LoadUrl("http://zzzz.zzzz.net")
    wkivwslist.Initialize
    wkivwslist.Add(pp)
    ASViewPagerNative1.AddPages(wkivwslist)
 
End Sub

Private Sub WebkitWebView1_OverrideUrl (url As String) As Boolean 'Works from API level 1 and above.
    LogColor( url,Colors.Blue)
End Sub
I need to note that WebkitWebView1 is already loaded in the layout page1 so it is initialized
any solution?????
 

drgottjr

Expert
Licensed User
Longtime User
the author of webkitwebview has, himself, deprecated his
library in favor a new set of utilities. if you're having trouble
with webkitwebview, you may want to consider using his
newer library instead.

the overrideurl event works just fine with our core webview.
you might want to look into that, as you don't even need a
separate library to handle it. it might also help you to
understand what that event is meant to do and how to use
it.
 
Upvote 0

ShadTech

Member
Licensed User
the author of webkitwebview has, himself, deprecated his
library in favor a new set of utilities. if you're having trouble
with webkitwebview, you may want to consider using his
newer library instead.

the overrideurl event works just fine with our core webview.
you might want to look into that, as you don't even need a
separate library to handle it. it might also help you to
understand what that event is meant to do and how to use
it.
i installed the newer one
and in the attached image all other separate libraries i haves used trying to catch overrideurl event or resourceerror event, but no code works,
could you give me piece of code help doing this
 

Attachments

  • 112.png
    112.png
    37.9 KB · Views: 43
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
technically, for the purpose of shouldoverrideurlloading(), you only need the webkitwebviewclient module. shouldoverride is handled by webviewclient.
but let's take a step back. below i have attached a simple working example for you.

this is how you handle shouldoverride:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim webview As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    webview.Initialize("webview")
    Activity.AddView(webview, 0%x,0%y,100%x,200%y)
    webview.Loadhtml(File.ReadString(File.DirAssets,"test.html"))
End Sub

Sub webview_OverrideUrl (Url As String) As Boolean
    If Url.Contains("google") Then
        ToastMessageShow("blocking this url!",False)
        Return True
    Else
        ToastMessageShow("Cannot override this link!  Must load.",False)
        Return False
    End If
End Sub

it's unclear from your post whether or not you understand under what conditions shouldoverrideurl is triggered. it's also not clear whether there might be some other error in your code that prevented webkitwebview from working in the first place. run the example and see what you see.

edit: sorry, i just noticed a typing error: the height of the webview should be "100%y", not "200%y". it doesn't affect how the example runs, so you can leave it.
 

Attachments

  • override.zip
    7.8 KB · Views: 46
Upvote 0

ShadTech

Member
Licensed User
technically, for the purpose of shouldoverrideurlloading(), you only need the webkitwebviewclient module. shouldoverride is handled by webviewclient.
but let's take a step back. below i have attached a simple working example for you.

this is how you handle shouldoverride:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim webview As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    webview.Initialize("webview")
    Activity.AddView(webview, 0%x,0%y,100%x,200%y)
    webview.Loadhtml(File.ReadString(File.DirAssets,"test.html"))
End Sub

Sub webview_OverrideUrl (Url As String) As Boolean
    If Url.Contains("google") Then
        ToastMessageShow("blocking this url!",False)
        Return True
    Else
        ToastMessageShow("Cannot override this link!  Must load.",False)
        Return False
    End If
End Sub

it's unclear from your post whether or not you understand under what conditions shouldoverrideurl is triggered. it's also not clear whether there might be some other error in your code that prevented webkitwebview from working in the first place. run the example and see what you see.

edit: sorry, i just noticed a typing error: the height of the webview should be "100%y", not "200%y". it doesn't affect how the example runs, so you can leave it.
that is the normal b4a webview I know it ,,,,
its problem that running JavaScript so heavy and lag sometimes,
but with the webkitweview js and everything was running smoothly and all its functionality runs smoothly ,
that is why i need webkitweview not normal b4a webview
I have noticed that the event
Sub webkitweview1_PageLoadingProgressChanged(Progress As Int)
LogColor(Progress,Colors.red)
End Sub
raised and run successfully
why overideurl not???
really confused??
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i found and downloaded the deprecated ultimatewebview and run the author's example.
as with my example that i posted earlier, i used my test.html file as url to load.

Private Sub UltimateWebView1_OverrideUrl (WebResourceRequest1 As WebResourceRequest) As Boolean
works just fine. the result is the same as for my simple example using a standard webview.
if you bothered
to run my example, and if you run the example attached below, you will see that both examples behave the same way.

i'm afraid the problem is your use and/or understanding of the event. i have never used ultimatewebview before, and
yet the example worked perfectly (for me) immediately on the first attempt.

below please find the example from ultimatewebview with my test file. load it and simply press the "go" button.
don't fill in the url. just tap the "go" button.

i'm sorry, but there is not much more i can do for you.
 

Attachments

  • B4AExample.zip
    12.2 KB · Views: 45
Upvote 0

ShadTech

Member
Licensed User
i found and downloaded the deprecated ultimatewebview and run the author's example.
as with my example that i posted earlier, i used my test.html file as url to load.

Private Sub UltimateWebView1_OverrideUrl (WebResourceRequest1 As WebResourceRequest) As Boolean
works just fine. the result is the same as for my simple example using a standard webview.
if you bothered
to run my example, and if you run the example attached below, you will see that both examples behave the same way.

i'm afraid the problem is your use and/or understanding of the event. i have never used ultimatewebview before, and
yet the example worked perfectly (for me) immediately on the first attempt.

below please find the example from ultimatewebview with my test file. load it and simply press the "go" button.
don't fill in the url. just tap the "go" button.

i'm sorry, but there is not much more i can do for you.
I really think and appreciate your effort with me,
really you are good man ,
but I have really tried the two version of ultimatewebview2 and ultimatewebview ,
they work fine with mem
but when running my full jS app they are running JavaScript with slowness and some lag even ultimate & understand webview ,
I find the thing that I want in webkitwebview with you with no hang very smooth run for my JavaScript but no overideurl event can be used with it,
that's my only problem brother.
 
Last edited:
Upvote 0
Top