Page 1 of 1

Re: One tab = One isolated browser

Posted: Fri Nov 23, 2018 8:24 pm
by salvadordf
Hi,

You need to create a different request context for each independent browser.

The MDIBrowser demo can create independent child browsers when you check the "Create a new request context for new browsers" checkbox.

The TChildForm.FormShow procedure in uChildForm.pas calls TCefRequestContextRef.New to create the request context but the first parameter is empty to use "in memory" cache and cookies.

This configuration may use a lot of memory if you navigate for a long time. If that's your case, I would recommend to use a different cache directory for each request context.

Re: One tab = One isolated browser

Posted: Fri Nov 23, 2018 8:58 pm
by salvadordf
You can call TChromium.Browser.Host.RequestContext.GetDefaultCookieManager

Read this page for all the details about that function :
https://magpcss.org/ceforum/apidocs3/pr ... llback%3E)

Re: One tab = One isolated browser

Posted: Fri Nov 23, 2018 9:31 pm
by salvadordf
s1uggard wrote: Fri Nov 23, 2018 9:12 pm Should this code need work?

Code: Select all

  tempContext := TCefRequestContextRef.New(GlobalCEFApp.Cache, '', False, False, False, False);
  cookieManager := tempContext.GetDefaultCookieManager(nil);
  chromium.CreateBrowser(browser.WindowParent, '', tempContext, _appPath + 'chromiumlib\cookies\' + hash + '\', False);
Replace "browser.WindowParent" for the TCEFWindowParent component instance as the CreateBrowser parameter.
I can't test the rest of the code right now but I guess it should be ok.
s1uggard wrote: Fri Nov 23, 2018 9:12 pm And how set custom UserAgent to isolated tab?
Need used OnBeforeResourceLoad or is there an easier way?
They will use the default user agent or GlobalCEFApp.UserAgent.
You can also use the TChromium.OnBeforeResourceLoad event of each browser to replace its user agent header.

Re: One tab = One isolated browser

Posted: Sat Nov 24, 2018 10:34 am
by salvadordf
Let's say that your application creates 2 tabs. Each tab has a browser and each browser has a different directory for the cache and cookies like this :
  • Tab1 with Browser1
    • Cache directory -> c:\MyApp\cache1
    • Cookies directory -> c:\MyApp\cookies1
  • Tab2 with Browser2
    • Cache directory -> c:\MyApp\cache2
    • Cookies directory -> c:\MyApp\cookies2
Those browsers are completely independent because the application used different request contexts and it used different cache and cookies directories.

In this case, if Browser1 stores a new cookie it will be placed in the c:\MyApp\cookies1 directory. Browser2 can't see the cookies from Browser1 because it uses c:\MyApp\cookies2 to store the cookies.

If you need them to share the cookies then they should not be independent and you can create them as usual, sharing the same request context and setting GlobalCEFApp.cache and GlobalCEFApp.cookies.