Page 1 of 1

Unable to implement JS dialogs

PostPosted: Tue Jul 07, 2015 7:29 am
by jkman
I am wanting to disable alert,confirm and promp basically. Have implemented the abstract class CefJSDialogHandler like this:
Code: Select all
    public class CustomJSDialogs: CefJSDialogHandler
    {
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, string acceptLang, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
        {
            suppress_message = true;
            callback.Continue(true, "");
            return true;
        }
        protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
        {
            callback.Continue(true, "");
            return true;
        }

        protected override void OnResetDialogState(CefBrowser browser)
        {
            return;
        }

        protected override void OnDialogClosed(CefBrowser browser)
        {
            return;
        }
    }


And returned them in CefClient like this:
Code: Select all
protected virtual CefJSDialogHandler GetJSDialogHandler()
        {
            return new CustomJSDialogs();
        }


Yet alerts are still showing. What am I doing wrong please?

Re: Unable to implement JS dialogs

PostPosted: Wed Jul 08, 2015 6:02 am
by jkman
The same applies in disabling context menu!

I have created custom handler like this:
Code: Select all
public class ContextMenuHH: CefContextMenuHandler
    {
        protected void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            model.Dispose();
            model = null;
        }

        protected bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags)
        {
            return false;
        }

        protected void OnContextMenuDismissed(CefBrowser browser, CefFrame frame)
        {
        }
       
    }


And have put it into CefWebClient inplementation like this:
Code: Select all
protected virtual CefContextMenuHandler GetContextMenuHandler()
        {
            return _contextMenuHandler;
        }


where
Code: Select all
_contextMenuHandler = new ContextMenuHH();


yet it does nothing. Need context menus disabled. Is that possible?

Re: Unable to implement JS dialogs

PostPosted: Thu Jul 09, 2015 5:13 am
by jkman
Also application crashes from time to time. Could you have a look please at my cefglue.log if it says something?

Here is cefglue.log:
http://pastebin.com/8CfjXXHy

Thank you very much!

PS: It probably says also something about the js alerts - this line seems interesting to me:
Code: Select all
[0709/103348:FATAL:javascript_dialog_manager.cc(103)] Check failed: !*did_suppress_message.

Re: Unable to implement JS dialogs

PostPosted: Thu Jul 09, 2015 12:06 pm
by jkman
After removing my JS implementation the error removed. But I still need to disable JS alerts. Any thoughts?

Re: Unable to implement JS dialogs

PostPosted: Thu Jul 09, 2015 2:23 pm
by magreenblatt
In C++ you would implement CefJSDialogHandler to override the default JS dialog implementation.

Re: Unable to implement JS dialogs

PostPosted: Thu Apr 22, 2021 7:01 am
by rkcef
magreenblatt wrote:In C++ you would implement CefJSDialogHandler to override the default JS dialog implementation.


I know this is a really old thread but I'm unable to find anything newer that has more detailed information about implementing CefJSDialogHandler in the CefClient Example (it seems like jkman was using it).

Maybe you could elaborate a bit on this topic. I've also created a new thread asking for some help on how to correctly implement CefJSDialogHandler in the cefclient example project -> https://magpcss.org/ceforum/viewtopic.php?f=6&t=18356&p=48783#p48783

Thank you very much :)