on and I open a file picker using that input, the main app (Wi" /> on and I open a file picker using that input, the main app (Wi" /> on and I open a file picker using that input, the main app (Wi"/>

CefSharp ChromiumBrowser looses focus when opening file picker via <input type="file">

78 Views Asked by At

As said in the title, given I am visiting a page, that has a simple <input type="file"> on and I open a file picker using that input, the main app (WinForms) looses focus (which is to be expected), however when I pick a file or cancel the file picker dialog, the main window regains a focus (noticable as a status bar color change) however the chromium component does not regain it. I have a JavaScript listener for keyboard input (keyboard shortcuts) on that page and they no longer work until I click on some random position inside chromium component.

I added a simple 'Activated' event listener to the form hosting the ChromiumBrowser component and inside it I am checking if ChromiumBrowser has a focus and in that particual scenario it is false.

mainForm.Activated += (s, a) => 
{
    if (mainForm.ChromeBrowser.IsBrowserInitialized)
    {
        var hasFocus = mainForm.ChromeBrowser.ContainsFocus; // hasFocus is false after file picker dialog is closed.

        var focus = mainForm.ChromeBrowser.Focus(); // returns false
    }
};

If I try to manually set the focus to the ChromiumBrowser component, it returns false (don't know why and have no idea how to figure that out).

The focus was normally regained after closing the file picker in the version 79.1.360 - we recently upgraded to 120.1.110 and noticed that issue.

Is there anything else I can try to regain focus on the proper component? I even tried simulating a mouse click but it does not help.

EDIT: at some other part of the application we already use the ChromeBrowser.Focus() method and there it returns 'true' however focus is still not on the component itself.

0

There are 0 best solutions below