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.

Two proxies in the same application

dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Two proxies in the same application

Post by dilfich »

How to make two different proxies in the same application?
In one form, and on it two browsers.
Or is this not possible?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Two proxies in the same application

Post by salvadordf »

Hi,

Yes, it is possible to have several browsers using different proxy settings but you have to create the browsers with a different request context.

The MDIBrowser demo has all the code you need. Read the code comments in TChildForm.FormShow.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Two proxies in the same application

Post by dilfich »

Nice!
How to use a single folder with the cookies for both browsers?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Two proxies in the same application

Post by salvadordf »

I'm afraid that's not possible.

The browsers can share the cache and cookies directories only if they have the same request context.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Two proxies in the same application

Post by dilfich »

Hi!
TCefRequestContextRef.New(PathCache, '', False, False, False, False)
How do I specify different Cookie paths?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Two proxies in the same application

Post by salvadordf »

TChromium.CreateBrowser has a parameter called "aCookiesPath" to set the cookies path.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Two proxies in the same application

Post by salvadordf »

Winexcel wrote: Mon Mar 26, 2018 2:27 pm What will happen if i specify the same cache folder?
If two browsers in different processes use the same cache then you will probably get errors, lockups or cache corruption.
Two browsers in the same process can share the same cache.
Winexcel wrote: Mon Mar 26, 2018 2:27 pm And what will happen if i don't use a cache directory at all?
I mean that a cache in memory.
That's correct. That's how you create a web browser in "incognito" mode because all cache is in memory only.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Two proxies in the same application

Post by salvadordf »

Sorry, I had to edit the last comment about cache sharing.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Two proxies in the same application

Post by salvadordf »

Winexcel wrote: Mon Mar 26, 2018 2:41 pm
salvadordf wrote: Mon Mar 26, 2018 2:32 pm That's correct. That's how you create a web browser in "incognito" mode because all cache is in memory only.
Will a cache be free when I close a TFMXChromium instance? Or is it in memory until I closed my application?
The cache is handled internally by Chromium.

I guess it's kept in memory until you close your app or Chromium considers that it has to reduce the memory usage or some cache element is stale.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Two proxies in the same application

Post by salvadordf »

Winexcel wrote: Mon Mar 26, 2018 2:44 pm
salvadordf wrote: Mon Mar 26, 2018 2:32 pm If two browsers in different processes
How can I set this option? Is it about StartSubProcess?
I'm sorry for not explaining this more clearly. I'll give a couple of examples :
  • One app is executed once but it creates several browsers in different tabs : In this situation you can share the cache between all the browsers because they share the same context by default.
  • One app is executed several times at the same moment and each instance creates one browser : In this situation you can't share the cache between different browsers because they use different contexts.


CEF3 only allows to call "cef_execute_process" once per process which means that you can have only one GlobalCEFApp per application.

GlobalCEFApp creates a global context that is used by all the browsers in that application unless you create a different context for each browser.
All browsers in that app that use the same context share the same cache without problems.

if one app creates several browsers with different contexts but they use the same cache directory then you will probably have errors, lockups or cache corruption.
Post Reply