Menu ▾ ▴

#1438 NicelyResynchronizingAjaxController not used properly

2.10
open
nobody
None
5
2012-10-21
2012-09-27
mauromol
No

As far as I understand it correctly, the NicelyResynchronizingAjaxController should be used to make XHR requests synchronous to the main thread, that is:

WebClient webClient = new WebClient();
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
HtmlPage page = webClient.getPage(myUrl); // here, getPage should take enough time for XHR requests to be all executed
page.asXml(); // fully compiled XML page generated

Correct me if I'm wrong.
The problem I see is that this is not the case: XHR requests are still done on other threads on the background. Debugging HtmlUnit I found out why. To decide whether to make XHR requests synchronous or not, NicelyResynchronizingAjaxController.processSynchron(HtmlPage, WebRequest, boolean) is called. This returns true only if the current thread is the same as the thread in which the NicelyResynchronizingAjaxController instance has been constructed (which is supposed to be the main thread). Unfortunately, what I see is that while I create the NicelyResynchronizingAjaxController in my main thread, the processSynchron method is actually invoked in another thread called "JS executor for <webclient instance="">": hence, XHR requests are never resynchronized.
What I still don't understand is this: even if NicelyResynchronizingAjaxController were resynchronizing calls correctly, they would be synchronous against this "JS executor" thread, not the main thread. So, unless there's an API method to join the main thread with the "JS executor" thread, I still couldn't perform what I need (i.e.: wait for all JS code to finish before getting the fully-compiled XML representation of my page).</webclient>

Discussion


Log in to post a comment.