AngleSharp / AngleSharp.Js

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

JavaScript function changing dataset properties of element node is executed from C# but dataset changes are not reflected in AngleSharp DOM #77

Open martin-honnen opened 3 years ago

martin-honnen commented 3 years ago

Bug Report

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

A JavaScript function that changes two dataset properties on an element node is successfully called from C# but somehow the dataset property changes are not reflected in the AngleSharp DOM.

Steps to Reproduce

  1. [First Step] Run code
    
    using System;
    using System.Threading.Tasks;
    using AngleSharp;
    using AngleSharp.Html.Dom;
    using AngleSharp.Scripting;

namespace DatasetMWE { class Program { static async Task Main(string[] args) { var html = @"<!DOCTYPE html>

Test

Test

Section test

"; var jsService = new JsScriptingService(); var config = Configuration.Default.With(jsService); var context = BrowsingContext.New(config); var document = await context.OpenAsync(req => req.Content(html)); var testFunction = jsService.GetOrCreateJint(document).GetValue("test"); var result = testFunction.Invoke(); Console.WriteLine(document.DocumentElement.OuterHtml); var sectionEl = document.QuerySelector("section") as IHtmlElement; Console.WriteLine(sectionEl.Dataset["level"]); Console.WriteLine(result); } } } ``` **Expected behavior:** The dataset changes the JavaScript function performs should be reflected in the AngleSharp DOM so both the OuterHtml as well as the result output should show the changes, i.e. the output should be ``` Test

Test

Section test

2 test executed ``` **Actual behavior:** I get the output ``` Test

Test

Section test

1 test executed ``` **Environment details:** [OS, .NET Runtime, ...] Windows 10 20H2, .NET 5 (Core) Visual Studio 2019 console project ## Possible Solution