Android Question [SOLVED] WebviewExtras2 newbe question

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
There is a webpage, what works well in Chrome in my android device. I have to make it to work in b4a webview. I have an initial code:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    WebViewExtras1.Initialize(WebView1)
    Dim WebChromeClient1 As DefaultWebChromeClient
    WebChromeClient1.Initialize("WebChromeClient1")
    WebViewExtras1.SetWebChromeClient(WebChromeClient1)
    WebViewExtras1.JavaScriptEnabled = True
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    WebView1.LoadUrl("https://arrakis.demo.promera.systems/")
End Sub

Private Sub WebView1_PageFinished (Url As String)
    ToastMessageShow("Page loaded...",False)
End Sub
Private Sub WebChromeClient1_ConsoleMessage(ConsoleMessage1 As ConsoleMessage) As Boolean
    Log(ConsoleMessage1.Message)
    Return True
End Sub
but I got error:
B4X:
TypeError: y.map(...).flat is not a function
Uncaught TypeError: y.map(...).flat is not a function
It looks like as a javascript problem, but it isn't happen in Chrome browser (in android). What have to do for my webview do works like Chrome?
thanks in advance
Steven
 
Last edited:

Ivica Golubovic

Active Member
Licensed User
Hi All!
There is a webpage, what works well in Chrome in my android device. I have to make it to work in b4a webview. I have an initial code:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    WebViewExtras1.Initialize(WebView1)
    Dim WebChromeClient1 As DefaultWebChromeClient
    WebChromeClient1.Initialize("WebChromeClient1")
    WebViewExtras1.SetWebChromeClient(WebChromeClient1)
    WebViewExtras1.JavaScriptEnabled = True
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    WebView1.LoadUrl("https://arrakis.demo.promera.systems/")
End Sub

Private Sub WebView1_PageFinished (Url As String)
    ToastMessageShow("Page loaded...",False)
End Sub
Private Sub WebChromeClient1_ConsoleMessage(ConsoleMessage1 As ConsoleMessage) As Boolean
    Log(ConsoleMessage1.Message)
    Return True
End Sub
but I got error:
B4X:
TypeError: y.map(...).flat is not a function
Uncaught TypeError: y.map(...).flat is not a function
It looks like as a javascript problem, but it isn't happen in Chrome browser (in android). What have to do for my webview do works like Chrome?
thanks in advance
Steven
Try:
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User

Attachments

  • Screenshot_20211118_133952_com.test.net.jpg
    Screenshot_20211118_133952_com.test.net.jpg
    250.8 KB · Views: 232
Last edited:
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
No the link does not work. When you log in it's ok, but later there are some javascript buttons that when I click on, the screen goes white, just like in the regular webview. But if I do the same in the Chrome browser, no problem.
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User
Okay, you may need to enable some option in WebViewSettings. Try to catch the error via the ReceivedError or ReceivedHttpError event. In essence, it is difficult to come to a conclusion without a practical example. If you need any help you can contact me at any time.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Thank you for your help, but I can't do more too. This webpage isn't mine and the underlying javascript code is very confused (protected, obfuscated?) so I just know that the webview works otherwise as the Chrome in the same device.
I read a lot and did a lot of other websettings, but no result. In the ultimatewebview there is no error in ReceivedError or ReceivedHttpError, only the webpage goes blank after pressing some buttons and in the normal webview shows this error (in the log):
B4X:
TypeError: y.map(...).flat is not a function
Uncaught TypeError: y.map(...).flat is not a function
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User
Thank you for your help, but I can't do more too. This webpage isn't mine and the underlying javascript code is very confused (protected, obfuscated?) so I just know that the webview works otherwise as the Chrome in the same device.
I read a lot and did a lot of other websettings, but no result. In the ultimatewebview there is no error in ReceivedError or ReceivedHttpError, only the webpage goes blank after pressing some buttons and in the normal webview shows this error (in the log):
B4X:
TypeError: y.map(...).flat is not a function
Uncaught TypeError: y.map(...).flat is not a function
"Flat map" is not supported by WebView. It's not even supported by many well-known browsers on the market (I think that Microsoft Edge don't supports it either).
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
I found the solution using webviewextras2 lib.
B4X:
    Javascript.Append($"
Object.defineProperty(Array.prototype, 'flat', {
    value: function(depth = 1) {
      return this.reduce(function (flat, toFlatten) {
        return flat.concat((Array.isArray(toFlatten) && (depth>1)) ? toFlatten.flat(depth-1) : toFlatten);
      }, []);
    }
});   
    "$)
    WebViewExtras1.executeJavascript(Javascript.ToString)
Now there is a y.map(...).flat
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User
I found the solution using webviewextras2 lib.
B4X:
    Javascript.Append($"
Object.defineProperty(Array.prototype, 'flat', {
    value: function(depth = 1) {
      return this.reduce(function (flat, toFlatten) {
        return flat.concat((Array.isArray(toFlatten) && (depth>1)) ? toFlatten.flat(depth-1) : toFlatten);
      }, []);
    }
});  
    "$)
    WebViewExtras1.executeJavascript(Javascript.ToString)
Now there is a y.map(...).flat
I'm glad you found a solution. ???
 
Upvote 0
Hi All!
There is a webpage, what works well in Chrome in my android device. I have to make it to work in b4a webview. I have an initial code:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    WebViewExtras1.Initialize(WebView1)
    Dim WebChromeClient1 As DefaultWebChromeClient
    WebChromeClient1.Initialize("WebChromeClient1")
    WebViewExtras1.SetWebChromeClient(WebChromeClient1)
    WebViewExtras1.JavaScriptEnabled = True
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    WebView1.LoadUrl("https://arrakis.demo.promera.systems/")
End Sub

Private Sub WebView1_PageFinished (Url As String)
    ToastMessageShow("Page loaded...",False)
End Sub
Private Sub WebChromeClient1_ConsoleMessage(ConsoleMessage1 As ConsoleMessage) As Boolean
    Log(ConsoleMessage1.Message)
    Return True
End Sub
but I got error:
B4X:
TypeError: y.map(...).flat is not a function
Uncaught TypeError: y.map(...).flat is not a function
It looks like as a javascript problem, but it isn't happen in Chrome browser (in android). What have to do for my webview do works like Chrome?
thanks in advance
Steven
I was trying to look for the similar solution with the same issue. Tried the code above and I didn't get any error. Seems like the code is fine but my page display is still white blank..
 
Upvote 0
Top