CefDOMVisitor Visit method never called?

43 Views Asked by At

I want to detect document.ready via CefDOMVisitor Visit call and wrote code like below, but after page load I get logs DOMVisitor() and ~DOMVisitor(), no DOMVisitor::Visit. Why is "Visit" not called?

class DOMVisitor : public CefDOMVisitor {
public:
    DOMVisitor(){
        App::Log(L"DOMVisitor()", __FUNCTION__, __FILE__, __LINE__);
    };
    ~DOMVisitor(){
        App::Log(L"~DOMVisitor()", __FUNCTION__, __FILE__, __LINE__);
    };
    virtual void Visit(CefRefPtr<CefDOMDocument> document) override{
        App::Log(L"DOMVisitor::Visit", __FUNCTION__, __FILE__, __LINE__);
    };

    IMPLEMENT_REFCOUNTING(DOMVisitor);
};
class LoadHandler : public CefLoadHandler {
public:
    virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        int httpStatusCode) override{
        CEF_REQUIRE_UI_THREAD();

        if (frame && frame->IsMain() && httpStatusCode == 200)
        {
            frame->VisitDOM(new DOMVisitor);
        }
    };

    IMPLEMENT_REFCOUNTING(LoadHandler);
};

fin.

I run the RENDERER process and the BROWSER process at the same time, and LoadHandler is implemented in the BROWSER process. However, the CefFrame::VisitDOM() method can only be called from the rendering process, so DOMVisitor needs to be implemented in the RENDERER process rather than implemented and called in the BROWSER process.

0

There are 0 best solutions below