B4J Question Trying to load Amazon Music (SOLVED)

Colin Evans

Active Member
Licensed User
Longtime User
Hi, trying to load Amazon Music to play a few playlists but when i use the following to load Amazon

WebView1.Loadurl("https://music.amazon.co.uk/")

I get the following message, does anyone know a workaround


Your browser is not supported​

 

EnriqueGonzalez

Expert
Licensed User
Longtime User
You may fake the browser with this

B4X:
Webview1.as("javaobject").runmethod("setUserAgent",array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36")
you should check for the most up to date user agent.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
You may fake the browser with this

B4X:
Webview1.as("javaobject").runmethod("setUserAgent",array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36")
you should check for the most up to date user agent.

Thank you for taking the time to reply, but I'm lost in how to implement it to get the website loaded, I copied the line you supplied but I get a syntax error, hope you can explain in novice terms :)
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User
Longtime User
Thank you for taking the time to reply, but I'm lost in how to implement it to get the website loaded, I copied the line you supplied but I get a syntax error, hope you can explain in novice terms :)

You will have to use another advanced library because the classic WebView is very simple and does not support a huge number of advanced and modern protocols.
 
Upvote 0

amykonio

Active Member
Licensed User
Longtime User
Maybe something like that.
For the code above:

B4X:
    Dim jo As JavaObject
    
    jo = WebView1
    jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"))

But I'm not sure it will work.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Maybe something like that.
For the code above:

B4X:
    Dim jo As JavaObject
   
    jo = WebView1
    jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"))

But I'm not sure it will work.
To be honest I haven't got a clue how to do this, I've searched the forum and just getting deeper into the mire

I tried the following based on your code

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private Pane1 As Pane
    Dim WebView1 As WebView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    Dim jo As JavaObject
    jo = WebView1
    jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"))
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    WebView1.Loadurl("https://music.amazon.co.uk/")
End Sub

But I get the following error even though Webview is generated via the designer

B4X:
main._appstart (java line: 57)
java.lang.RuntimeException: Object should first be initialized (WebView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
    at b4j.example.main._appstart(main.java:57)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
    at b4j.example.main.start(main.java:37)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)

Help!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
main._appstart (java line: 57) java.lang.RuntimeException: Object should first be initialized (WebView).
You are accessing the webview before the layout is loaded? Surely it is not initialized at this time.

Dim jo As JavaObject jo = WebView1 jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"))
Move these lines after the LoadLayout-Line
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
You are accessing the webview before the layout is loaded? Surely it is not initialized at this time.


Move these lines after the LoadLayout-Line
Thanks, stupid mistake on my part, so I've done that but it still states the Browser is not supported

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim jo As JavaObject
    jo = WebView1
    jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"))
    WebView1.Loadurl("https://music.amazon.co.uk/")
End Sub

1637686469884.png
 
Upvote 0

amykonio

Active Member
Licensed User
Longtime User
Try the following:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim jo As JavaObject
    jo = WebView1
    'jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"))
    jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Chrome/96.0.4664.45 Safari/537.36 Edg/96.0.1054.29"))
  
    Dim obj As Object
    obj = jo.RunMethodJO("getEngine", Null).RunMethod("getUserAgent", Null)
    WebView1.Loadurl("https://music.amazon.co.uk/")
End Sub
Here it seems to be working.
With:
B4X:
jo.RunMethodJO("getEngine", Null).RunMethod("setUserAgent", Array("Chrome/96.0.4664.45 Safari/537.36 Edg/96.0.1054.29"))
you can check that the UserAgent was set (I saw it in debug with a breakpoint). This line can be comment out in your final code.
1637704781365.png


Andreas.
 
Upvote 0
Top