Cannot display webkit Inspector in ultralight c++

25 views Asked by At

I am trying to add an inspector to use for debugging. I am using ultralight and tried following their documentation but was only successful with bundling inspector with my build.

My current code to attempt displaying inspector looks like this:

explicit WebGUI(WebGUIConfig config)
    {
        this->functionMap = config.getFunctionMap();
        app = ultralight::App::Create();
        window = ultralight::Window::Create(app->main_monitor(), config.width, config.height, false,
                                            ultralight::kWindowFlags_Titled | ultralight::kWindowFlags_Resizable *
                                            config.isResizable);
        app->set_window(*window);
        window->SetTitle(config.title.c_str());
        overlay = ultralight::Overlay::Create(*window, window->width(), window->height(), 0, 0);
        overlay->view()->set_load_listener(this);
        overlay->view()->LoadURL(config.url.c_str());
        window->set_listener(this);
        overlay->view()->set_view_listener(this);

        ultralight::RefPtr<ultralight::View> inspectorView = overlay->view()->inspector();
        inspectorView->Resize(500, 500);
        auto inspectorViewView = ultralight::Overlay::Create(*window, *inspectorView, 0, 0);
        inspectorViewView->view()->set_load_listener(this);
        inspectorViewView->view()->set_view_listener(this);
    }

I can see many errors in the debug console (most of them are syntax exceptions), but I dont see any inspector window appearing. Am I doing something wrong? How do I display this view?

1

There are 1 answers

0
Poulpynator On

Disclaimer this is not a full answer.

I used the quickstart to start my project, then :

In MyApp.h :

RefPtr<Overlay> inspector_overlay_;

In MyApp.cpp :

MyApp::MyApp()
{
    app_ = App::Create();
    window_ = Window::Create(app_->main_monitor(), WINDOW_WIDTH, WINDOW_HEIGHT,
                             false, kWindowFlags_Titled | kWindowFlags_Resizable);
    overlay_ = Overlay::Create(window_, 1, 1, 0, 0);


    OnResize(window_.get(), window_->width(), window_->height());
    overlay_->view()->LoadURL("file:///index.html");

    app_->set_listener(this);
    window_->set_listener(this);
    overlay_->view()->set_load_listener(this);
    overlay_->view()->set_view_listener(this);
    overlay_->view()->CreateLocalInspectorView();
}

RefPtr<View> MyApp::OnCreateInspectorView(ultralight::View* caller, bool is_local,
    const String& inspected_url) {
    if (inspector_overlay_)
        return nullptr;

    inspector_overlay_ = Overlay::Create(window_, window_->width(), 200, 0, 150);

    caller->Resize(window_->width(), window_->height());
    inspector_overlay_->Show();
    return inspector_overlay_->view();
}

But with that I am not able to interact with the overlay view (I am probably missing some event handling ?). So I used the browser sample and replace one of the html file of one of the tab with my files, I also added the /inspector folder from the source in the asset folder and fix the CMakeLists.txt file. Then it was working properly so you should be able to extract what you need from there.

If you make it work in your project I am interested as well :)