Menu

#1824 onLoad not called with the correct ready state

2.23
closed
RBRi
javascript (30)
1
2016-09-23
2016-09-22
bitkid
No

Hi!

When serving this test page

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Implement</title>
</head>
<body>
<script>
    var script = document.createElement('script');
    script.src = 'someexisting.js';
    script.async = true;
    script.onload = function () {
        alert(this.readyState)
    };
    document.body.appendChild(script);
</script>
</body>
</html>

the alert will only yield "loading" .. i never get a callback with "complete" / "loaded" state for BrowserVersion.INTERNET_EXPLORER

Related

Bugs: #1824

Discussion

  • RBRi

    RBRi - 2016-09-22
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,6 +2,7 @@
    
     When serving this test page
    
    +~~~~~
     <!DOCTYPE html>
     <html>
     <head>
    @@ -20,5 +21,6 @@
     </script>
     </body>
     </html>
    +~~~~~
    
     the alert will only yield "loading" .. i never get a callback with "complete" / "loaded" state for BrowserVersion.INTERNET_EXPLORER
    
     
  • RBRi

    RBRi - 2016-09-22
    • status: open --> pending
    • assigned_to: RBRi
     
  • RBRi

    RBRi - 2016-09-22

    Have done some real tests with real browsers. Looks like HtmlUnit calls the onload function the same way as IE11 does.
    There was only a minor difference; the readyState returns undefined in your sample. This is fixed now for HtmlUnit.
    Can you please verify your sample with real IE.

     

    Last edit: RBRi 2016-09-22
  • bitkid

    bitkid - 2016-09-22
    package fq.pixel.test;
    
    import com.gargoylesoftware.htmlunit.BrowserVersion;
    import com.gargoylesoftware.htmlunit.WebClient;
    import com.google.common.base.Charsets;
    import com.google.common.io.Files;
    import org.junit.Test;
    
    import java.io.File;
    import java.io.IOException;
    
    public class ExampleTest {
        String html = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "    <meta charset=\"utf-8\"/>\n" +
                "    <title>Implement</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "<script>\n" +
                "    var script = document.createElement('script');\n" +
                "    script.src = 'test.js';\n" +
                "    script.async = true;\n" +
                "    script.onload = function () {\n" +
                "        alert(this.readyState)\n" +
                "    };\n" +
                "    document.body.appendChild(script);\n" +
                "</script>\n" +
                "</body>\n" +
                "</html>";
    
        @Test
        public void showDefect() throws IOException {
            WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER);
            webClient.setAlertHandler((page, message) -> System.out.println(message));
            File to = new File("test.html");
            to.deleteOnExit();
            File jsFile = new File("test.js");
            jsFile.deleteOnExit();
            Files.write(html, to, Charsets.UTF_8);
            Files.write("{}", jsFile, Charsets.UTF_8);
            webClient.getPage(to.toURI().toURL());
        }
    }
    

    the alert listener prints "loading" for me (OSX)

     
    • RBRi

      RBRi - 2016-09-23

      To make it clear:
      I have done a similar test. And yes the result was 'loading' when running the test with HtmlUnit. But when running the test inside a real IE the result was 'undefind'. And there was no 'complete' at all. Based on this observation i have changed the code to also produce 'undefined'.

      If you use the latest build from teamcity (https://ci.canoo.com/teamcity/project.html?projectId=HtmlUnit&tab=projectOverview) you should get the same results.

      In general HtmlUnit tries to mimic the real browser als close as possible.
      Please check if you get the same results also with real browsers.

       
  • RBRi

    RBRi - 2016-09-23

    The fix seems to have some positive effect for our jQuery test cases also. I guess it was not wrong at all.

     
  • bitkid

    bitkid - 2016-09-23

    undefined is totally fine! that's how our production code checks the onLoad/onReadyStateChange handler

    element.onload = element.onreadystatechange = function () {
                if (!loaded && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
    

    so !this.readyState in the if then works as expected! Thanks for your help!

     
  • RBRi

    RBRi - 2016-09-23

    Ok, great. There is also a new snapshot build available.
    Will close this.
    Thanks for the detailed report.

     
  • RBRi

    RBRi - 2016-09-23
    • status: pending --> closed
     
  • bitkid

    bitkid - 2016-09-23

    where can i find the related code change? just out of interest :)

     
    • RBRi

      RBRi - 2016-09-23

      https://sourceforge.net/p/htmlunit/code/commit_browser

      On Fri, 23 Sep 2016 11:04:57 +0000 bitkid wrote:

      where can i find the related code change? just out of interest :)


      ** [bugs:#1824] onLoad not called with the correct ready state**

      Status: closed
      Group: 2.23
      Labels: javascript
      Created: Thu Sep 22, 2016 12:29 PM UTC by bitkid
      Last Updated: Fri Sep 23, 2016 10:24 AM UTC
      Owner: RBRi

      Hi!

      When serving this test page

      ~~~~~
      <!DOCTYPE html>


      <meta charset="utf-8">
      <title>Implement</title>


      <script><br> var script = document.createElement('script');<br> script.src = 'someexisting.js';<br> script.async = true;<br> script.onload = function () {<br> alert(this.readyState)<br> };<br> document.body.appendChild(script);<br> </script>


      ~~~~~

      the alert will only yield "loading" .. i never get a callback with "complete" / "loaded"
      state for BrowserVersion.INTERNET_EXPLORER


      Sent from sourceforge.net because htmlunit-develop@lists.sourceforge.net is subscribed
      to https://sourceforge.net/p/htmlunit/bugs/

      To unsubscribe from further messages, a project admin can change settings at
      https://sourceforge.net/p/htmlunit/admin/bugs/options. Or, if this is a mailing list, you
      can unsubscribe from the mailing list.

      ----< Inline text [text-plain-05.txt] >------------------



      ----< Inline text [text-plain-06.txt] >------------------


      HtmlUnit-develop mailing list
      HtmlUnit-develop@lists.sourceforge.net
      https://lists.sourceforge.net/lists/listinfo/htmlunit-develop

       

      Related

      Bugs: #1824


Log in to post a comment.