Closed yanxiaodi closed 1 year ago
In my winform app, I try this
await CoreWebView2.CallDevToolsProtocolMethodAsync("Fetch.enable", "{\"patterns\":[{\"urlPattern\":\"*\", \"requestStage\":\"Response\"}]}");
It working good. About "RequestPattern[]", is it form CefSharp Common? I did not see any ref in webView2.
Hello @yanxiaodi ,
I have assigned this to @imicy, who will help figure out how to approach the bug you're seeing. Thanks for your find!
@chinasmu Thanks. I think I got it.
@imicy @victorthoang So if we call the method like
await CoreWebView2.CallDevToolsProtocolMethodAsync("Fetch.enable", "{\"patterns\":[{\"urlPattern\":\"*\", \"requestStage\":\"Response\"}]}");
It works. Because the parameter is an object that has a patterns
field, which has the array as the value. But if we call the method like
var patterns = new RequestPattern[] { new RequestPattern { RequestStage = "Response" } };
// The below line throws an exception
await devToolsProtocolHelper.Fetch.EnableAsync(patterns);
The parameter is an array, not an object that has a patterns
field.
@yanxiaodi, Hi, I'm looking into this bug.
The reason is, RequestPattern
's param cannot be null. You could try:
var patterns = new RequestPattern[] {
new RequestPattern {
UrlPattern = "",
RequestStage = "Response",
ResourceType = ""
}
};
And about
await webView.CoreWebView2.CallDevToolsProtocolMethodAsync("Fetch.enable", JsonSerializer.Serialize(patterns));
has an another problem, you should use like this:
dynamic parameters = new ExpandoObject();
parameters.patterns = patterns;
await webView.CoreWebView2.CallDevToolsProtocolMethodAsync("Fetch.enable", JsonSerializer.Serialize(parameters));
The difference is :
[{"urlPattern":"","resourceType":"","requestStage":"Response"}] // your code generate
{"patterns":[{"urlPattern":"","resourceType":"","requestStage":"Response"}]} // expected
Thanks @yunate
That's not an intuitive way to use this API. As a user, when I use await devToolsProtocolHelper.Fetch.EnableAsync(patterns);
, the parameter has the RequestPattern[]
type. Users would not know why it needs a ExpandoObject
.
I think you can change the parameter type for this API?
@yanxiaodi thanks for your suggestion.
About Users would not know why it needs a ExpandoObject.
The reason is the CallDevToolsProtocolMethodAsync
require its json string param must like {"patterns":[{"urlPattern":"","resourceType":"","requestStage":"Response"}]}
.
About can change the parameter type for this API
, we will talk about this with our team, but the origin API will be retained for version compatible.
The format of CDP API is outside the scope of WebView2 and is currently By Design.
Description I would like to call
Fetch.EnableAsync()
method with aRequestPattern
parameter but I got an error:Version SDK: WebView2: 1.0.1343.22, WebView2.DevToolsProtocolExtension: 1.0.824 Runtime: Framework: WPF OS: Win11, 22H2
Repro Steps
I have some code like this:
Screenshots
Additional context
AB#41812449