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.

Change the url in the event onBeforeResourceLoad

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

Change the url in the event onBeforeResourceLoad

Post by igor666 »

How to change the link in the onbeforeresourceload event? If changing so

procedure TfmMain.mainChromiumBeforeResourceLoad(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const callback: ICefRequestCallback;
out Result: TCefReturnValue);
begin
if LowerCase(request.Method) = 'get' then
begin
request.Url := request.Url + '?paramname=paramvalue';
end;
end;


then the request goes into a loop (cycle), substitutes the parameters several times and as a result does not load anything. Using OLDCEF4Delphi.

Sorry for my english :)
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Change the url in the event onBeforeResourceLoad

Post by salvadordf »

Hi,

The CEF3 code comments for that event say this :

Code: Select all

  ///
  // Called on the IO thread before a resource request is loaded. The |request|
  // object may be modified. Return RV_CONTINUE to continue the request
  // immediately. Return RV_CONTINUE_ASYNC and call cef_request_tCallback::
  // cont() at a later time to continue or cancel the request asynchronously.
  // Return RV_CANCEL to cancel the request immediately.
  //
  ///
According to the comments you can modify the "request" parameter in that event and set "Result" to RV_CONTINUE to continue immediately.

Your code seems fine but it looks like CEF is triggering the event again for the modified URL generating an infinite loop.

If that's the case, you need to check that the request doesn't have '?paramname=paramvalue' before modifying it.
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Re: Change the url in the event onBeforeResourceLoad

Post by igor666 »

Thanks for the answer
Post Reply