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?