Skip to content

[Feature]: Add sessionId support to DevToolsProtocolHelper #5258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AFatNiBBa opened this issue May 28, 2025 · 1 comment
Open

[Feature]: Add sessionId support to DevToolsProtocolHelper #5258

AFatNiBBa opened this issue May 28, 2025 · 1 comment
Assignees
Labels
feature request feature request

Comments

@AFatNiBBa
Copy link

Describe the feature/enhancement you need

I started using the DevToolsProtocolHelper and it's incredibly useful, its only problem is that it doesn't provide any way of calling CoreWebView2.CallDevToolsProtocolMethodForSessionAsync() so I can never use it when I need to execute the method on a specific session

The scenario/use case where you would use this feature

I want to execute DevToolsProtocolHelper.Page.PrintToPDFAsync() on a new session created with DevToolsProtocolHelper.Target.CreateTargetAsync() and DevToolsProtocolHelper.Target.AttachToTargetAsync()

How important is this request to you?

Nice to have. There are other ways to tackle this, but having official API support would be beneficial.

Suggested implementation

Instead of passing the CoreWebView2 to DevToolsProtocolHelper and its domains, it would be wise to pass an interface with one of two implementations

namespace Microsoft.Web.WebView2.Core.DevToolsProtocolExtension
{
    public static class DevToolsExtension
    {
        public static DevToolsProtocolHelper GetDevToolsProtocolHelper(this CoreWebView2 coreWebView2)
        {
            return new DevToolsProtocolHelper(new BaseSessionDevToolsProtocolProvider(coreWebView2));
        }

        public static DevToolsProtocolHelper GetDevToolsProtocolHelper(this CoreWebView2 coreWebView2, string sessionId)
        {
            return new DevToolsProtocolHelper(new CustomSessionDevToolsProtocolProvider(coreWebView2, sessionId));
        }
    }
}

internal interface IDevToolsProtocolProvider
{
    Task<string> CallDevToolsProtocolMethodAsync(string methodName, string parametersAsJson);
}

internal class BaseSessionDevToolsProtocolProvider(CoreWebView2 core) : IDevToolsProtocolProvider
{
    public Task<string> CallDevToolsProtocolMethodAsync(string methodName, string parametersAsJson) => core.CallDevToolsProtocolMethodAsync(methodName, parametersAsJson);
}

internal class CustomSessionDevToolsProtocolProvider(CoreWebView2 core, string sessionId) : IDevToolsProtocolProvider
{
    public Task<string> CallDevToolsProtocolMethodAsync(string methodName, string parametersAsJson) => core.CallDevToolsProtocolMethodForSessionAsync(sessionId, methodName, parametersAsJson);
}

What does your app do? Is there a pending deadline for this request?

My app shows some documents that I would like to print, but I need to do so in a new document because in the main page there are some menus that shouldn't be printed.
As a requirement I mustn't show the default print UI, so I can't just put all in an iframe and then call the Window.print() on that.
I have a deadline but I can call CoreWebView2.CallDevToolsProtocolMethodForSessionAsync() for the time being

@AFatNiBBa
Copy link
Author

Alternatively, it would be useful to have something like CoreWebView2.PrintToPdfStreamAsync() on CoreWebView2Frames

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request
Projects
None yet
Development

No branches or pull requests

2 participants