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.

History and cache

Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

History and cache

Post by Hitman »

Hi guys,
could someone please help me with this?
I need to be able to clear cache, history, form data, everything from the browser.
I have a refresh button where i would like to place my code to clear everything after each use.

How this is done?

Many thanks in advance
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: History and cache

Post by salvadordf »

Hi,

CEF doesn't allow to delete the cache files while the browser is running but you can set GlobalCEFApp.DeleteCache and GlobalCEFApp.DeleteCookies to TRUE before calling GlobalCEFApp.StartMainProcess to delete the cache and cookies just before CEF is initialized.

Your app can save a registry value, INI value or whatever you like. The next time your app is executed it will read that value and set GlobalCEFApp.DeleteCache and GlobalCEFApp.DeleteCookies.
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: History and cache

Post by Hitman »

Hi!
thanks a lot!
how this is done?
any samples?

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

Re: History and cache

Post by salvadordf »

Read these pages to use INI files and the registry :
http://docwiki.embarcadero.com/RADStudi ... MemIniFile
http://docwiki.embarcadero.com/RADStudi ... _TRegistry

The simplest DPR code to delete the cache and cookies would be :

Code: Select all

program Project1;

uses
  Vcl.Forms,
  WinApi.Windows,
  uCEFApplication,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}

begin
  GlobalCEFApp := TCefApplication.Create;
  
  if MustDeleteCache then
    begin
      GlobalCEFApp.DeleteCache := True;
      GlobalCEFApp.DeleteCookies := True;
    end;  
  
  if GlobalCEFApp.StartMainProcess then
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end;

  GlobalCEFApp.Free;
end.
MustDeleteCache would be a custom function that reads the registry or the INI file.
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: History and cache

Post by Hitman »

Hi!
thank you.
I know how to create and use ini files but not sure what the ini file has got to do with the history and cache of the browser.
The goal is to prevent browser creating history and cache.

So what i am saying is,
no history, no cache at all.

Is there any samples of how to prevent browser from collecting history and cache?

About this code,
shouldn't i be okay if i add the following lines to my own DPR?

{ if MustDeleteCache then
begin
GlobalCEFApp.DeleteCache := True;
GlobalCEFApp.DeleteCookies := True;
end; }

I have a "Refresh" button and "Back" button in my app, i would like to be able to clear up everything when one of these buttons clicked.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: History and cache

Post by salvadordf »

Hitman wrote: Fri Apr 20, 2018 1:12 pm Hi!
thank you.
I know how to create and use ini files but not sure what the ini file has got to do with the history and cache of the browser.
I mention them in case you wanted to add a "clear cache" function in your app. That function would set a custom value value in the ini or the registry that your app would read next time it runs to set GlobalCEFApp.DeleteCache and GlobalCEFApp.DeleteCookies to true.

This way your app would use a cache in the users hard drive but your app or the user could clear it the next it executes your app.
Hitman wrote: Fri Apr 20, 2018 1:12 pm The goal is to prevent browser creating history and cache.

So what i am saying is,
no history, no cache at all.

Is there any samples of how to prevent browser from collecting history and cache?
That's even easier! :)
Just leave GlobalCEFApp.cache and GlobalCEFApp.cookies blank.

All the demos use the default (empty) values GlobalCEFApp.cache and GlobalCEFApp.cookies. This way CEF uses "in memory" cache.
Hitman wrote: Fri Apr 20, 2018 1:12 pm About this code,
shouldn't i be okay if i add the following lines to my own DPR?

{ if MustDeleteCache then
begin
GlobalCEFApp.DeleteCache := True;
GlobalCEFApp.DeleteCookies := True;
end; }

I have a "Refresh" button and "Back" button in my app, i would like to be able to clear up everything when one of these buttons clicked.
The refresh button could call TChromium.ReloadIgnoreCache to download the web page ignoring the cached resources.

You can also set HTTP headers to download all the resources again. If I remember correctly, you would have to set TChromium.CustomHeaderName with "Cache-Control" and TChromium.CustomHeaderValue with "no-cache".
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: History and cache

Post by Hitman »

Okay,
many thanks!
please clear me up,

"Just leave GlobalCEFApp.cache and GlobalCEFApp.cookies blank."
As far as i know,
i am not asking for any cache or cookies or history while running the browser, it keeps all by itself :o
How do i leave them blank?
do you mean i should not add the following code to my DPR at all?
{if MustDeleteCache then
begin
GlobalCEFApp.DeleteCache := True;
GlobalCEFApp.DeleteCookies := True;
end;}

I am already using this and it has no effect :|
TChromium.ReloadIgnoreCache
It still brings the data inserted into the web form.
All i want to do is to prevent it bringing any previously inserted data back.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: History and cache

Post by salvadordf »

Hitman wrote: Fri Apr 20, 2018 2:16 pm Okay,
many thanks!
please clear me up,

"Just leave GlobalCEFApp.cache and GlobalCEFApp.cookies blank."
As far as i know,
i am not asking for any cache or cookies or history while running the browser, it keeps all by itself :o
How do i leave them blank?

Code: Select all

GlobalCEFApp.cache := '';
GlobalCEFApp.cookies := '';
Hitman wrote: Fri Apr 20, 2018 2:16 pm do you mean i should not add the following code to my DPR at all?
{if MustDeleteCache then
begin
GlobalCEFApp.DeleteCache := True;
GlobalCEFApp.DeleteCookies := True;
end;}
You don't need that if you don't use a disk cache.
Hitman wrote: Fri Apr 20, 2018 2:16 pm I am already using this and it has no effect :|
TChromium.ReloadIgnoreCache
It still brings the data inserted into the web form.
All i want to do is to prevent it bringing any previously inserted data back.
I tried to replicate this in MiniBrowser and the form fields don't keep the previous values. I tried these websites :
https://www.w3schools.com/php/php_form_complete.asp
http://www.echoecho.com/htmlforms01.htm

Perhaps you can avoid that problem if you use a SSL certificate in your web server.
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: History and cache

Post by Hitman »

Do you use the following?
TChromium.ReloadIgnoreCache
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: History and cache

Post by salvadordf »

I used MiniBrowser without modifications which uses TChromium.Reload but I just tested those web pages again calling TChromium.ReloadIgnoreCache and I still can't replicate this issue. The form values are cleared after reloading using TChromium.ReloadIgnoreCache or TChromium.Reload.

Please try the MiniBrowser demo, click on the top-right button and select "Preferences". Then type "Cache-Control" without quotes in the Name edit box and "no-cache" without quotes in the Value edit box. Click OK and visit any website. It will download all resources ignoring the cache and the form values are cleared even when you click the "left" and "right" navigation buttons.
Post Reply