Page 1 of 1

cef crashing when registering extension for calling dot net

PostPosted: Fri Feb 23, 2018 7:37 am
by pkearan
We have been using cefglue version 2623 and using the below extension to pass data from javascript to dot net. Now we are upgrading cefglue to version 3202 but the extension below results in error during initialization of browser. If I comment the RegisterExtension line then there is no crash.

[0223/161321.161:FATAL:V8Initializer.cpp(80)]
Is something changed between these versions which I am missing?

Code below
Code: Select all
internal sealed class RenderProcessHandler : CefRenderProcessHandler
    {
        MyCustomCefV8Handler myCefV8Handler = new MyCustomCefV8Handler();
        protected override void OnWebKitInitialized()
        {
            var nativeFunction = @"gmApi = function(jsonArg) {

            native function MyNativeFunction(jsonArg);
            return MyNativeFunction(jsonArg);
        };
        ";
            CefRuntime.RegisterExtension("MessageEvent", nativeFunction, myCefV8Handler);
            base.OnWebKitInitialized();
        }
    }
    internal class MyCustomCefV8Handler : CefV8Handler
    {
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            returnValue = CefV8Value.CreateString("");
            ReceiveJsFunctionCall(arguments, ref returnValue);
            exception = null;
            return true;
        }
    }

Re: cef crashing when registering extension for calling dot

PostPosted: Sun Feb 25, 2018 11:55 am
by fddima
From API perspective everything should be fine, but chromium internals... who knows.

Try move extension registration to OnBrowserCreated method (looks like cef tests uses this point). There is also have sense to pick CEF debug build and catch real stacktrace which probably can be useful.

PS: If nothing helps, almost same functionality can be done with CefV8Context::Eval in OnContextCreated. I'm use last way for years, because extensions was tricky from start (poor error reporting in case of syntax errors).

Re: cef crashing when registering extension for calling dot

PostPosted: Mon Feb 26, 2018 4:36 am
by amaitland
Try window.gmApi =

Re: cef crashing when registering extension for calling dot

PostPosted: Tue Feb 27, 2018 5:15 am
by pkearan
"var gmApi" solved the issue. I think the validations are more strict now.

Re: cef crashing when registering extension for calling dot

PostPosted: Wed Feb 28, 2018 12:02 pm
by ndesktop
Check the CEF issue 1944.
The same missing var was at fault.