Skip to content

[πŸš€ Feature]: [dotnet] Have IJavascriptEngine dispose it's underlying DevToolsSessionΒ #11616

@RenderMichael

Description

@RenderMichael

Feature and motivation

Currently, IJavascriptEngine has a private DevToolsSession which cannot be disposed of, leaving it open until the end of execution. I would like to be able to dispose this session. I opened #11594 to achieve this.

Usage example

My code currently looks like

public async Task<ReadOnlyCollection<ConsoleLog>> ScanConsoleAsync(System.Action action)
{
    var consoleMessages = new List<ConsoleLog>();

    var monitor = new JavaScriptEngine(Context.WebDriver);
    monitor.JavaScriptConsoleApiCalled += StartMonitoring;
    await monitor.StartEventMonitoring();
    action.Invoke();
    monitor.StopEventMonitoring();
    monitor.JavaScriptConsoleApiCalled -= StartMonitoring;

    return consoleMessages.AsReadOnly();

    void StartMonitoring(object? _, JavaScriptConsoleApiCalledEventArgs e) => consoleMessages.Add(new ConsoleLog(e.MessageType, e.MessageContent, e.MessageTimeStamp));
}

public sealed record ConsoleLog(string Type, string Text, DateTime Timestamp);

and this change would simply have me add using to the class's invocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-dotnet.NET BindingsI-enhancementSomething could be better

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions