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.
Set Cookie
-
- Posts: 25
- Joined: Thu Sep 21, 2017 4:33 pm
Set Cookie
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!
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!
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Set Cookie
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.
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.
-
- Posts: 25
- Joined: Thu Sep 21, 2017 4:33 pm
Re: Set Cookie
It works correctly. Just need to pass last callback parameter a nil. Thank!
Re: Set Cookie
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
R Greg Dawson
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Set Cookie
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.
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.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Set Cookie
Please, try this code. I tested it in 64 bits with Lazarus and it works.
Add a custom procedure that calls SeCookie like this :
Then create a TCefFastTask with that procedure :
PS : To test this code in Lazarus just add a '@' before SetCookieTask when you create TCefFastTask
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;
Code: Select all
procedure PostCookieTask;
var
TempTask : TCefFastTask;
begin
TempTask := TCefFastTask.Create(SetCookieTask);
CefPostTask(TID_IO, TempTask);
end;
Re: Set Cookie
And how can you put a cookie site which is in the frame? It is possible through JS, but it is not quite convenient.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Set Cookie
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
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
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..
Or is it only through JavaScript..
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Set Cookie
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.
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.