Search code examples
javascriptc++google-chromedebuggingawesomium

Console.log() does not output to remote debugger for Awesomium in C++


I am using Awesomium library for UI of my C++ application ("plain" C++, no .NET, precompiled headers etc.).

Everything works fine, I am able to send events from C++ application to JavaScript in Awesomium and vice versa. UI responds to clicks etc. thanks to webCore->Update().

The problem is, sometimes errors in JavaScript occurs. And I would like to see them like in e.g. Edge/Chrome/Firefox (where you can press F12 to see console, debugger etc.).

I know that it's possible to use remote debugger for Awesomium with appropriate WebConfig so I've tried:

Awesomium::WebConfig webConfig;
webConfig.remote_debugging_host = Awesomium::WSLit("127.0.0.1");
webConfig.remote_debugging_port = 9222;
//create the WebCore singleton with configuration
webCore = Awesomium::WebCore::Initialize(webConfig);

//create a new WebView instance with a certain width and height
view = webCore->CreateWebView(width, height, 0, Awesomium::kWebViewType_Window);
view->set_parent_window(*windowHandle->getHWND());

view->set_view_listener(this);

//create a global js object named 'app'
Awesomium::JSValue result = view->CreateGlobalJavascriptObject(Awesomium::WSLit("app"));

//bind our method dispatcher to the WebView
view->set_js_method_handler(this);

if (result.IsObject()) {
    //bind our custom method to it
    Awesomium::JSObject& appObject = result.ToObject();
    appObject.SetCustomMethod(Awesomium::WSLit("sendEvent"), false);
}

Now in Chrome at http://localhost:9222/# I see my session: enter image description here

I am able to e.g. select UI elements inside my C++ application with debugger. But I cannot see anything in my debugger's console tab in Chrome (I do use console.log("Hello!") inside website that is loaded into Awesomium): enter image description here

p.s. The debugger window is not 100% height (as you see on screen). Can I fix it somehow?

p.s.2. Google Chrome is not my browser of choice. Can I use another one for debugging Awesomium UI?


Solution

  • JavaScript error/debug messages are not visible in the remote debugger of Awesomium (v1.7.5.1). The only way I found was by listening to the OnAddConsoleMessage() method in the WebViewListener::Load class. You have to make your own subclass and register it to your webview.

        #include <Awesomium/WebViewListener.h>
        class MyViewListender : public WebViewListener::View {
    
                // ... All the overridden WebViewListener::View methods go here
    
                void OnAddConsoleMessage(Awesomium::WebView* caller,
                                         const Awesomium::WebString& message,
                                         int line_number,
                                         const Awesomium::WebString& source) 
                {
                        cout << "Console: " << message << endl;
                }
        };
    

    Register it:

        MyViewListender* my_view_listener = new MyViewListender();
        view->set_view_listener(my_view_listener);