AngleSharp / AngleSharp.Js

:angel: Extends AngleSharp with a .NET-based JavaScript engine.

Home Page:https://anglesharp.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JavaScript DOMContentLoaded not triggered after upgrading Jint

mdesousa opened this issue · comments

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>");
}

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:

  • Obviously, the fix is to avoid upgrading Jint and something (internally) seems to break from AngleSharp's expectations
  • If we would make it work with 2.11.x (how? can someone look into it?) why shouldn't we directly go for Jint 3.0? (see sebastienros/jint#343)

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?

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.

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.

Yes, I think that makes sense! Thanks.

Landed in devel.