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
-
- Posts: 460
- Joined: Thu Aug 10, 2017 12:40 pm
Feature request
Hi,
Long-time CEF4Delphi user / fan here... I really love this project, thank you very much Salvador !
There are 2 features that would really be awesome if could happen, at least for my use case :
- Set specific user agent for each TChromium instance ; at the moment the user agent is global, ie, same for all TChromium instances.
- Delete or change cookies/cache dir without having to close the app before. If i want to change to cookies dir, i can't do it unless i close my app before.
Is these possible in the near future ?
Thanks !
Long-time CEF4Delphi user / fan here... I really love this project, thank you very much Salvador !
There are 2 features that would really be awesome if could happen, at least for my use case :
- Set specific user agent for each TChromium instance ; at the moment the user agent is global, ie, same for all TChromium instances.
- Delete or change cookies/cache dir without having to close the app before. If i want to change to cookies dir, i can't do it unless i close my app before.
Is these possible in the near future ?
Thanks !
- salvadordf
- Posts: 4052
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Feature request
Thank you so much for all your donations and support in Patreon!!!thefunkyjoint wrote: ↑Thu Jan 23, 2020 11:34 pm Long-time CEF4Delphi user / fan here... I really love this project, thank you very much Salvador !
You can modify the HTTP headers in the normal resource requests to set a custom user agent whenever you want but JavaScript will keep using the user agent you set when you initialize CEF.thefunkyjoint wrote: ↑Thu Jan 23, 2020 11:34 pm There are 2 features that would really be awesome if could happen, at least for my use case :
- Set specific user agent for each TChromium instance ; at the moment the user agent is global, ie, same for all TChromium instances.
In order to fix that we would need to modify Chromium's code, CEF's code and CEF4Delphi's code.
I've never modified Chromium's code and even if I could do that you would need to build custom CEF binaries with all those modifications each time you upgrade your application.
You can do that right now and the MDIBrowser demo has all the code you need :thefunkyjoint wrote: ↑Thu Jan 23, 2020 11:34 pm - Delete or change cookies/cache dir without having to close the app before. If i want to change to cookies dir, i can't do it unless i close my app before.
https://github.com/salvadordf/CEF4Delph ... m.pas#L203
Whenever you need to use a different cache directory you just need to create a new TChromium with a TCEFWindowParent and set a custom ICefRequestContext parameter when you call TChromium.CreateBrowser.
The custom ICefRequestContext would use a different cache directory and the new browser would be completely independent from the previous browsers.
For example, if you use the "c:\old_cache" directory when you initialize CEF you can have several browsers using that cache directory if you don't set a ICefRequestContext parameter when you call TChromium.CreateBrowser.
Later you can create a new independent browser using "c:\new_cache". You would have to create an instance of ICefRequestContext with this code :
Code: Select all
TempNewContext1 := TCefRequestContextRef.New('c:\new_cache', '', False, False, False);
Code: Select all
TempNewChromium1.CreateBrowser(TempNewCEFWindowParent1, '', TempNewContext1);
In case you need a new browser using "c:\old_cache" again then you can create it with a NIL ICefRequestContext parameter when you call TChromium.CreateBrowser.
However, if you need a second browser using "c:\new_cache" then you would need to call TChromium.ShareRequestContext to get the new ICefRequestContext instance in the "aContext" parameter.
Code: Select all
if TempNewChromium1.ShareRequestContext(TempNewContext2, nil) then
TempNewChromium2.CreateBrowser(TempNewCEFWindowParent2, '', TempNewContext2);
In this situation TempNewChromium1 and TempNewChromium2 would use "c:\new_cache" while the rest of the browsers would use "c:\old_cache".
-
- Posts: 18
- Joined: Mon Oct 07, 2019 7:53 am
Re: Feature request
Hello!
Thanks for the great product!
I am not the author of the topic, but I have a similar question
I can change the cookie folder without calling CreateBrowser:
But the cache folder does not change. How to change the cache folder without calling CreateBrowser?
And the second question
I create contexts in two browsers in the same way
without ShareRequestContext
It is not right? Need to create through ShareRequestContext?
Thanks for the great product!
I am not the author of the topic, but I have a similar question
I can change the cookie folder without calling CreateBrowser:
Code: Select all
SurfWebBrowserChr.ShareRequestContext(Context);
TempCookieManager: = Context.GetDefaultCookieManager (nil);
TempCookieManager.SetStoragePath('c:\new_cache', false, nil);
And the second question
I create contexts in two browsers in the same way
Code: Select all
Context: = TCefRequestContextRef.New('c:\old_cache', '', False, False, True, False);
SurfWebBrowserChr.CreateBrowser (SurfWebBrowserChrParent, '', Context);
It is not right? Need to create through ShareRequestContext?
- salvadordf
- Posts: 4052
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Feature request
Hi,
CEF had a lot of API changes in the last months and CefCookieManager.SetStoragePath doesn't exist now :
https://bitbucket.org/chromiumembedded/ ... orkservice
It's not possible to run several instances of your application that use the same cache directory. However, you can create as many browsers as you want in the same application that use the same cache directory.
I haven't checked Chromium's code to see if it's possible to create several contexts with TCefRequestContextRef.New sharing the same cache in the same application but if the CEF API has a specific function to do that, I would definitively recommend using it.
Some of those functions were deprecated and they are not used in the latest CEF4Delphi version.micmorozov wrote: ↑Fri Jan 24, 2020 9:15 am I can change the cookie folder without calling CreateBrowser:But the cache folder does not change. How to change the cache folder without calling CreateBrowser?Code: Select all
SurfWebBrowserChr.ShareRequestContext(Context); TempCookieManager: = Context.GetDefaultCookieManager (nil); TempCookieManager.SetStoragePath('c:\new_cache', false, nil);
CEF had a lot of API changes in the last months and CefCookieManager.SetStoragePath doesn't exist now :
https://bitbucket.org/chromiumembedded/ ... orkservice
These are the CEF code comments for ShareRequestContext :micmorozov wrote: ↑Fri Jan 24, 2020 9:15 am I create contexts in two browsers in the same waywithout ShareRequestContextCode: Select all
Context: = TCefRequestContextRef.New('c:\old_cache', '', False, False, True, False); SurfWebBrowserChr.CreateBrowser (SurfWebBrowserChrParent, '', Context);
It is not right? Need to create through ShareRequestContext?
Code: Select all
///
// Creates a new context object that shares storage with |other| and uses an
// optional |handler|.
///
I haven't checked Chromium's code to see if it's possible to create several contexts with TCefRequestContextRef.New sharing the same cache in the same application but if the CEF API has a specific function to do that, I would definitively recommend using it.
Re: Feature request
Code: Select all
TempManager := TCefCookieManagerRef.Global(nil);
When i turn to
TempManager: = TCefCookieManagerRef.Global (nil);
This is the default
And the rest of the samples are not available to me.
Code: Select all
TempManager:= RequestContext.GetHandler.GetCookieManager;
Code: Select all
(Chrom.CreateBrowser(ChromWindow, '',RequestContext))
- salvadordf
- Posts: 4052
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Feature request
Try this for each browser :
Code: Select all
TempManager := TChromium.Browser.Host.RequestContext.GetCookieManager(nil);
-
- Posts: 460
- Joined: Thu Aug 10, 2017 12:40 pm
Re: Feature request
Do you have any examples about how to do it, please ?You can modify the HTTP headers in the normal resource requests to set a custom user agent whenever you want but JavaScript will keep using the user agent you set when you initialize CEF.
Thanks !
- salvadordf
- Posts: 4052
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Feature request
There's an example here :
https://github.com/salvadordf/CEF4Delph ... r.pas#L428
That demo searches for the "Accept-Encoding" header to set it to "identity" but you would have to search "User-Agent" and set it to your custom user agent string.
There's a new TChromium.SetUserAgentOverride procedure that you can also try to use a custom user agent.
https://github.com/salvadordf/CEF4Delph ... r.pas#L428
That demo searches for the "Accept-Encoding" header to set it to "identity" but you would have to search "User-Agent" and set it to your custom user agent string.
There's a new TChromium.SetUserAgentOverride procedure that you can also try to use a custom user agent.
-
- Posts: 460
- Joined: Thu Aug 10, 2017 12:40 pm
Re: Feature request
I'm still confused on how to do this in the correct way.You can do that right now and the MDIBrowser demo has all the code you need :
https://github.com/salvadordf/CEF4Delph ... m.pas#L203
Whenever you need to use a different cache directory you just need to create a new TChromium with a TCEFWindowParent and set a custom ICefRequestContext parameter when you call TChromium.CreateBrowser.
Let's say my app has 2 instances of TChromium. Now i want to use a different cookies dir, so i want to free these two instances and create another new 2 instances of the new cookies dir, but without having to close my app.
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 ?
Re: Feature request
I do this way, GlobalCEFApp.Cache not specify,
in GlobalCEFApp.RootCache specify the parent folder where the caches will be stored.
Dynamically creating CEFWindowParent/TChromium and specify requestContext
Now if I want to change the cache path, then I destroy instances CEFWindowParent/TChromium
And again dynamically creating CEFWindowParent/TChromium.
Specify RequestContext with the other path to cache.
in GlobalCEFApp.RootCache specify the parent folder where the caches will be stored.
Dynamically creating CEFWindowParent/TChromium and specify requestContext
Code: Select all
RequestContext := TCefRequestContextRef.New(PathToCache, '', false, false, false);
Chromium1.CreateBrowser(CEFWindowParent1, '', RequestContext);
Code: Select all
Chromium1.CloseBrowser(true);
CEFWindowParent1.Free;
Specify RequestContext with the other path to cache.
Code: Select all
RequestContext := TCefRequestContextRef.New(OtherPathToCache, '', false, false, false);
Chromium1.CreateBrowser(CEFWindowParent1, '', RequestContext);