Contents - Index - Top


PowerBuilder - Cookie management example

 

The AntView control has an extra interface for managing cookies. This is the AntViewCookieManager interface and it is modeled after WebView2's native interface. This includes the OnGetCookieList event.

Sadly PowerBuilder cannot directly access events that are outside of the main interface.

 

Because of that we have added synchronous alternatives to work around this limitation.

First there is GetCookiesAsJsonSync which returns a Json string with all the cookies for the URL passed. This allows you to access the individual cookie contents.

Then there is GetCookieSync which returns a cookie object so you can manipulate each individual cookie.

 

Here's an explanation of the synchronous code example as found in the web browser demo:

 

The address box now has an option  https://www.antwise.com/demo/cookies.html as a test page to experiment with.

 

 

When you load that html page, it will set three cookies for it via javascript. This page also has a button that enumerates all the cookies -accessible from javascript- for the page. If you click it, it will show you the following.

 

 

The Web Browser demo has a button "Cookies" that will first list all of the available cookies loaded in the document for the current URL.

Followed by changing the value of cookie "two" to "strawberry" and adding a new cookie called "extra" with the value "biscuit".

 

Here's the code for that.

 

int i

int err

int count

String ls_cookies

String ls_url

String ls_name

OLEOBJECT io_CookieManager

OLEOBJECT io_Cookie

io_cookieManager = edgewebbrowser.object.CookieManager

 

ls_url = edgewebbrowser.object.source

ls_cookies = "" // must initialize

messageBox("url = ", ls_url)

err = io_CookieManager.GetCookiesAsJsonSync(ls_url,REF ls_cookies)

messageBox('Cookies = ', ls_cookies)

 

// Change cookie two from coconut to strawberry

ls_name = "two"

err = io_CookieManager.GetCookieSync(ls_url, ls_name, REF io_Cookie)

IF err = 0 THEN

      io_Cookie.value = "strawberry"

      io_CookieManager.AddOrUpdateCookie(io_Cookie)

ELSE

      MessageBox("cookie not found",ls_name)

END IF      

// add a new cookie

io_Cookie = io_CookieManager.createCookie("extra","biscuit","antwise.com","/")

io_CookieManager.AddOrUpdateCookie(io_Cookie)

 

After the button in the PowerBuilder part with the code above was clicked, you can then click the button at the html page again and it shows you the following:

 

 


AntView - The MS Edge WebView2 ActiveX control Date last changed: 11/05/2025