Page 1 of 1
how can I add cookie before browsing the url?
Posted: Thu Feb 17, 2022 6:32 am
by raychl
I tried to add cookies at onnavigationstarting event, but it didn't work.
Re: how can I add cookie before browsing the url?
Posted: Thu Feb 17, 2022 8:36 am
by salvadordf
Hi,
This is what the API documentation say about AddOrUpdateCookie :
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2cookiemanager?view=webview2-1.0.1108.44#addorupdatecookie
Try adding your cookie with the CookieManager demo and then navigate to that site.
Re: how can I add cookie before browsing the url?
Posted: Sat Feb 19, 2022 2:51 pm
by raychl
Thank you. It's working properly.
Add cookie OnNavigationStarting
....
TempCookie := WVBrowser1.CreateCookie('TestCookie', '1234', 'example.com', '/');
if assigned(TempCookie) then
try
WVBrowser1.AddOrUpdateCookie(TempCookie);
finally
TempCookie := nil;
end;
...
Get cookie OnNavigationCompleted
...
WVBrowser1.GetCookies;
...
Test cookie GetCookiesCompleted
...
var
ACookieSize:SYSUINT;
Acookie: ICoreWebView2Cookie;
AName,AValue,ADomain:PWideChar;
I:Integer;
begin
aCookieList.Get_Count(ACookieSize);
for I := 0 to ACookieSize-1 do
begin
aCookieList.GetValueAtIndex(i,Acookie);
Acookie.Get_name(AName);
Acookie.Get_value(AValue);
Acookie.Get_Domain(ADomain);
if(AName='TestCookie')then
begin
ShowMessage(AValue);
end;
end;
...
how to set cookies to get Expires back
Posted: Sun Jun 19, 2022 12:37 am
by dvbss11
how to set cookies to get Expires back in demo version uCookieVisitor.pas press SetCookies with Expires=now then want to see cookies but Expires = 12/31/1899
Re: how can I add cookie before browsing the url?
Posted: Mon Jun 20, 2022 8:40 am
by salvadordf
Hi,
I just uploaded a new WebView4Delphi version with a TCoreWebView2Cookie.ExpiresDate property.
That property reads and writes the same value as TCoreWebView2Cookie.Expires but in TDateTime format.
Set TCoreWebView2Cookie.ExpiresDate := Now; in the CookieManager demo and you will see the right date.