V
V
Vladimir Kai2017-03-22 16:00:54
Delphi
Vladimir Kai, 2017-03-22 16:00:54

How to properly use the Chromium component in Delphi?

Good afternoon!
Installed the Chromium component for Delphi.
Works fast, but there was a problem with saving Cookies.
According to the instructions on the site parsing-and-i.blogspot.ru/2013/01/tchromium-cookie... I
used the code from the example on the button's OnClick event:

procedure TDeliveryForm.sBitBtn1Click(Sender: TObject);
var
CookieManager: ICefCookieManager;
CookiesPath  : String;
begin
      CookiesPath := ExtractFilePath(Application.ExeName) + DefaultCookiesDir + 'Ddelivery';
      CookieManager := TCefCookieManagerRef.Global(nil);
      CookieManager.SetStoragePath(CookiesPath, True, nil);
      Chromium1.Load('https://cabinet.ddelivery.ru/');
end;

The folder and Cookies files are created by the program, but the next time it is launched, the authorization on the requested site is reset.
What am I doing wrong?
On the Internet, only this instruction and others like it.
All I need is that the authorization is not reset every time ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kai, 2017-03-24
@gold_dezmor

Well, I actually figured it out..

procedure TDeliveryForm.sBitBtn1Click(Sender: TObject);
var
CookieManager: ICefCookieManager;
CookiesPath  : String;
CefBack: ICefCompletionCallback;
begin
      CookiesPath := ExtractFilePath(Application.ExeName) + DefaultCookiesDir + 'Site1'; // Задаем путь к "печенькам"
    //  ForceDirectoriesUTF8(CookiesPath); // если пути нет то создаем его
      CookieManager := TCefCookieManagerRef.Global(CefBack); // подключаемся к менеджеру печенек
      CookieManager.SetStoragePath(CookiesPath, True, CefBack); // устанавливаем путь к хранилищу "печенек"
      Chromium1.Load('https://cabinet.SITE.ru/user');   // загрузка страницы
end;

A
ArtLivinov, 2020-08-21
@ArtLivinov

For CEF3, the cookie file can be set with the code

procedure TForm1.Button1Click(Sender: TObject);
var
  CookieManager: ICefCookieManager;
  CookiesPath: String;
begin
  CookiesPath:= ExtractFilePath(Application.ExeName) + 'dirForCookie1\';//DefaultCookiesDir
  CookieManager:= TCefCookieManagerRef.Global(nil);
  CookieManager.SetStoragePath(CookiesPath,False,nil);
end;

Checked. The code was taken from here blog.ivru.net/?id=211 in the same article there is a more detailed description of how cookies are assigned, in particular that those that were about pressing the button will get stuck. And there is also a code on how to get cookies that are already set for the component, including those that are in the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question