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.

how to access new window

coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

how to access new window

Post by coater »

some websites need to create new tab or window when popping up. Such as <www.cnki.net>.
When click search results, it will create a new window.
It cannot be opened rightly using url in Chromium1BeforePopup.
My question is how to acquire the browser title in new window.
keen for your help, thank you very much!
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to access new window

Post by salvadordf »

Hi,

There are two ways to handle popup windows in CEF3 :
  • Let CEF3 create the popup window.
  • Use a custom Delphi form.
The MiniBrowser demo lets CEF3 create popup windows. In this case you can get the title by using the GetWindowText Windows API function. Here you have an example :
https://stackoverflow.com/questions/143 ... eving-text

If you use a custom window made with Delphi then you can read the TForm.Caption property. The PopupBrowser2 demo shows you how to use custom Delphi forms for the popup windows.
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: how to access new window

Post by coater »

Thank you very much!
I was confused. Sorry for bothering you again.

1. GetWindowText only get windows text. May I get browser title or visit browser dom.


2. PopupBrowser2 demo can not operate pop up window rightly.

Is it possible to add one demo to illustrate pop up window. Thank you!
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to access new window

Post by salvadordf »

coater wrote: Sat Sep 29, 2018 11:51 pm 1. GetWindowText only get windows text. May I get browser title or visit browser dom.
Copy the code in the DOMVisitor demo and remove the TChromium.OnBeforePopup event.

Then replace this code in the TDOMVisitorFrm.Chromium1ContextMenuCommand procedure :

Code: Select all

    MINIBROWSER_CONTEXTMENU_VISITDOM_FULL :
      PostMessage(Handle, MINIBROWSER_VISITDOM_FULL, 0, 0);
...with this ...

Code: Select all

    MINIBROWSER_CONTEXTMENU_VISITDOM_FULL :
      begin
          TempMsg := TCefProcessMessageRef.New(RETRIEVEDOM_MSGNAME_FULL); // Same name than TCefCustomRenderProcessHandler.MessageName
          browser.SendProcessMessage(PID_RENDERER, TempMsg);
      end;
and add this variable to that procedure :

Code: Select all

var
  TempMsg : ICefProcessMessage;
You will have to add the "if Chromium1.IsSameBrowser(browser) then" checks to many of the DOMVisitor events. These checks are used in the MiniBrowser demo to execute the events only for the main window and not for the popups.
coater wrote: Sat Sep 29, 2018 11:51 pm 2. PopupBrowser2 demo can not operate pop up window rightly.
Is it possible to add one demo to illustrate pop up window. Thank you!
Please, provide all the details you can if you find any issues in that demo.
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: how to access new window

Post by coater »

Thank you very much!

1. Are their someways to distinguish Main browsers and Popup browser when we decide which browser could be used to process message?

2.Using Popupbrowser demo cannot open new form after click.
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to access new window

Post by salvadordf »

coater wrote: Sun Sep 30, 2018 10:10 am Thank you very much!
1. Are their someways to distinguish Main browsers and Popup browser when we decide which browser could be used to process message?
If you have a ICefBrowser parameter you can check ICefBrowser.Identifier. That identifier is the same as the TChromium.BrowserID property and each browser has a unique identifier.
coater wrote: Sun Sep 30, 2018 10:10 am 2.Using Popupbrowser demo cannot open new form after click.
Can you reproduce that issue with another website?
www.cnki.net is incredibly slow or impossible to open from my country.

Thanks!
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: how to access new window

Post by coater »

Thank you very much!
Sorry to bother you again and again.
I was still confused.

1.If there are many pop up browsers, how to search them and find one to process message?
1.1 If there are some functions such as browser.count or getbrowser((browser.Identifier)), and so on.
1.2 Now the only way I found is to get browser in the Chromium1LoadEnd event . are there other ways?
----
Chromium1LoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer);
TempMsg := TCefProcessMessageRef.New(BrowserToSender); // Same name than TCefCustomRenderProcessHandler.MessageName
browser.SendProcessMessage(PID_RENDERER, TempMsg) ;
--------
2.Sorry, I cannot find another one. Is it possible to use proxy to visit the website.
proxies:
http://ip.zdaye.com/FreeIPlist.html

If I can find one, I will post here.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to access new window

Post by salvadordf »

coater wrote: Sun Sep 30, 2018 10:58 am Thank you very much!
Sorry to bother you again and again.
I was still confused.

1.If there are many pop up browsers, how to search them and find one to process message?
1.1 If there are some functions such as browser.count or getbrowser((browser.Identifier)), and so on.
1.2 Now the only way I found is to get browser in the Chromium1LoadEnd event . are there other ways?
----
Chromium1LoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer);
TempMsg := TCefProcessMessageRef.New(BrowserToSender); // Same name than TCefCustomRenderProcessHandler.MessageName
browser.SendProcessMessage(PID_RENDERER, TempMsg) ;
--------
Create a list or dynamic array of ICefBrowser interfaces and add the "browser" instances in the TChromium.OnAfterCreated event.
Use the TChromium.OnBeforeClose or the TChromium.OnClose to remove them from your list or array.

Edit : By "removing" I mean setting them to NIL to decrease the reference count.
coater wrote: Sun Sep 30, 2018 10:58 am 2.Sorry, I cannot find another one. Is it possible to use proxy to visit the website.
proxies:
http://ip.zdaye.com/FreeIPlist.html
If I can find one, I will post here.
I finally could open that "pyrolysis" link using a proxy.

CEF3 triggers the TChromium.OnBeforePopup in that link and the value for the targetDisposition parameter is WOD_NEW_FOREGROUND_TAB.

The PopupBrowser2 demo only shows new popup windows when targetDisposition is WOD_NEW_POPUP but you can ignore that and open as popup anything that has these targetDisposition values : WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_WINDOW or WOD_NEW_POPUP.
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: how to access new window

Post by coater »

I got it.
Thank you very much!!!
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: how to access new window

Post by coater »

Is it a bug?

------------
var
BrowserList: TList<ICefBrowser>;

---------
BrowserList:=Tlist<ICefBrowser>.Create; //uses Generics.Collections ,formshow procedure.
---------
-----------//add ICefBrowser to list
procedure TIinformSearchFrm.Chromium1AfterCreated(Sender: TObject;
const browser: ICefBrowser);
begin
memo1.Lines.Add(inttostr(browser.Identifier));//new browser has been created.
BrowserList.Add(browser);
end;
-------

I opened a new window,
the code below works.
--------
TempBrowser:=(BrowserList.Items[1)]) ; // item1 browser
TempMsg := TCefProcessMessageRef.New(BrowserToSender);
if TempBrowser<>nil then TempBrowser.SendProcessMessage(PID_RENDERER, TempMsg);
-------

If I opened another new window, The count of BrowserList is 3.
But the code below not work. Is this a bug?
--------
TempBrowser:=(BrowserList.Items[2)]) ;
TempMsg := TCefProcessMessageRef.New(BrowserToSender);
if TempBrowser<>nil then TempBrowser.SendProcessMessage(PID_RENDERER, TempMsg);
--------


////////////////////////////
This also happened if I got browser in Chromium1LoadEnd.
----------------------------
procedure TIinformSearchFrm.Chromium1LoadEnd(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer);
var TempMsg : ICefProcessMessage;
const BrowserToSender='string';
begin
Popupbrowser:=browser; // Popupbrowser.SendProcessMessage only work when browser.identifier=2;
end;
---------------------
///////////////////////


keen for your help, thank you very much!
Post Reply