Here is some additional finding on that issue. I could'nt believe it was THAT stupid by me....
Just writing
Code: Select all
ActiveControl := CEFWindowParent1;
Chromium1.ExecuteJavaScript('document.getElementById("auxEdt").focus();', 'about:blank', 0);
works with Result := False in the TMainForm.Chromium1SetFocus() handler. But what in fact I'm doing is a little more complex. Instead of just "firing&forget" the Chromium1.ExecuteJavaScript() call, I embed each function I wish to execute (focus() here) into something like this:
Code: Select all
try {
var El = document.getElementById("<some id here>");
var Res = (El!=null);
if (Res) { El.focus(); }
myextension.ReturnToDelphi(6, Res);
} catch(err) {
myextension.ReturnToDelphi(6, false, "RMSG", err.message);
}
with a registered "ReturnToDelphi" extension and waiting for the response via OnBrowserMessage(). The waiting is a timed WaitLock in a separate thread on an event that gets set when the OnBrowserMessage() arrives. So I'm not blocking the main thread or any other threads at all.
Now, with having Result := False in the TMainForm.Chromium1SetFocus() handler, the problem is that the response through OnBrowserMessage() times out!! When I first was at that point some days ago, I found by try&error that having Result := True in the TMainForm.Chromium1SetFocus() circumvents this issue, i.e. the awaited OnBrowserMessage() came in. Therefore I had that True there...
Now, with False back again in TMainForm.Chromium1SetFocus() that timeout issue is back. The solution to this seems to be doing some Application.ProcessMessages; Sleep(1); loops between ActiveControl := CEFWindowParent1 and executing the JS code for some milliseconds.
It seems to me there is some deadlock when having False in TMainForm.Chromium1SetFocus() and not doing some main thread Application.ProcessMessages after an ActiveControl := CEFWindowParent1.
I am fine with that Application.ProcessMessages solution, but you might be interested in searching a little deeper to see whats causing the deadlock there. Just for curiousity...
Regards, Lu