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.

Feature request

User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Feature request

Post by salvadordf »

thefunkyjoint wrote: Wed Sep 02, 2020 6:40 pm What should be the correct procedure ? What i'm thinking :
1 - Free / destroy current TChromium instances (just call .free method for each instance ?)
2 - Create two new instances with the new cookie dir
Is this correct ?
Yes, that's correct but call .free at the right moment.

Follow the browser destruction steps described in the demos : TChromium.CloseBrowser -> TChromium.OnClose -> TCEFWindowParent.Free (in the app main thread) -> TChromium.OnBeforeClose -> TChromium.Free (in the app main thread)
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: Feature request

Post by Student »

TChromium.OnBeforeClose -> TChromium.Free
I didn't do this in my app, I didn't think it was necessary, and your demos don't have it either.
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Feature request

Post by salvadordf »

You're right, it's not necessary but I wanted to highlight that all the previous steps must be completed before destroying the TChromium component.

The demos call TChromium.Free automatically when the form or frame that contains the component is destroyed and that happens after the destruction sequence is completed.
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: Feature request

Post by Student »

Okay, thanks for the detailed answer.
thefunkyjoint
Posts: 459
Joined: Thu Aug 10, 2017 12:40 pm

Re: Feature request

Post by thefunkyjoint »

salvadordf wrote: Thu Sep 03, 2020 7:02 am
thefunkyjoint wrote: Wed Sep 02, 2020 6:40 pm What should be the correct procedure ? What i'm thinking :
1 - Free / destroy current TChromium instances (just call .free method for each instance ?)
2 - Create two new instances with the new cookie dir
Is this correct ?
Yes, that's correct but call .free at the right moment.

Follow the browser destruction steps described in the demos : TChromium.CloseBrowser -> TChromium.OnClose -> TCEFWindowParent.Free (in the app main thread) -> TChromium.OnBeforeClose -> TChromium.Free (in the app main thread)
I'm missing something, because even if i create a new browser with the correct cookies dir on the context, the new browser will still use the cookies dir set on 'GlobalCEFApp.Cache' option.

What i want is : when the use open the app for the first time, i set a 'default' cookies dir. Then the user have a combobox to select different cookies folders.

When calling TCefRequestContextRef.New, should i pass the complete cookies dir or olny the sub-directory inside GlobalCEFApp.RootCache ?

Any ideas ?
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Feature request

Post by salvadordf »

Each time a user selects the option to use a different "cookies" directory the application must create a new browser because the cookies are stored inside the cache directory and you can only specify the cache directory when you're about to create a new browser.

The directory structure should be something like this :

Code: Select all

c:\some_random_dir\rootcache\cache_a
c:\some_random_dir\rootcache\cache_b
c:\some_random_dir\rootcache\cache_c
c:\some_random_dir\rootcache\cache_d
In this case GlobalCEFApp.RootCache := 'c:\some_random_dir\rootcache';
But the browsers can set the cache parameter for TCefRequestContextRef.New with any of these values :
  • c:\some_random_dir\rootcache\cache_a
  • c:\some_random_dir\rootcache\cache_b
  • c:\some_random_dir\rootcache\cache_c
  • c:\some_random_dir\rootcache\cache_d
thefunkyjoint
Posts: 459
Joined: Thu Aug 10, 2017 12:40 pm

Re: Feature request

Post by thefunkyjoint »

Here is what is happening :

I always used a 'workaround' method to select different cookies directories, which consists in close my app and reopen it again setting GlobalCEFApp.Cache to the new cookies dir i want, and passing nil to TCefRequestContextRef.New context.

This always worked, but has the inconvenient to the user having to close and reopen the app whenever he wants to switch cookies dir.

So that's why i'm trying to implement this new way , which consists in destroy the browsers and re-create it with the new context.

So here is what i'm doing :

1 - I set GlobalCEFApp.RootCache to ''C:\Users\admin\AppData\Roaming\Myapp'

2 - I leave GlobalCEFApp.Cache alone, don't set anything to it.

3 - I set TCefRequestContextRef.New('C:\Users\admin\AppData\Roaming\Myapp\Cookies', '', false, false, false);

4 - Browser is created and i can see the 'C:\Users\admin\AppData\Roaming\Myapp\Cookies' directory was created indeed.

4 - I then navigate to a site that requires login, for instance Facebook.com, and log in on it.

5 - I close my app.

6 - I open my app again BUT i'm not logged on Facebook anymore.

If i switch to the 'old' method (specify 'C:\Users\admin\AppData\Roaming\Myapp\Cookies' on GlobalCEFApp.Cache and pass nil to the TCefRequestContextRef.New) , it works again.

What am i missing ? :?
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: Feature request

Post by Student »

Demo MDIBrowser works for you?
In dpr add code

Code: Select all

GlobalCEFApp.Cache := '';
GlobalCEFApp.RootCache := 'GlobalCache';
In uChildForm.pas event formshow change code

Code: Select all

TempContext := TCefRequestContextRef.New(GlobalCEFApp.RootCache+'\Cache1\', '', False, False, False)
Log in to FaceBook, and re-launch app check your auth.
thefunkyjoint
Posts: 459
Joined: Thu Aug 10, 2017 12:40 pm

Re: Feature request

Post by thefunkyjoint »

I don't know why but it seems to be working now, with one little issue : the cookies dir i already have before aren't working, i'm having to login again in all websites using this 'new' method ; only after i did this the login data became persistent. Any reason for this ?

Thanks ! :)
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: Feature request

Post by Student »

thefunkyjoint wrote: Thu Sep 03, 2020 11:58 pm I don't know why but it seems to be working now, with one little issue : the cookies dir i already have before aren't working, i'm having to login again in all websites using this 'new' method ; only after i did this the login data became persistent. Any reason for this ?

Thanks ! :)
In RootCache dir created a file LocalPrefs.json, it is stored there encrypted_key, with it, chromium gets access to the reading cookies in your caches, therefore, previously created cookies he can't read it.
Post Reply