Execution order of several CefFrame::ExecuteJavaScript calls

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Execution order of several CefFrame::ExecuteJavaScript calls

Postby palaver » Thu Jan 26, 2017 11:44 am

Do we need to synchronize between CefFrame::ExecuteJavaScript() calls to make sure they execute in the correct order, if they are called in a loop?

Here's an example scenario:
Code: Select all
class MyBrowserControl
{
    CefRefPtr<CefBrowser> m_pBrowser;
    bool m_isContextCreated;
    vector<string> m_jsQueue;
};

MyBrowserControl::Create()
{
    m_pBrowser = CreateBrowserSync(...);
    m_isContextCreated = false;
}


MyBrowserControl::ExecuteJavaScript(std::string const &jsCall)
{
    if (!m_isContextCreated) {
        m_jsQueue.push_back(jsCall);
    }
}

// In response to message from the CefRenderProcessHandler::OnContextCreated() callback to the browser process
MyBrowserControl::OnContextCreated()
{
    if (!m_jsQueue.empty()) {
        for (auto const &jsCall : m_jsQueue) {
            CefRefPtr<CefFrame> pFrame = m_pBrowser->GetMainFrame();
            pFrame->ExecuteJavaScript(jsCall, pFrame->GetURL(), 0);   // <-- [1]
        }
    }
}


It seems like the order of execution of the JS calls is not always correct. Do I need to do any synchronization? If so, what is the callback to see if a JS call has completed/returned?
palaver
Techie
 
Posts: 36
Joined: Wed Nov 25, 2015 9:51 am

Return to Support Forum

Who is online

Users browsing this forum: ndesktop and 40 guests