Skip to content
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

Microsoft.Web.WebView2 WebResourceRequested Set Response Not Working - Requests keeping in a pending state #568

Closed
pauloortins opened this issue Oct 22, 2020 · 9 comments
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@pauloortins
Copy link

pauloortins commented Oct 22, 2020

Description
When trying to set the response inside the WebResourceRequested the request is freezing in the pending state instead to return the response to the browser.

Version
SDK: 1.0.674-prerelease
Runtime: 88.0.678.0
Framework: WPF
OS: Win10

Repro Steps

private void WebView_CoreWebView2Ready(object sender, EventArgs e)
{
   Control.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
   Control.CoreWebView2.AddWebResourceRequestedFilter("gameplan://*", CoreWebView2WebResourceContext.Image);
}
private void CoreWebView2_WebResourceRequested(object sender, CoreWebView2WebResourceRequestedEventArgs e)
{
   var response = webView.CoreWebView2.Environment.CreateWebResourceResponse(null, (int)HttpStatusCode.Forbidden, null, null);
   e.Response = response;
}

image

Screenshots

Additional context

AB#29931313

@pauloortins pauloortins added the bug Something isn't working label Oct 22, 2020
@champnic champnic added the tracked We are tracking this work internally. label Oct 22, 2020
@champnic
Copy link
Member

Thanks for reporting, I've opened a bug on our backlog and we'll take a look! Just to confirm, have you put a breakpoint in CoreWebView2_WebResourceRequested and are able to see it getting hit? Our support for custom URIs is incomplete at the moment, and I wanted to check if it was a problem stemming from the custom URI or from creating and setting the response. Thanks!

@pauloortins
Copy link
Author

pauloortins commented Oct 22, 2020 via email

@pauloortins
Copy link
Author

Hello! Any news?

@champnic
Copy link
Member

champnic commented Nov 4, 2020

No, we haven't had a chance to look at this issue yet. We're tentatively scheduled to look at it later this month. I'll keep you updated when we've had a chance to investigate the bug. Thanks!

@daricvn
Copy link

daricvn commented Nov 21, 2020

I received NotImplemented exception while trying to access the Environment property. Hope this help.

@Yarith
Copy link

Yarith commented Dec 10, 2020

I got the NotImplementedException and the (pending) requests, too.

The not impemented property was not too difficult to work around, because i was already creating an own environment:

this.environment = await CoreWebView2Environment.CreateAsync(userDataFolder: userDataFolder);
// Make sure that before this call the webView2 is already put inside a container, e.g. window.Content = webView2
// If you forget it, this call will hang forever, because it is waiting for the hwnd.
await webView2.EnsureCoreWebView2Async(environment);

The (pending) requests seems to be caused when you are not putting a non-empty string into the ReasonPhrase parameter. It must be a string with Length > 0. Here some examples what has worked for me:

e.Response = this.environment.CreateWebResourceResponse(null, (int)HttpStatusCode.NotFound, "Not Found", null);
e.Response = this.environment.CreateWebResourceResponse(null, (int)HttpStatusCode.RequestedRangeNotSatisfiable, "Range Not Satisfiable", null);
e.Response = this.environment.CreateWebResourceResponse(
    LimitStream(stream, (int)length), (int)HttpStatusCode.PartialContent, "Partial Content", 
    $"Content-Range: bytes {from}-{from + length - 1}/{stream.Length}\r\n" +
    $"Content-Length: {length}");
e.Response = this.environment.CreateWebResourceResponse(stream, (int)HttpStatusCode.OK, "Ok", null);

@dianaqu
Copy link
Contributor

dianaqu commented Feb 10, 2021

Hi @pauloortins, I am the developer looking into this bug, but I don't seem to be able to repro it. I tried your code with a sample app and don't see the pending status. Would you mind share a repro a project so I can better understand the issue?

image

@champnic
Copy link
Member

This should be fixed in runtime 90.0.804.0+. Please give it a try and let us know if you run into any further issues. Thanks!

@Skarnivorous
Copy link

I have been getting this in 1.0.824-pre - a table of img will sit in 'Pending' for quite some time before suddenly being allowed to load, and the newer images added after that also load quickly. Randomly it will not have any delay at all. None of them start at all. Look forward to updated control to see if resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

6 participants