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.

Replacing redirect URL

Post Reply
Vaytl
Posts: 28
Joined: Tue Jan 04, 2022 12:52 pm

Replacing redirect URL

Post by Vaytl »

I'm trying to change the redirect. But it doesn't work.

Code: Select all

procedure TMiniBrowserFrm.Chromium1ResourceRedirect(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame;
  const request: ICefRequest; const response: ICefResponse;
  var newUrl: ustring);
begin
  if newUrl = 'https://old-url.com/redirect' then
    newUrl := 'https://new-url.com';
end;
User avatar
salvadordf
Posts: 4156
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Replacing redirect URL

Post by salvadordf »

Hi,

Try using TChromium.OnBeforeResourceLoad to redirect a request.

Code: Select all

      /// Called on the IO thread before a resource request is loaded. The |browser|
      /// and |frame| values represent the source of the request, and may be NULL
      /// for requests originating from service workers or ICefUrlRequest. To
      /// redirect or change the resource load optionally modify |request|.
      /// Modification of the request URL will be treated as a redirect. Return
      /// RV_CONTINUE to continue the request immediately. Return RV_CONTINUE_ASYNC
      /// and call ICefCallback functions at a later time to continue or cancel
      /// the request asynchronously. Return RV_CANCEL to cancel the request
      /// immediately.
Vaytl
Posts: 28
Joined: Tue Jan 04, 2022 12:52 pm

Re: Replacing redirect URL

Post by Vaytl »

Excellent, thank you!
Vaytl
Posts: 28
Joined: Tue Jan 04, 2022 12:52 pm

Re: Replacing redirect URL

Post by Vaytl »

Please tell me why the redirect is not displayed in Chromium1ResourceRedirect, for example, "https://google.com/" redirect to "https://www.google.com/"?
Also in Chromium1GetResourceResponseFilter there is no 'Location' in response header?
User avatar
salvadordf
Posts: 4156
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Replacing redirect URL

Post by salvadordf »

Please, understand that CEF4Delphi is only a CEF wrapper and it can only give you access to all the information, methods, events, etc. allowed by CEF and Chromium.

In this case, the available headers on some events are decided by Chromium. I'm not sure if the redirect information is provided by CEF or Chromium.
Vaytl
Posts: 28
Joined: Tue Jan 04, 2022 12:52 pm

Re: Replacing redirect URL

Post by Vaytl »

Thank you for your assistance, Salvador.
Post Reply