Page 1 of 1

CefCreateUrl function is not working

Posted: Fri Mar 25, 2022 5:31 pm
by igor666
Hi, the CefCreateUrl function is not working. For example:

Code: Select all

var
  urlParts: TUrlParts;
begin
  urlParts.scheme := 'https';
  urlParts.host := 'site.com';
  urlParts.origin := 'https://site.com/';
  urlParts.path := '/work.php';
  urlParts.query := 'mode=some_mode&param=some_param';
  
  request.query := CefCreateUrl(urlParts);
end;
As a result request.query is https://site.com/work.php without query.
I first noticed it in version 96, installed version 99, same result, "query" is lost when creating url from parts.
What am I doing wrong? :D Thanks for the answer.

Re: CefCreateUrl function is not working

Posted: Sat Mar 26, 2022 10:22 am
by salvadordf
I added a button in the SimpleBrowser2 demo with this code in the OnClick event :

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  TempURL : TUrlParts;
begin
  // Original URL -> https://www.briskbard.com/forum/viewtopic.php?p=7966#p7966
  TempURL.spec     := '';
  TempURL.scheme   := 'https';
  TempURL.username := '';
  TempURL.password := '';
  TempURL.host     := 'www.briskbard.com';
  TempURL.port     := '';
  TempURL.origin   := 'https://www.briskbard.com';
  TempURL.path     := '/forum/viewtopic.php';
  TempURL.query    := 'p=7966';
  TempURL.fragment := 'p7966';

  AddressEdt.Text  := CefCreateUrl(TempURL);
end;
When I click it the resulting URL is the same as the original URL, including the query and fragment.

CEF doesn't allow to modify the request parameter in all TChromium events. Perhaps you are trying to modify the request in an event where the request is read-only.

Re: CefCreateUrl function is not working

Posted: Sat Mar 26, 2022 7:48 pm
by igor666
It seems I gave a bad example, I'm sorry, I did not check it, it really works. I think I understand when it doesn't work, in the same SimpleBrowser2 example, I replaced the Go button code with the following

Code: Select all

procedure TForm1.GoBtnClick(Sender: TObject);
var
  url: TUrlParts;
begin
  // This will load the URL in the edit box
  //Chromium1.LoadURL(AddressEdt.Text);
  CefParseUrl(AddressEdt.Text,url);
  url.query := 'mode=asd&asd=hgf';
  AddressEdt.Text := CefCreateUrl(url);
end;
As a result, instead of google.com with parameters, I got just a link http://www.google.com/. It seems that if we first parse the url using the CefParseUrl function, and then change this url, then the CefCreateUrl function does not work correctly. Below I am attaching two screenshots from the debugger, pay attention to query and spec. I added a parameter to the address bar and clicked on the Go button as a result, the parameters remained old instead of being replaced by new ones.
For several years, the program has worked for me this way, now I'm switching from version 78 to version 99 and ran into this problem.

Re: CefCreateUrl function is not working

Posted: Sun Mar 27, 2022 3:52 pm
by igor666
I found a solution, you need to reset the spec parameter, for example like this

Code: Select all

procedure TForm1.GoBtnClick(Sender: TObject);
var
  url: TUrlParts;
begin
  // This will load the URL in the edit box
  //Chromium1.LoadURL(AddressEdt.Text);
  CefParseUrl(AddressEdt.Text,url);
  url.spec := '';
  url.query := 'mode=asd&asd=hgf';
  AddressEdt.Text := CefCreateUrl(url);
end;
in that case it works as it should. I don't know if this is a bug or by design :)