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.
I am making my own project with TChromium (VCL component) and have an error.
When user taps a link which should open a website in a new window, the website opens in the same window.
I used simple code
The new popup window needs to be created following the instructions in the CEF code comments in order to keep the "referrer" (and also the POST information among other things)
procedure TForm1.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
var
Header: ICefStringMultimap;
Request: ICefRequest;
Data: ICefPostData;
begin
Result:=True;
Header := TCefStringMultimapOwn.Create;
Header.Append('Referer', Chromium1.Browser.MainFrame.Url);
Request := TCefRequestRef.New;
Request.Assign(targetUrl, 'GET', Data, Header);
Chromium1.Browser.MainFrame.LoadRequest(Request);
end;
This code works great, but sometimes application crashes with message
APPCRASH
5efcf65f
libcef.dll
3.2454.1344.0
562d8f27
80000003
00186429
6.3.9600.2.0.0.256.48
1049
1: 5861
2: 5861822e1919d7c014bbb064c64908b2
3: d1d9
4: d1d94a13d3609d6b740644c12508f581
This example will work only in simple cases when the link from site A leads directly to site B. And, for example, this will not work with the yandex search engine, since in Chromium1.Browser.MainFrame.Url there will be an httpS search link, and in targetUrl there will be a direct link to the site from the search result. As a result, we get an empty referrer at the transition.
I am currently watching an example of PopupBrowser2, but I just can’t figure out how to redirect the transition to the current window without opening a new one. Help please, can this be done?
This can be done, but this is not a faithful referrer. If in Chrome to remove target = _blank for the link and load it, it will be seen that the referrer is simply https://yandex.ru there. I would like some kind of method that would leave all the settings and requests as is, when redirecting the download. I don’t want to parse downloaded pages and delete target = _blank on all links.
igor666 wrote: Tue Jul 07, 2020 11:13 am
This can be done, but this is not a faithful referrer. If in Chrome to remove target = _blank for the link and load it, it will be seen that the referrer is simply https://yandex.ru there. I would like some kind of method that would leave all the settings and requests as is, when redirecting the download. I don’t want to parse downloaded pages and delete target = _blank on all links.
I gave Yandex as an example, but the options may be different. Thus, we decided a specific example, and not the situation as a whole. Indeed, in one case, the referrer transfer can be with the flag REFERRER_POLICY_ORIGIN, in another REFERRER_POLICY_NEVER_CLEAR_REFERRER, etc. And there is no request in the onBeforePopup event to check which flag should be for the current request.