AngleSharp / AngleSharp.Js

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

Custom IConsoleLogger not called #81

Closed greengiant83 closed 2 years ago

greengiant83 commented 2 years ago

When using a custom a IConsoleLogger its Log() method is never called

Here is the AngleSharp code. Note that the source html contains a script that calls: console.log("Oi!").

        var source = "<!DOCTYPE html><html lang='en'><body><script>console.log('Oi!');</script></body></html>";
        var config = Configuration.Default.WithJs().WithConsoleLogger(ctx => new MyConsoleLogger());
        var context = BrowsingContext.New(config);
        var document = await context.OpenAsync(req => req.Content(source));

Here is the code for MyConsoleLogger

public class MyConsoleLogger : IConsoleLogger
{
    public MyConsoleLogger()
    {
        Debug.Log("MyConsoleLogger constructed");
    }

    public void Log(object[] values)
    {
        Debug.Log("console.log called");
    }
}

MyConsoleLogger is constructed but the log method is never called