MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Bug]: WebView2 WebResourceRequested does not fired for WebSockets

Open
#4,303 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

Hi,

I'm using WebView2 in custom WFP application. I need to add custom headers into requests so I use WebResourceRquested event. Here is my code:

`using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;

namespace WebViewAddingHeaders;
internal class MyWebBrowser: WebView2
{
public MyWebBrowser()
{
CoreWebView2InitializationCompleted += OnInitializationCompleted;
}

private void OnInitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
{
	CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All);
	CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
}

private void CoreWebView2_WebResourceRequested(object? sender, CoreWebView2WebResourceRequestedEventArgs e)
{
	e.Request.Headers.SetHeader("MY_TESTING_HEADER", "Testing header value");
}

}`

But I noticed that this event is not fired for web sockets. I try to access python + streamlit application. There are sent multiple requests. For "normal" requests the header is present.
image
But it is not present for web sockets
image

I tried to filter only WebSockets in AddWebResourceRequestedFilter. I tried to enable custom scheme for ws. But nothing helped.

Is it possible to catch and enhance all requests, including web sockets?

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

1.0.2210.55

SDK Version

No response

Framework

WPF

Operating System

Windows 11

OS Version

No response

Repro steps

In description.

Repros in Edge Browser

No

Regression

No, this never worked

Last working version (if regression)

No response

AB#48649859

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WPF repro in the issue, focusing on CoreWebView2.AddWebResourceRequestedFilter and the WebResourceRequested event. Verify the behavior for WebSocket requests using the stated WebView2 runtime and compare it with normal requests. Done means determining whether WebSocket requests can be intercepted and have headers added, or documenting the supported limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.