Android Question problem with using WebViewExract and javaScript in my code

pat.hs

Member
Hi, I hope someone can help me
My problem is that I want to access the codes of the Instagram Inspect section and receive the caption of the posts, the code is compiled and executed without any errors, but after entering the link and requesting the download, I receive the following errors.
codes :
Sub WebView1_PageFinished (Url As String)
Dim javascript As String
WebView1.JavaScriptEnabled = True
javascript = "web.CallSub('cap', false, javascript: document.getElementsByClassName('_ezgzd')[0].innerText)"
w.executeJavascript(WebView1,javascript)

End Sub

Public Sub cap (ca As String)
textcaption.Text=ca.Trim
ProgressDialogHide
End Sub

Sub download_Click
mpclick.Play
w.addJavascriptInterface(WebView1,"web")
w.addWebChromeClient(WebView1,"")
WebView1.LoadUrl(""&edlink.Text)
ProgressDialogShow("copying...")
End Sub



Errors :
ErrorUtils caught an error:
followedByViewer state must be defined
Subsequent non-fatal errors won't be logged; see https://fburl.com/debugjs. in https://www.instagram.com/static/bundles/es6/ConsumerLibCommons.js/4f9d3a21f3b5.js (Line: 4)
Uncaught SyntaxError: missing ) after argument list in ..... (Line: 1)
Uncaught TypeError: Cannot read property 'push' of undefined in ..... (Line: 53)
 

Ivica Golubovic

Active Member
Licensed User
Can you be a little more precise and detailed. From your post and code, I can't figure out what exactly you want to do. How exactly do you want to download the file, do you need to get a link to download the file by executing the javascript ... Can you share the part where the webview is used, but please share as
B4X:
code here...
?
 
Upvote 0

pat.hs

Member
Sure, what I want to do is display an Instagram page in WebView , and then access the code of that page with JavaScript, and use the "document.getElementByClassName" and Give the name of the class in which the caption text is located, receive that text and display it in the edittext. But after entering the link and hitting the download button, I will receive the following errors.


ErrorUtils caught an error:
followedByViewer state must be defined
Subsequent non-fatal errors won't be logged; see https://fburl.com/debugjs. in https://www.instagram.com/static/bundles/es6/ConsumerLibCommons.js/4f9d3a21f3b5.js (Line: 4)
Uncaught SyntaxError: missing ) after argument list in ..... (Line: 1)
Uncaught TypeError: Cannot read property 'push' of undefined in ..... (Line: 53)


I will put the code of the relevant section below.
if u want i can attach files so u can run it and see how its work
B4X:
Sub WebView1_PageFinished (Url As String)
Dim javascript As String
WebView1.JavaScriptEnabled = True
javascript = "web.CallSub('cap', false, javascript: document.getElementsByClassName('C4VMK')[0].innerText)"
w.executeJavascript(WebView1,javascript)

End Sub

Public Sub cap (ca As String)
textcaption.Text=ca.Trim
ProgressDialogHide
End Sub

Public Sub download_Click
w.addJavascriptInterface(WebView1,"web")
w.addWebChromeClient(WebView1,"")
WebView1.LoadUrl(""&edlink.Text)
ProgressDialogShow("copying...")
End Sub
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User
Sure, what I want to do is display an Instagram page in WebView , and then access the code of that page with JavaScript, and use the "document.getElementByClassName" and Give the name of the class in which the caption text is located, receive that text and display it in the edittext. But after entering the link and hitting the download button, I will receive the following errors.


ErrorUtils caught an error:
followedByViewer state must be defined
Subsequent non-fatal errors won't be logged; see https://fburl.com/debugjs. in https://www.instagram.com/static/bundles/es6/ConsumerLibCommons.js/4f9d3a21f3b5.js (Line: 4)
Uncaught SyntaxError: missing ) after argument list in ..... (Line: 1)
Uncaught TypeError: Cannot read property 'push' of undefined in ..... (Line: 53)


I will put the code of the relevant section below.
if u want i can attach files so u can run it and see how its work
B4X:
Sub WebView1_PageFinished (Url As String)
Dim javascript As String
WebView1.JavaScriptEnabled = True
javascript = "web.CallSub('cap', false, javascript: document.getElementsByClassName('C4VMK')[0].innerText)"
w.executeJavascript(WebView1,javascript)

End Sub

Public Sub cap (ca As String)
textcaption.Text=ca.Trim
ProgressDialogHide
End Sub

Public Sub download_Click
w.addJavascriptInterface(WebView1,"web")
w.addWebChromeClient(WebView1,"")
WebView1.LoadUrl(""&edlink.Text)
ProgressDialogShow("copying...")
End Sub
Ok, I see the point. Extract your project as Zip and I will try to find solution for you. ?
 
Upvote 0

pat.hs

Member
Wow thanks for the help ? The code for this section is in the caption module, To see how it gives an error, click on the caption button on the menu page, and after a link from the Instagram page, put it in the text editor and click the download button.
 

Attachments

  • insta_downloader1.zip
    505 KB · Views: 254
Upvote 0

Ivica Golubovic

Active Member
Licensed User
First, you must use WebViewExtra2 library instead WebViewExtra. I will attach it to you. I can not get any response from javascript. Your project now not throwing error, but you must see what is wrong with your javascript.
 

Attachments

  • insta_downloader.zip
    505.1 KB · Views: 261
  • WebViewExtras2.zip
    41.2 KB · Views: 279
Upvote 0

pat.hs

Member
hi again, Thank you very much, it really helped❤️
I try to solve my problem with JavaScript or maybe make a new thread?
First, you must use WebViewExtra2 library instead WebViewExtra. I will attach it to you. I can not get any response from javascript. Your project now not throwing error, but you must see what is wrong with your javascript.
 
Upvote 0
Top