Page 1 of 1

Change the url in the event onBeforeResourceLoad

Posted: Fri Feb 08, 2019 1:39 pm
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 :)

Re: Change the url in the event onBeforeResourceLoad

Posted: Fri Feb 08, 2019 2:28 pm
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.

Re: Change the url in the event onBeforeResourceLoad

Posted: Fri Feb 08, 2019 2:35 pm
by igor666
Thanks for the answer