How to determine when ExecuteJavaScript is complete

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.

How to determine when ExecuteJavaScript is complete

Postby codetemplar » Fri Jun 17, 2016 6:34 am

Hi All,

Due to the nature of the application I am writing I need to handle synchronous XMLHttpRequest. I have set the javascript up correctly so it blocks on the send command. I have created a scheme to intercept this request which works perfectly. The javascript does not continue exiting until my scheme handler calls callback->continue("") inside ProcessRequest.

However what I want to do inside ProcessRequest before I call continue on the callback is execute some javascript code using ExecuteJavaScript like so:

Code: Select all
bool ResourceHandler::ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
{
   m_browser->GetMainFrame()->ExecuteJavaScript("alert(\"here\");", m_browser->GetMainFrame()->GetURL(), 0);   
   callback->Continue();
}


My javascript looks like:

Code: Select all
function CreateXmlHttpRequest() {
        var xmlHttp = null;
        if (window.XMLHttpRequest) {
            // For Mozilla, Safari, ...
            xmlHttp = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlHttp;
    }

    var sendXml = function(eventName, detail) {
        var xmlHttp = CreateXmlHttpRequest();
      var para = "";
        xmlHttp.open("POST", "http://testdomain/", false);
        xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttp.send(para);
   alert("moved on");
    };



Now I expected, and need, for the "here" alert sent from the c++ ExecuteJavaScript to appear before the "moved on" alert after the synchronous XMLHttpResquest has completed. I am guessing that ExecuteJavaScript is an asynchronous call which is how this is happening. Is there any way that I can address this?

Thanks
codetemplar
Newbie
 
Posts: 5
Joined: Thu Feb 25, 2016 3:25 pm

Re: How to determine when ExecuteJavaScript is complete

Postby magreenblatt » Fri Jun 17, 2016 9:20 am

You cannot execute other JavaScript in the same page while a synchronous XMLHttpResquest is pending.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 111 guests