2022-04-20, 10:37:47
Hi Maddire,
You can’t read the values of whereyouat and lengthOfVideo via the Document interface functions OnRequestElementValueById and OnRequestElementValueByName methods as they are javascript variables, not forms.
Those methods are specificly for reading from form data.
There’s no document interface for reading out global variables.
That doesn’t mean you can’t get at that data, but that you should use another method.
Initially I was thinking via webmessage, but that means you would need a user actions such as a click on a button and it seems you want to read out a status.
So in that case you need a bit of custom javascript and run that via anonymous script (actually you can also use executescript, but the anonymous script has some advantages over passing variables and such)
Here’s an example I wrote for a customer, but translated into VB.
And you then get the results like this:
So if I would apply that to your example code then it could look like:
and
Attached is the test code I used (which doesn't have your control, but it does fire the event and returns "1" because it couldn't find the player.)
Hope this helps,
--
Wil
You can’t read the values of whereyouat and lengthOfVideo via the Document interface functions OnRequestElementValueById and OnRequestElementValueByName methods as they are javascript variables, not forms.
Those methods are specificly for reading from form data.
There’s no document interface for reading out global variables.
That doesn’t mean you can’t get at that data, but that you should use another method.
Initially I was thinking via webmessage, but that means you would need a user actions such as a click on a button and it seems you want to read out a status.
So in that case you need a bit of custom javascript and run that via anonymous script (actually you can also use executescript, but the anonymous script has some advantages over passing variables and such)
Here’s an example I wrote for a customer, but translated into VB.
Code:
Private Sub readAppStyleVariable()
Dim Script As String
Dim Params As Variant
Script = " () => {" & vbCrLf
Script = Script & " let appStyle = '';" & vbCrLf
Script = Script & " let app = document.getElementById('cip-hosted-payments-app');" & vbCrLf
Script = Script & " if (app !== null) {" & vbCrLf
Script = Script & " appStyle = app.style.display;" & vbCrLf
Script = Script & " if (appStyle !== null) {" & vbCrLf
Script = Script & " return appStyle;" & vbCrLf
Script = Script & " } else {" & vbCrLf
Script = Script & " return 'null';" & vbCrLf
Script = Script & " }" & vbCrLf
Script = Script & " } else {" & vbCrLf
Script = Script & " return '1';" & vbCrLf
Script = Script & " }" & vbCrLf
Script = Script & "}" & vbCrLf
' connect document
Document.BrowserDispatch (EdgeWebBrowser.Dispatch)
' run the above as anonymous function 1
Document.RunAnonymousFunction 1, Params, Script
End Sub
Code:
Private Sub Document_OnRunAnonymousFunction(ByVal Id As Long, ByVal Params As Variant, ByVal Data As String, ByVal Error As Long)
If Id = 1 Then
Debug.Print "AppStyle = " & Data
End If
End Sub
So if I would apply that to your example code then it could look like:
Code:
Private Sub readPlayerCurrentTime()
Dim Script As String
Dim Params As Variant
Script = " () => {" & vbCrLf
Script = Script & " let playerTime = '';" & vbCrLf
Script = Script & " let app = document.getElementById('player');" & vbCrLf
Script = Script & " if (app !== null) {" & vbCrLf
Script = Script & " playerTime = app.currentTime();" & vbCrLf
Script = Script & " if (playerTime !== null) {" & vbCrLf
Script = Script & " return playerTime;" & vbCrLf
Script = Script & " } else {" & vbCrLf
Script = Script & " return 'null';" & vbCrLf
Script = Script & " }" & vbCrLf
Script = Script & " } else {" & vbCrLf
Script = Script & " return '1';" & vbCrLf
Script = Script & " }" & vbCrLf
Script = Script & "}" & vbCrLf
' connect document
Document.BrowserDispatch (EdgeWebBrowser.Dispatch)
' run the above as anonymous function 2
Document.RunAnonymousFunction 2, Params, Script
End Sub
Code:
Private Sub Document_OnRunAnonymousFunction(ByVal Id As Long, ByVal Params As Variant, ByVal Data As String, ByVal Error As Long)
If Id = 1 Then
Debug.Print "AppStyle = " & Data
End If
If Id = 2 Then
Debug.Print "PlayerTime = " & Data
End If
End Sub
Attached is the test code I used (which doesn't have your control, but it does fire the event and returns "1" because it couldn't find the player.)
Hope this helps,
--
Wil