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.

No refferer when open link in popup window

andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

No refferer when open link in popup window

Post by andreykrasnodar »

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

Code: Select all

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);
begin
  Result := True;
  Chromium1.Browser.MainFrame.LoadUrl(targetUrl);
end;
but now there is no referrer:

Code: Select all

document.write(this.document.referrer);
displays nothing. What should I do?
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: No refferer when open link in popup window

Post by andreykrasnodar »

Is that code correct:

Code: Select all

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;
?

P.S. Here I am trying to send request to my site sending request with appended string "Referrer". What should I append more?
User avatar
salvadordf
Posts: 4040
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: No refferer when open link in popup window

Post by salvadordf »

Hi,

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)

I just wrote this in another thread about popup widows :
viewtopic.php?f=10&p=5682#p5682

Try using the PopupBrowser2 demo code as a template for your application and you should see the right "document.referrer" value.
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: No refferer when open link in popup window

Post by andreykrasnodar »

andreykrasnodar wrote: Wed Jul 01, 2020 11:45 am

Code: Select all

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
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: No refferer when open link in popup window

Post by andreykrasnodar »

Due to errors I wrote a simple javascript code which changes _blank to _self. No errors more.
igor666
Posts: 64
Joined: Fri Feb 08, 2019 1:25 pm

Re: No refferer when open link in popup window

Post by igor666 »

andreykrasnodar wrote: Wed Jul 01, 2020 8:54 pm
andreykrasnodar wrote: Wed Jul 01, 2020 11:45 am

Code: Select all

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?
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: No refferer when open link in popup window

Post by dilfich »

console.log("RF: " + document.referrer);
Maybe something like this. there is a referrer, JS: RF: https://yandex.ru/search/?text=fgfg&lr=37143

Code: Select all

  Header := TCefStringMultimapOwn.Create;
  Request := TCefRequestRef.New;
  Request.Assign(targetUrl, '', nil, Header);
  Request.SetReferrer(Browser.MainFrame.Url, REFERRER_POLICY_NEVER_CLEAR_REFERRER);
  Chromium1.Browser.MainFrame.LoadRequest(Request);
igor666
Posts: 64
Joined: Fri Feb 08, 2019 1:25 pm

Re: No refferer when open link in popup window

Post by igor666 »

dilfich wrote: Sat Jul 04, 2020 11:19 am console.log("RF: " + document.referrer);
Maybe something like this. there is a referrer, JS: RF: https://yandex.ru/search/?text=fgfg&lr=37143

Code: Select all

  Header := TCefStringMultimapOwn.Create;
  Request := TCefRequestRef.New;
  Request.Assign(targetUrl, '', nil, Header);
  Request.SetReferrer(Browser.MainFrame.Url, REFERRER_POLICY_NEVER_CLEAR_REFERRER);
  Chromium1.Browser.MainFrame.LoadRequest(Request);
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.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: No refferer when open link in popup window

Post by dilfich »

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.
Play with the settings
Request.SetReferrer(Browser.MainFrame.Url, REFERRER_POLICY_NEVER_CLEAR_REFERRER);
RF: https://yandex.ru/search/?text=fgfg&lr=37143
Request.SetReferrer(Browser.MainFrame.Url, REFERRER_POLICY_ORIGIN);
RF: https://yandex.ru/
igor666
Posts: 64
Joined: Fri Feb 08, 2019 1:25 pm

Re: No refferer when open link in popup window

Post by igor666 »

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.
Post Reply