Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetCookies Method Example
#1
Hello,

We are using the AntView WebView2 ActiveX control in our PowerBuilder 2022 R3 application. 

We are trying to use the GetCookies Method to get a list of cookies on the user's profile.

Can anyone provide some sample code of how to do this?

We're getting stuck understanding how to access the OnGetCookieList EVENT that is fired when the GetCookies() Method is invoked.

Appreciate any code, feedback or insight.

Kind Regards,

Greg
Reply
#2
Hi Greg,

I don't have PowerBuilder installed at this moment, but in VB6 the code to get cookies for a current URL looks like this (this is using AntView version 2.x code, so slight changes will be needed for AntView version 1.x - anything AntviewAx2 then should be AntviewAx )

Code:
Option Explicit

Public WithEvents CookieManager As AntviewAx2.AntViewCookieManager
'

Private Sub CookieButton_Click()
' click
  Set CookieManager = EdgeWebBrowser.CookieManager
  CookieManager.GetCookies EdgeWebBrowser.Source
End Sub

Private Sub CookieManager_OnGetCookieList(ByVal HResult As Long, ByVal Args As AntviewAx2.IAntViewCookieList)
  Dim ndx As Integer
  Dim Cookie As AntviewAx2.AntViewCookie
 
  If HResult = 0 Then
    If Args.Count > 0 Then
    For ndx = 0 To (Args.Count - 1)
      Set Cookie = Args.ValueAtIndex(ndx)
      If (Cookie.Name <> "") Then
        MsgBox "name " & Cookie.Name & " = " & Cookie.Value, vbOKOnly, "Cookie " & CStr(ndx + 1) & " of " & CStr(Args.Count)
      End If
    Next
    Else
      MsgBox "No Cookies have been set for this site.", vbOKOnly, "Cookies"
    End If
  End If
End Sub

So in summary, you have to first create an object based on the AntViewCookiemanager interface.

Once you want to use that, assign the WebBrowser object IDispatch pointer of the cookiemanager to your object and invoke the GetCookies method with the URL from the currently browsed page.

The OnGetCookieList event from the Cookiemanager object is where you can enumerate the cookies.
The Args parameter contains a AntViewCookieList object that has a list with all the cookies.

Hope this helps,
--
Wil
Reply
#3
(2025-04-03, 22:21:25)wila Wrote: Hi Greg,

I don't have PowerBuilder installed at this moment, but in VB6 the code to get cookies for a current URL looks like this (this is using AntView version 2.x code, so slight changes will be needed for AntView version 1.x - anything AntviewAx2 then should be AntviewAx )

Code:
Option Explicit

Public WithEvents CookieManager As AntviewAx2.AntViewCookieManager
'

Private Sub CookieButton_Click()
' click
  Set CookieManager = EdgeWebBrowser.CookieManager
  CookieManager.GetCookies EdgeWebBrowser.Source
End Sub

Private Sub CookieManager_OnGetCookieList(ByVal HResult As Long, ByVal Args As AntviewAx2.IAntViewCookieList)
  Dim ndx As Integer
  Dim Cookie As AntviewAx2.AntViewCookie
 
  If HResult = 0 Then
    If Args.Count > 0 Then
    For ndx = 0 To (Args.Count - 1)
      Set Cookie = Args.ValueAtIndex(ndx)
      If (Cookie.Name <> "") Then
        MsgBox "name " & Cookie.Name & " = " & Cookie.Value, vbOKOnly, "Cookie " & CStr(ndx + 1) & " of " & CStr(Args.Count)
      End If
    Next
    Else
      MsgBox "No Cookies have been set for this site.", vbOKOnly, "Cookies"
    End If
  End If
End Sub

So in summary, you have to first create an object based on the AntViewCookiemanager interface.

Once you want to use that, assign the WebBrowser object IDispatch pointer of the cookiemanager to your object and invoke the GetCookies method with the URL from the currently browsed page.

The OnGetCookieList event from the Cookiemanager object is where you can enumerate the cookies.
The Args parameter contains a AntViewCookieList object that has a list with all the cookies.

Hope this helps,
--
Wil

Unfortunately, that is the problem we're seeing. In PowerBuilder, we don't have access to the OnGetCookieList event since we are just getting a handle to the CookieManager object as follows:

Code:
oleobject    lole_cookies
String ls_cookies, ls_uri

lole_cookies = ole_webview2.Object.CookieManager

IF IsValid(lole_cookies) THEN
    lole_cookies.GetCookies(ls_uri)
END IF

So we can issue the GetCookies() Method call, but don't see a way of writing any code in the OnGetCookieList event to get the cokkies.

If you could provide a PowerBuilder example to show what we are missing, that would be greatly appreciated.

Regards,

Greg
Reply
#4
Hi Greg,

Ah yes, PowerBuilder and the handling of events that are not in the main part of the control, I'm slightly remembering some of it and the pain it incurred at the time.
Just did a search and does the following link help?

https://community.sap.com/t5/technology-...p/11497679

--
Wil
Reply
#5
(2025-04-04, 08:51:09)wila Wrote: Hi Greg,

Ah yes, PowerBuilder and the handling of events that are not in the main part of the control, I'm slightly remembering some of it and the pain it incurred at the time.
Just did a search and does the following link help?

https://community.sap.com/t5/technology-...p/11497679

--
Wil

Hello Wil,

Unfortunately that doesn't help us. We are already inserting the AntView ActiveX .ocx control into a Window that exposes all of the main WebView2 Events that you have wrapped like onwebmessagereceived, onwindowclosedrequested, etc.

Our trouble is with the OleObject Property of the OLE Control called CookieManager. In all my years of PowerBuilder Programming, I've never had to deal with an OleObject Property type, whereas other simple datatypes like string, boolean and numeric are straight forward. Any suggestions?

Thanks again for all the response.

Kind Regards,

Greg
[Image: YWIwMzdiNzc2ZGRiNGQwNmE2OTIxNjc1NmUyYjk5...L2Fzaw.png]
Reply
#6
Hi Greg,

It's not very uncommon for an ActiveX control to expose access to its inner interfaces that way. We're just following the WebView2 design here. As you can see that bit is only 2 lines of code in VB6.
Code:
Public WithEvents CookieManager As AntviewAx2.AntViewCookieManager
'
  Set CookieManager = EdgeWebBrowser.CookieManager

First creation of the object and then assigning it, so that the object is actually using the CookieManager interface from the instantiated browser object.

When I look at PowerBuilder syntax then it should be something along the lines of:
Code:
int i

io_CookieManager = CREATE OLEObject

i = io_CookieManager.ConnectToNewObject("AntViewAx.AntViewCookieManager") // i should be 0

// set the dispatch pointer to the one in the current browser object
io_CookieManager.object = edgewebbrowser.CookieManager

Which is ... completely untested.

You might not be able to assign the dispatch pointer or have to assign it in a specific way.
I know that PowerBuilder can handle dispatch pointers as we're using those in the examples for PowerBuilder with the BrowserDispatch method. But they might not have a mechanism to assign an object to an existing interface (which would be weird IMO)

For the document interface we made this:
Code:
int i

io_Document = CREATE OLEObject

i = io_Document.ConnectToNewObject("AntViewAx2.AntViewDocument") // i should be 0

// connect the document interface to the current browser object
io_Document.BrowserDispatch(edgewebbrowser.object.IDispatchPointer)

Even once we get past this, there might still be issues with raising the events.
However I do notice that you have an active developer subscription.

Let's take the discussion on this to email and see if we can get you a solution for this issue.

--
Wil
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)