Menu

Synchronous xmlhttprequest on the main thread.

Help
itdanne
2015-02-26
2015-02-27
  • itdanne

    itdanne - 2015-02-26

    First of all, thanks for an awesome product!

    In my dealings with the JWebBrowser I've noticed that the AWT-EventThread will hang from time to time when displaying certain web content. After some investigation I've seen that it mostly is due to synchronous XmlHttpRequest. I've put together a simple html that will completely hang the SimpleWebBrowserExample when loaded:

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <script>
            /**
             * Synchronous call to non routable address will lock up     the browser thread.
             */
            function sleep() {
                var request = new XMLHttpRequest();
                request.open('GET', 'http://10.255.255.1/', false);
                request.send(null);
    
                if (request.status === 200) {
                    console.log(request.responseText);
                }
            }
        </script>
    </head>
    <body onload="sleep()">
        This page will block indefinitely due to synchronous,     unresolvable call on "onload".
    </body>
    </html>
    

    This is of course an extreme example but even short blocks on the main thread become quite noticeable when they spill over to the EDT.

    When running in SimpleWebBrowser the EDT will hang on: chrriis.dj.nativeswing.swtimpl.components.core.NativeWebBrowser#getResourceLocation

    In the application where I use JWebBrowser it rather hangs on:
    java.awt.Component#hasFocus at
    chrriis.dj.nativeswing.NativeSwing.NIAWTEventListener#adjustNativeComponents at
    chrriis.dj.nativeswing.NativeSwing.NIAWTEventListener#eventDispatched

    My current solution is to make sure that no webpages that are displayed uses synchronous calls on the main thread, but it would be great if the browser didn't hang the EDT if someone happen to make a problematic web page.

     

    Last edit: itdanne 2015-02-26
  • Christopher Deckers

    Hi,

    As far as I know, all I am doing is to delegate to the SWT Browser. If SWT blocks its UI thread, then it will also block the AWT UI thread, and unfortunately I don't think I can do anything about it...

    -Christopher

     

Log in to post a comment.