Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
how can I add cookie before browsing the url?
how can I add cookie before browsing the url?
I tried to add cookies at onnavigationstarting event, but it didn't work.
- salvadordf
- Posts: 4563
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: how can I add cookie before browsing the url?
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.
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?
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;
...
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
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
- salvadordf
- Posts: 4563
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: how can I add cookie before browsing the url?
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.
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.