Skip to content

JavaScript DOMContentLoaded not triggered after upgrading Jint #50

@mdesousa

Description

@mdesousa

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions