Skip to content

Can't get Jint when no script tag is included #28

@KurtGokhan

Description

@KurtGokhan

I am trying to get Jint engine from the javascript service. However, when there is no script tag with a body, GetJint method returns null. I can get Jint engine after adding a script dynamically or including a script tag with body at start. It can be tested with following method.

[TestMethod]
public async Task JintTest()
{
    var cfg = Configuration.Default.WithJavaScript().WithDefaultLoader();
    var svc = cfg.Services.OfType<ScriptingService>().FirstOrDefault(x => x.Engine.Type == "text/javascript");

    var htmlEmpty = "<!doctype html><script type=\"text/javascript\"></script>";
    var htmlNonEmpty = "<!doctype html><script type=\"text/javascript\">a=5</script>";

    var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(htmlNonEmpty));
    Assert.IsNotNull(svc.Engine.GetJint(document), "Can't get Jint when the script tag is not empty");

    document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(htmlEmpty));
    Assert.IsNotNull(svc.Engine.GetJint(document), "Can't get Jint when the script tag is empty");  // Currently error is here

    var script = document.CreateElement("script");
    script.SetAttribute("type","text/javascript");
    script.TextContent = "a=5";
    document.Head.AppendChild(script);

    Assert.IsNotNull(svc.Engine.GetJint(document), "Can't get Jint even after dynamically adding the script");
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions