Page 1 of 2
Set Cookie
Posted: Thu Sep 21, 2017 4:53 pm
by marcoscdoni
Hello, first of all I would like to say that your work is amazing! Congratulations!
To assign a cookie in DCEF3 I use the following code:
TCefFastTask.New(TID_IO, procedure
begin
CookieManager.SetCookie(url, name, value, domain, '/', false, false, false, creationDate, accessDate, expirationDate);
end
);
How would it be possible to do the same using CEF4Delphi?
Thank you!
Re: Set Cookie
Posted: Thu Sep 21, 2017 5:03 pm
by salvadordf
Hi,
I've never done that but in theory it should be done the same way.
CEF4Delphi is based in DCEF3 and many classes are identical.
Re: Set Cookie
Posted: Thu Sep 21, 2017 8:41 pm
by marcoscdoni
It works correctly. Just need to pass last callback parameter a nil. Thank!
Re: Set Cookie
Posted: Sun Oct 21, 2018 5:49 pm
by rgdawson
I find that this works for 32-bit, but does nothing when I compile my application in 64-bit. In 64-bit, the anonymous task does not get executed. No idea why at this point.
R Greg Dawson
Re: Set Cookie
Posted: Sun Oct 21, 2018 6:44 pm
by salvadordf
While I find a way to test this in 64 bits (Lazarus or some friend with a 64 bit Delphi compiler) I added a SetCookie example to the CookieVisitor demo in the context menu.
The CEF3 code comments say that you can call SetCookie in any thread and the example in CookieVisitor do that successfully.
Please, use SetCookie without a task while I try to find a way to see why that task is not working.
Re: Set Cookie
Posted: Sun Oct 21, 2018 7:28 pm
by salvadordf
Please, try this code. I tested it in 64 bits with Lazarus and it works.
Add a custom procedure that calls SeCookie like this :
Code: Select all
procedure SetCookieTask;
var
TempManager : ICefCookieManager;
begin
TempManager := TCefCookieManagerRef.Global(nil);
TempManager.SetCookie('https://www.example.com',
'example_cookie_name',
'1234',
'',
'/',
True,
True,
False,
now,
now,
now,
nil);
end;
Then create a TCefFastTask with that procedure :
Code: Select all
procedure PostCookieTask;
var
TempTask : TCefFastTask;
begin
TempTask := TCefFastTask.Create(SetCookieTask);
CefPostTask(TID_IO, TempTask);
end;
PS : To test this code in Lazarus just add a '@' before SetCookieTask when you create TCefFastTask
Re: Set Cookie
Posted: Mon Nov 26, 2018 4:09 pm
by dilfich
And how can you put a cookie site which is in the frame? It is possible through JS, but it is not quite convenient.
Re: Set Cookie
Posted: Wed Nov 28, 2018 9:34 am
by salvadordf
Sorry for the late answer.
The CookieManager is the only way to set cookies with CEF3 if you don't want to use JavaScript :
https://magpcss.org/ceforum/apidocs3/pr ... nager.html
You can also use JavaScript if it's more convenient :
https://www.w3schools.com/js/js_cookies.asp
https://developer.mozilla.org/en-US/doc ... ent/cookie
Re: Set Cookie
Posted: Wed Nov 28, 2018 10:14 am
by dilfich
About this question, in the demo you have shown the work of CookieManager and it works. But how to use it to set cookies to another site in the frame?
Or is it only through JavaScript..
Re: Set Cookie
Posted: Wed Nov 28, 2018 11:09 am
by salvadordf
The CookieVisitor demo creates a cookie for the "example.com" domain while visiting the "google.com" website.
You can set cookies for any domain whether it's in a frame or it's not even loaded.
Modify the cookie domain in the TCookieVisitorFrm.Chromium1ContextMenuCommand procedure to test your cookie.