I'm fairly new to CEF in general. I'm using the C++ example project "cefclient" to build my own desktop application for Windows 10. So far it seems to work fine. I'm using the CEF version "90.5.4+gc6a4331+chromium-90.0.4430.72".
Right now I'm trying to override (of if possible to hide altogether) the default Javascript prompt for the event "onbeforeunload" when the application window gets closed (for example by clicking on the top right "X" button).
I'm trying to extend the class "ClientHandler" (cefclient\browser\client_handler.h) with the class "CefJSDialogHandler" (cef\include\cef_jsdialog_handler.h) to implement the two methods "OnJSDialog" and "OnBeforeUnloadDialog".
This seems to be the right place because there's already a method called "GetJSDialogHandler()" that returns "CefRefPtr<CefJSDialogHandler>" (for linux, but still).
The issue I'm facing is, when I extend "ClientHandler" with "CefJSDialogHandler" and recompile everything, the application crashes immediately after I double click the EXE file. When I call the EXE file from the Terminal, it still crashes but I get the message "Segmentation fault".
- Code: Select all
class ClientHandler : public CefClient,
...,
public CefJSDialogHandler // <-- I've added it at the end of the list
{
...
bool OnJSDialog(CefRefPtr<CefBrowser> browser,
const CefString& origin_url,
JSDialogType dialog_type,
const CefString& message_text,
const CefString& default_prompt_text,
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message) OVERRIDE;
bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) OVERRIDE;
}
I've tried to search the forum but couldn't find anything that would help me.
I also tried to create a custom Class that extends "CefJSDialogHandler" like described in this thread: https://magpcss.org/ceforum/viewtopic.php?f=14&t=13169&p=26551
but unfortunately I wasn't successful.
To clearify what I'm trying to do: I would like to suppress the default javascript prompt (and automatically return the same signal as if the user had clicked on "cancel" in the prompt) and instead show a custom notification inside the web application. Right now, when I try to close the window, I get the default prompt with the message "Is it OK to leave/reload this page?". If I click on "OK" the window will be closed right away, but if I on "Cancel" only the prompt closes and my custom notification will be shown instead. That is what I want but of course without the default prompt ever be shown.
What is the right way to implement "CefJSDialogHandler"?
Hopefully someone can point me in the right direction.
Thanks very much.