private void WebView2WebResourceRequested(object sender, WebResourceRequestedEventArgs e) { WebView2WebResourceRequest webResourceRequest = e.Request; WebView2WebResourceResponse webResourceResponse = e.Response; string message = "{ \"kind\": \"event\", \"name\": " + "\"WebResourceRequested\", \"args\": {" + "\"request\": " + RequestToJsonString(webResourceRequest) + ", " + "\"response\": null" + "}"; message += WebViewPropertiesToJsonString(_eventSourceWebView2); message += "}"; PostEventMessage(message); }
private string RequestToJsonString(WebView2WebResourceRequest request) { IStream content = request.Content; WebView2HttpRequestHeaderCollection headers = request.Headers; string method = request.Method; string uri = request.Uri; string result = "{"; result += "\"content\": "; result += (content == null ? "null" : "\"...\""); result += ", "; result += "\"headers\": " + RequestHeadersToJsonString(headers) + ", "; result += "\"method\": " + EncodeQuote(method) + ", "; result += "\"uri\": " + EncodeQuote(uri) + " "; result += "}"; return(result); }