AngleSharp / AngleSharp.Js

:angel: Extends AngleSharp with a .NET-based JavaScript engine.
https://anglesharp.github.io
MIT License
103 stars 22 forks source link

JavaScript DOMContentLoaded not triggered after upgrading Jint #50

Closed mdesousa closed 5 years ago

mdesousa commented 5 years ago

Hi,

We recently upgraded to the latest version of jint (from 2.10.4 --> 2.11.58) and noticed that the test below breaks. It looks like the DOMContentLoaded event is not triggered and the original HTML document never gets modified when it's loaded.

public void ExecuteOnLoadJavaScriptTest()
{
    // arrange
    var html = "<html><head></head><body><div id='status'>FAILED</div></body>" +
        "<script>document.addEventListener('DOMContentLoaded', function() { var element = document.getElementById('status'); element.innerHTML = 'SUCCESS'; });</script></html>";

    // act
    var config = Configuration.Default.WithJavaScript();
    var parser = new HtmlParser(config);
    var document = parser.Parse(html);
    while (document.ReadyState != DocumentReadyState.Complete)
    {
        // javascript processing is asynchronous, need to wait until document state is complete
        Thread.Sleep(100);
    }
    var result = document.DocumentElement.OuterHtml;

    // assert
    result.Should().StartWith("<html><head></head><body><div id=\"status\">SUCCESS</div>");
}
FlorianRappl commented 5 years ago

Is this a dup of #49? It seems so, because for both the root cause is an upgrade of Jint.

Question is now what to do about it:

For me the future is Jint 3. But is seems to be a similar story to AngleSharp's v0.10 release đź—ˇ ... What is your opinion?

mdesousa commented 5 years ago

Ah yes, thanks! I wasn't sure if I had created it and for some reason couldn't find it earlier today. This current issue is cleaner because I did a bit more testing, and it appears that all you need to do is upgrade to the latest jint to see this issue. We can stay in jint 2.10.4 for now... I agree, it'd be nice to leverage Jint 3.0 when it's available. I just tried with the latest beta (1353), and the code compiles and runs... but this issue is still present.

FlorianRappl commented 5 years ago

We can stay in jint 2.10.4 for now... I agree, it'd be nice to leverage Jint 3.0 when it's available. I just tried with the latest beta (1353), and the code compiles and runs... but this issue is still present.

Did not assume the issue is not present, just wanted to ask if we should (before we spend some time on trying to make it run with 2.11) already go to 3.0 and see what's needed to make it run there.

mdesousa commented 5 years ago

Yes, I think that makes sense! Thanks.

FlorianRappl commented 5 years ago

Landed in devel.