window.focus() does not bring popup window to front

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

window.focus() does not bring popup window to front

Postby mschertler2 » Tue Apr 04, 2017 12:25 pm

I'm using CEF in a WinForms application using the CefSharp wrapper. In their forum I was told to ask my question here, because it seems to be a general CEF question. My application hosts a browser in its main window. Additionaly the user is able to detach certain contents (i.e. chat conversations) that are then opened in a popup window. Opening the popup is done using JavaScript and works fine.

var popup = window.open(...);

When the user clicks the same item again in the main window, the corresponding popup should receive focus and come to front.

if (popup && !popup.closed) popup.focus();

This works fine in standard browsers including chromium. But when I try the same with my embedded CEF control, the popup window doesn't receive focus and stays in the background. Any ideas what I do wrong?
mschertler2
Newbie
 
Posts: 2
Joined: Tue Apr 04, 2017 11:55 am

Re: window.focus() does not bring popup window to front

Postby magreenblatt » Tue Apr 04, 2017 12:40 pm

Your client can implement CefFocusHandler::OnGotFocus and use OS functions to bring the window to the front.
magreenblatt
Site Admin
 
Posts: 12968
Joined: Fri May 29, 2009 6:57 pm

Re: window.focus() does not bring popup window to front

Postby mschertler2 » Wed Apr 05, 2017 1:46 pm

Thanks for your quick reply.

I tried it, but it seems CefFocusHandler::OnGotFocus is just called in my main window. In the popup windows I don't get the callback when it got focus.
mschertler2
Newbie
 
Posts: 2
Joined: Tue Apr 04, 2017 11:55 am

Re: window.focus() does not bring popup window to front

Postby dbuechel » Wed Oct 16, 2024 8:43 am

We're having the exact same issue (also with CefSharp and a .NET application) and I can confirm as well that the FocusHandler is not called for the window.focus() JavaScript method.
dbuechel
Techie
 
Posts: 14
Joined: Wed Mar 03, 2021 3:55 pm

Re: window.focus() does not bring popup window to front

Postby magreenblatt » Wed Oct 16, 2024 11:05 am

Have you filed a bug with CefSharp?
magreenblatt
Site Admin
 
Posts: 12968
Joined: Fri May 29, 2009 6:57 pm

Re: window.focus() does not bring popup window to front

Postby dbuechel » Mon Oct 21, 2024 11:09 am

There already exist various related issues and discussions of which the following one is actually a post of the OP, which the maintainer of CefSharp declared to be an upstream issue in CEF: https://github.com/cefsharp/CefSharp/issues/1845. Any help or guidance would be highly appreciated, as this is quite an important issue to us.

I have tried to implement the focus handler API (see https://cefsharp.github.io/api/118.6.x/html/T_CefSharp_IFocusHandler.htm), but it appears that it does not exactly serve the use case we're trying to cover here. I have also stumbled upon a pull request for CEF which claims to solve the issue but has been stale for almost 4 years now: https://github.com/chromiumembedded/cef/issues/2931.
dbuechel
Techie
 
Posts: 14
Joined: Wed Mar 03, 2021 3:55 pm

Re: window.focus() does not bring popup window to front

Postby magreenblatt » Mon Oct 21, 2024 1:10 pm

The PR that you reference had unresolved issues, and the source repository now appears to be gone. The related CEF issue, https://github.com/chromiumembedded/cef/issues/2931, will need a new champion.
magreenblatt
Site Admin
 
Posts: 12968
Joined: Fri May 29, 2009 6:57 pm

Re: window.focus() does not bring popup window to front

Postby dbuechel » Tue Oct 22, 2024 5:30 am

Thanks a lot for your help, it is highly appreciated. I was not aware of that fact and I'm unfortunately not equipped resp. lack the knowledge to be able to contribute, but if there were a new pull request resolving the issue, that certainly would be great.

Or would it be a possibility (which I could imagine to furthermore be less effort) to create a new CEF API which would let the embedding host know and handle a popup requesting focus? As previously stated, I have implemented the focus handler you've mentioned above as a possible solution, but unfortunately (or at least in CefSharp), it does not appear to be usable to handle JavaScript calls to the .focus() method.
dbuechel
Techie
 
Posts: 14
Joined: Wed Mar 03, 2021 3:55 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 56 guests