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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

CefCreateUrl function is not working

Post Reply
igor666
Posts: 71
Joined: Fri Feb 08, 2019 1:25 pm

CefCreateUrl function is not working

Post 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.
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CefCreateUrl function is not working

Post 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.
igor666
Posts: 71
Joined: Fri Feb 08, 2019 1:25 pm

Re: CefCreateUrl function is not working

Post 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.
You do not have the required permissions to view the files attached to this post.
igor666
Posts: 71
Joined: Fri Feb 08, 2019 1:25 pm

Re: CefCreateUrl function is not working

Post 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 :)
Post Reply