VB6 - Cookie Sync example
File(s): frmCookieSyncDemo.frm
We have added a demo form for using the Cookie Synchronous interface to the examples.
Here's a screenshot of that demo.

The code of that demo is:
Private Sub CookieButton_Click()
Dim Err As Integer
Dim Cookies As String
Dim CookieManager As AntViewAx2.AntViewCookieManager
Dim Cookie As AntViewAx2.AntViewCookie
' See also button "Cookies" in the frmBrowser demo
Set CookieManager = EdgeWebBrowser.CookieManager
Err = CookieManager.GetCookiesAsJsonSync(EdgeWebBrowser.Source, Cookies)
MsgBox "Cookies are:" & vbCrLf & Cookies
' Change cookie two from coconut to strawberry
Err = CookieManager.GetCookieSync(EdgeWebBrowser.Source, "two", Cookie)
If Err = 0 Then
MsgBox "Cookie 'two' is now " & Cookie.Value & " and we're changing it into strawberry" & vbCrLf & "Plus add a new cookie biscuit."
Cookie.Value = "strawberry"
CookieManager.AddOrUpdateCookie Cookie
Else
MsgBox "Error retrieving cookie two " & CStr(Err)
End If
' add a new cookie
Set Cookie = CookieManager.CreateCookie("extra", "biscuit", "www.antwise.com", "/")
CookieManager.AddOrUpdateCookie Cookie
End Sub
Private Sub Form_Load()
Dim LicenseText As String
Dim Days As Integer
Dim eStatus As TxUnlockStatus
On Error Resume Next
Me.Show
Form_Resize
LicenseText = "AntView License Status = "
EdgeWebBrowser.UnlockControl "ExampleCompany", "WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F"
eStatus = EdgeWebBrowser.UnlockStatus
If (eStatus = usLicensed) Then
LicenseText = LicenseText & "Licensed"
End If
If (eStatus = usDemoLicense) Then
Days = EdgeWebBrowser.DemoDaysLeft
LicenseText = LicenseText & "Demo with " & (CStr(Days)) & " Days Left."
End If
If (eStatus = usUnlicensed) Then
LicenseText = LicenseText & "Expired demo license."
End If
InfoText.Text = LicenseText
EdgeWebBrowser.CreateWebView
EdgeWebBrowser.EventsUseHexadecimal = True ' For VB we need to use the Hexadecimal event variants
EdgeWebBrowser.Navigate "https://www.antwise.com/demo/cookies.html"
End Sub
Private Sub Form_Resize()
On Error Resume Next
EdgeWebBrowser.Width = Me.ScaleWidth - 200
EdgeWebBrowser.Height = Me.ScaleHeight - (InfoText.Height) - 140
InfoText.Top = Me.ScaleHeight - InfoText.Height - 20
CookieButton.Top = Me.ScaleHeight - CookieButton.Height - 20
CookieButton.Left = Me.ScaleWidth - CookieButton.Width - 100
End Sub
The interesting part there is in the CookieButton_Click method.
We first get the CookieManager interface into a local variable for easier access.
Set CookieManager = EdgeWebBrowser.CookieManager
Then we ask for all of the cookies in the page stored for the current URL via GetCookiesAsJsonSync, this is then returned as a Json formatted string into the variable Cookies. Which we subsequently print to the user.
Err = CookieManager.GetCookiesAsJsonSync(EdgeWebBrowser.Source, Cookies)
MsgBox "Cookies are:" & vbCrLf & Cookies
Since we manage this page, we know that Cookie "two" exists. So we can ask for cookies "two" via GetCookieSync without having to enumerate the available cookies.
We then change this cookie's value to "strawberry" and ask the CookieManager to save this new value (AddOrUpdateCookie) to the html page.
Err = CookieManager.GetCookieSync(EdgeWebBrowser.Source, "two", Cookie)
If Err = 0 Then
MsgBox "Cookie 'two' is now " & Cookie.Value & " and we're changing it into strawberry" & vbCrLf & "Plus add a new cookie biscuit."
Cookie.Value = "strawberry"
CookieManager.AddOrUpdateCookie Cookie
Else
MsgBox "Error retrieving cookie two " & CStr(Err)
End If
Finally, we add a new cookie "extra' with the CreateCookie method and save that.
' add a new cookie
Set Cookie = CookieManager.CreateCookie("extra", "biscuit", "www.antwise.com", "/")
CookieManager.AddOrUpdateCookie Cookie
AntView - The MS Edge WebView2 ActiveX control Date last changed: 11/05/2025