1

When using DCEF3 TChromium, how can i keep the session alive ?

For instance, if i go to a web-site and login on it, when i close my app and open it again, i need to login again. I want to keep the session alive, just like it would be if i use Google Chrome.

I tried to add 'CefLib' on my app 'uses' clause and set 'CefCache' like the code below, but although i can see files being stored on 'cookies' folder, it seems to make no difference in keeping the session alive :

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  ceflib in 'C:\app\dcef\src\ceflib.pas';

{$R *.res}

begin
  CefCache := 'cookies';
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Thanks in advance.

delphirules
  • 6,443
  • 17
  • 59
  • 108
  • Do you see any cookies being saved by TChromium? See http://stackoverflow.com/a/23723741/80901 for code to set the cookie storage path – mjn Jan 05 '16 at 15:33
  • @mjn the solution on this link seems to use a outdated version of DCEF, the code isn't compiling. – delphirules Jan 05 '16 at 15:41
  • Ok, whatever... If the browser does not store the session id cookie, resuming is not possible, so the question is still: do you see any cookies being saved? – mjn Jan 05 '16 at 15:47
  • I don't see no cookies being saved on the folder i specified on 'CefCache' folder. – delphirules Jan 05 '16 at 15:48
  • Ok, so the next step would be to study the TChromium source code to see if there is a way to make the cookies persistent and load them from disk on application start – mjn Jan 05 '16 at 15:54
  • After changing 'CefCache' to 'cookies', i can see a folder with this name is created on my app's folder and indeed, files are being created there. But even this way, when i close and open the app, the session data is lost... – delphirules Jan 05 '16 at 15:56
  • 1
    Ok, so the next step would be to study the TChromium source code to see if there is a way to load the cookies from disk on application start – mjn Jan 05 '16 at 15:57
  • Thanks for helping, i will try to do it. TChromium is a great component, too bad there is nearly no documentation... – delphirules Jan 05 '16 at 16:01
  • What is the lifespan of those cookies? Does the site generate permanent cookies (they don't have defined any lifespan or their defined lifespan is a long period - more than e month time I believe), short lived cookies (their lifespan is usually less than a day) or perhaps session based cookies meaning that they are only valid until last window/tab of certain site is closed? Also check your cookies managing settings. if you have your browser set to not allow permanent cookies those will never be created by the site you are visiting. – SilverWarior Jan 05 '16 at 16:50
  • @SilverWarior i'm testing with Facebook, i logon with my username and password. Then i close my app, and when i open it again, Facebook is not logged anymore. – delphirules Jan 05 '16 at 17:06
  • 1
    @delphirules That is because by default Facebook uses session based cookies. You could tell Facebook to try creating permanent cookie by checking the "Remember me" checkbox before logging in to the Facebook. And if your browser is configured to allow accepting permanent cookies closing and reopening your application should not require you to login again. That is unless TChromium might have a special setting to keep cookies based on current active session of TChromium itself (something similar as "InPrivate browsing" in internet explorer). – SilverWarior Jan 05 '16 at 17:13
  • @SilverWarior In my test i checked the 'Keep me logged in' box, but even this way, when i close and open my app, i'm not logged anymore. There must be some setting in TChromium to make it work, but i could not figure out yet... – delphirules Jan 05 '16 at 17:18
  • `too bad there is nearly no documentation` - well, it is an open source project. Open source projects depend on community support and/or donations. – mjn Jan 05 '16 at 17:28
  • @mjn you are right, and indeed, i contacted the developer offering a donation. he will accept in the next major update ;) – delphirules Jan 05 '16 at 20:13

1 Answers1

2

A guy form the official's DCEF3 forum provided the solution below, tested and approved !

CookieManager: ICefCookieManager;

FormCreate:
begin
   CookiesPath := ExtractFilePath(Application.ExeName) + 'cookies';
   CookieManager := TCefCookieManagerRef.Global(nil);
   CookieManager.SetStoragePath(CookiesPath, True, nil);
end;

FormClose:   
begin
  CookieManager.FlushStore(nil);
end
mjn
  • 36,362
  • 28
  • 176
  • 378
delphirules
  • 6,443
  • 17
  • 59
  • 108