Page 1 of 1

How to open _blank link in the same window?

Posted: Sat Jun 15, 2024 5:56 am
by nimq
Hello!

I need links that usually open in a new tab to always open in the same window

In older versions, I used the following code at Chromium_OnBeforePopup

Code: Select all

    case targetDisposition of
      CEF_WOD_CURRENT_TAB,
      CEF_WOD_SINGLETON_TAB,
      CEF_WOD_NEW_FOREGROUND_TAB,
      CEF_WOD_NEW_BACKGROUND_TAB,
      CEF_WOD_NEW_WINDOW,
      CEF_WOD_NEW_POPUP:
        begin
          ChromiumWindow1.ChromiumBrowser.StopLoad;
          req := TCefRequestRef.New;
          req.Url := targetUrl;
          req.Method := 'GET';
          req.Flags := UR_FLAG_ALLOW_STORED_CREDENTIALS;
          req.SetReferrer(frame.Url, REFERRER_POLICY_NEVER_CLEAR_REFERRER);
          ChromiumWindow1.ChromiumBrowser.LoadRequest(req);
          Result := true;
        end;
    else
      Result := False;
    end;
but it doesn't work now :(

How to achive what i need?

Thanks!

Re: How to open _blank link in the same window?

Posted: Sat Jun 15, 2024 8:19 pm
by salvadordf
Hi,

Try calling ChromiumWindow1.LoadURL(targetUrl) instead of using LoadRequest because that function may fail with bad IPC message reason INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the request origin using some other mechanism (LoadURL, link click, etc).

Re: How to open _blank link in the same window?

Posted: Mon Jun 17, 2024 10:00 am
by nimq
Hello!

if we use the LoadURL method everything works as expected, but the header is different - the referer is not being passed.

Is it possible to add a referer field when loading through LoadURL?

Re: How to open _blank link in the same window?

Posted: Mon Jun 17, 2024 2:58 pm
by salvadordf
Here's an example to add or replace an HTTP header :
https://github.com/salvadordf/CEF4Delphi/blob/16f76f39aa2cb898a587b15bb39367e077bd9e6d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1229

Consider using a TPageControl like the TabbedBrowser2 demo. You can hide the tabs and select the new browser tab automatically.