chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.09k stars 450 forks source link

SendKeyEvent crashing on MacOS #3666

Open adriankalinowski95 opened 3 months ago

adriankalinowski95 commented 3 months ago

Describe the bug I have problem with sending keyboard event. Always when im doing that I have crash. Result something like that: [0312/110036.722903:FATAL:render_widget_host_view_mac.mm(460)] Check failed: in_keyboardevent.

I was trying many ways to send this event, but always same result.

Sending code:

CefKeyEvent* key_event = new CefKeyEvent();
key_event->windows_key_code = 65; 
key_event->native_key_code = 65;
key_event->is_system_key = false;
key_event->type =  KEYEVENT_RAWKEYDOWN;
browser->GetHost()->SendKeyEvent(*key_event);

This code is working on Windows.

Probably, the problem is because ClientApplication is not handling this event.

@implementation ClientApplication

- (BOOL)isHandlingSendEvent {
  return handlingSendEvent_;
}

- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
  handlingSendEvent_ = handlingSendEvent;
}

- (void)sendEvent:(NSEvent*)event {
  CefScopedSendingEvent sendingEventScoper;
  [super sendEvent:event];
    if (event.type == NSEventTypeKeyDown ){
        std::cout << "keyevent!" << std::endl;
       // Event from browser->GetHost()->SendKeyEvent(..) is not cached here.
    }
}

To Reproduce Send key event via browser->GetHost()->SendKeyEvent(...)

Expected behavior Not crashing

Versions

Additional context I was testing this on cefclient app in reload button: root_window_mac

- (IBAction)reload:(id)sender {
  CefRefPtr<CefBrowser> browser = root_window_->GetBrowser();
  if (browser.get()) {
      REQUIRE_MAIN_THREAD();
    browser->Reload();
      CefKeyEvent* key_event = new CefKeyEvent();
      key_event->windows_key_code = 65; // Kod klawisza, np., 'A' jako 65
      key_event->native_key_code = 65;
      key_event->is_system_key = false;
      key_event->type =  KEYEVENT_RAWKEYDOWN;

      browser->GetHost()->SendKeyEvent(*key_event);
  }
}

But its giving same result as in my app.

magreenblatt commented 3 months ago

Your usage of SendKeyEvent may be incorrect. I suggest that you test with cefclient --off-screen-rendering-enabled to see how the CEF sample app is populating the CefKeyEvent structure.

Note also that SendKeyEvent is currently only tested/supported with off-screen rendering.

adriankalinowski95 commented 3 months ago

Do you have/know any proof of concept of that for screen rendering?

Mellnik commented 2 months ago

I can confirm this bug on Mac and off-screen rendering. I had this bug a while ago and also tested a SendKeyEvent with manual correctly populated CefKeyEvent struct.