Page 1 of 1

Opening new tab

Posted: Wed Aug 05, 2020 4:29 pm
by andreykrasnodar
Is there a possibility to open links with target="_blank" in a new tab, not in a new window?

Re: Opening new tab

Posted: Wed Aug 05, 2020 7:01 pm
by andreykrasnodar
I tried to make 2 tabs with 2 ChromiumOSR browsers named Chromium1 and Chromium2 and type this

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
  showmessage('trying to open a new tab');
  Result:=True;
  Header := TCefStringMultimapOwn.Create;
  Request := TCefRequestRef.New;
  Header.Append('Referer', Frame.Url);
  Request.Assign(targetUrl, '', nil, Header);
  Chromium2.Browser.MainFrame.LoadRequest(Request);
  ShowMessage('has opened');
end;
but application hangs.

Re: Opening new tab

Posted: Wed Aug 05, 2020 8:46 pm
by salvadordf
Try cancelling the new popup window setting "result" to true, saving the targetUrl value and sending a windows message to the main form to use the targetUrl value as parameter in Chromium2.Load.

Remove the "showmessage" or any other function that creates, destroys or modifies VCL controls inside cef events because they are executed in a different thread and the VCL is not thread safe.

Please, consider using cef4delphi instead of dcef3. There're multiple demos and many bugs in chromium, cef and dcef3 were fixed.

Re: Opening new tab

Posted: Wed Aug 05, 2020 9:05 pm
by andreykrasnodar
Try cancelling the new popup window setting "result" to true
I have already done it (the code ^)
Remove the "showmessage" or any other function that creates, destroys or modifies VCL controls inside cef events because they are executed in a different thread and the VCL is not thread safe.
Thanks. It helps.
Please, consider using cef4delphi instead of dcef3. There're multiple demos and many bugs in chromium, cef and dcef3 were fixed.
My software is for windows xp. So I have to use old CEF

Re: Opening new tab

Posted: Sat Aug 08, 2020 10:03 am
by andreykrasnodar
I have found an answer!!!!!

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;
  Request := TCefRequestRef.New;
  Request.Url := targetUrl;
  Request.Method := 'POST';
  Header := TCefStringMultimapOwn.Create;
  Header.Append('Referer', Frame.Url);
  Request.SetHeaderMap(Header);
  Data := TCefPostDataRef.New;
  Request.PostData := Data;
  Chromium2.Browser.MainFrame.LoadRequest(Request);
  chromium1.Browser.Host.SendFocusEvent(false);
  chromium2.Browser.Host.SendFocusEvent(True);
end;
It works PERFECT!!!

Re: Opening new tab

Posted: Sun Aug 09, 2020 8:30 am
by andreykrasnodar
andreykrasnodar wrote: Sat Aug 08, 2020 10:03 am I have found an answer!!!!!

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;
  Request := TCefRequestRef.New;
  Request.Url := targetUrl;
  Request.Method := 'POST';
  Header := TCefStringMultimapOwn.Create;
  Header.Append('Referer', Frame.Url);
  Request.SetHeaderMap(Header);
  Data := TCefPostDataRef.New;
  Request.PostData := Data;
  Chromium2.Browser.MainFrame.LoadRequest(Request);
  chromium1.Browser.Host.SendFocusEvent(false);
  chromium2.Browser.Host.SendFocusEvent(True);
end;
It works PERFECT!!!
But sometimes it is a problem named APPCRASH in module libcef.dll 3.2454.1344.0 at 00186429. External exception 80000003.