// Copyright © 2020 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
namespace CefSharp.DevTools.Network
{
using System.Linq;
///
/// Network domain allows tracking network activities of the page. It exposes information about http,
/// file, data and other requests and responses, their headers, bodies, timing, etc.
///
public partial class Network : DevToolsDomainBase
{
private CefSharp.DevTools.IDevToolsClient _client;
public Network(CefSharp.DevTools.IDevToolsClient client)
{
_client = (client);
}
///
/// Clears browser cache.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task ClearBrowserCacheAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.clearBrowserCache", dict);
return methodResult;
}
///
/// Clears browser cookies.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task ClearBrowserCookiesAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.clearBrowserCookies", dict);
return methodResult;
}
partial void ValidateDeleteCookies(string name, string url = null, string domain = null, string path = null);
///
/// Deletes browser cookies with matching name and url or domain/path pair.
///
/// Name of the cookies to remove.
/// If specified, deletes all the cookies with the given name where domain and path matchprovided URL.
/// If specified, deletes only cookies with the exact domain.
/// If specified, deletes only cookies with the exact path.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task DeleteCookiesAsync(string name, string url = null, string domain = null, string path = null)
{
ValidateDeleteCookies(name, url, domain, path);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("name", name);
if (!(string.IsNullOrEmpty(url)))
{
dict.Add("url", url);
}
if (!(string.IsNullOrEmpty(domain)))
{
dict.Add("domain", domain);
}
if (!(string.IsNullOrEmpty(path)))
{
dict.Add("path", path);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.deleteCookies", dict);
return methodResult;
}
///
/// Disables network tracking, prevents network events from being sent to the client.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task DisableAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.disable", dict);
return methodResult;
}
partial void ValidateEmulateNetworkConditions(bool offline, long latency, long downloadThroughput, long uploadThroughput, CefSharp.DevTools.Network.ConnectionType? connectionType = null);
///
/// Activates emulation of network conditions.
///
/// True to emulate internet disconnection.
/// Minimum latency from request sent to response headers received (ms).
/// Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
/// Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
/// Connection type if known.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task EmulateNetworkConditionsAsync(bool offline, long latency, long downloadThroughput, long uploadThroughput, CefSharp.DevTools.Network.ConnectionType? connectionType = null)
{
ValidateEmulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput, connectionType);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("offline", offline);
dict.Add("latency", latency);
dict.Add("downloadThroughput", downloadThroughput);
dict.Add("uploadThroughput", uploadThroughput);
if (connectionType.HasValue)
{
dict.Add("connectionType", this.EnumToString(connectionType));
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.emulateNetworkConditions", dict);
return methodResult;
}
partial void ValidateEnable(int? maxTotalBufferSize = null, int? maxResourceBufferSize = null, int? maxPostDataSize = null);
///
/// Enables network tracking, network events will now be delivered to the client.
///
/// Buffer size in bytes to use when preserving network payloads (XHRs, etc).
/// Per-resource buffer size in bytes to use when preserving network payloads (XHRs, etc).
/// Longest post body size (in bytes) that would be included in requestWillBeSent notification
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task EnableAsync(int? maxTotalBufferSize = null, int? maxResourceBufferSize = null, int? maxPostDataSize = null)
{
ValidateEnable(maxTotalBufferSize, maxResourceBufferSize, maxPostDataSize);
var dict = new System.Collections.Generic.Dictionary();
if (maxTotalBufferSize.HasValue)
{
dict.Add("maxTotalBufferSize", maxTotalBufferSize.Value);
}
if (maxResourceBufferSize.HasValue)
{
dict.Add("maxResourceBufferSize", maxResourceBufferSize.Value);
}
if (maxPostDataSize.HasValue)
{
dict.Add("maxPostDataSize", maxPostDataSize.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.enable", dict);
return methodResult;
}
///
/// Returns all browser cookies. Depending on the backend support, will return detailed cookie
/// information in the `cookies` field.
///
/// returns System.Threading.Tasks.Task<GetAllCookiesResponse>
public async System.Threading.Tasks.Task GetAllCookiesAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.getAllCookies", dict);
return methodResult.DeserializeJson();
}
partial void ValidateGetCertificate(string origin);
///
/// Returns the DER-encoded certificate.
///
/// Origin to get certificate for.
/// returns System.Threading.Tasks.Task<GetCertificateResponse>
public async System.Threading.Tasks.Task GetCertificateAsync(string origin)
{
ValidateGetCertificate(origin);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("origin", origin);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.getCertificate", dict);
return methodResult.DeserializeJson();
}
partial void ValidateGetCookies(string[] urls = null);
///
/// Returns all browser cookies for the current URL. Depending on the backend support, will return
/// detailed cookie information in the `cookies` field.
///
/// The list of URLs for which applicable cookies will be fetched
/// returns System.Threading.Tasks.Task<GetCookiesResponse>
public async System.Threading.Tasks.Task GetCookiesAsync(string[] urls = null)
{
ValidateGetCookies(urls);
var dict = new System.Collections.Generic.Dictionary();
if ((urls) != (null))
{
dict.Add("urls", urls);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.getCookies", dict);
return methodResult.DeserializeJson();
}
partial void ValidateGetResponseBody(string requestId);
///
/// Returns content served for the given request.
///
/// Identifier of the network request to get content for.
/// returns System.Threading.Tasks.Task<GetResponseBodyResponse>
public async System.Threading.Tasks.Task GetResponseBodyAsync(string requestId)
{
ValidateGetResponseBody(requestId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("requestId", requestId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.getResponseBody", dict);
return methodResult.DeserializeJson();
}
partial void ValidateGetRequestPostData(string requestId);
///
/// Returns post data sent with the request. Returns an error when no data was sent with the request.
///
/// Identifier of the network request to get content for.
/// returns System.Threading.Tasks.Task<GetRequestPostDataResponse>
public async System.Threading.Tasks.Task GetRequestPostDataAsync(string requestId)
{
ValidateGetRequestPostData(requestId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("requestId", requestId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.getRequestPostData", dict);
return methodResult.DeserializeJson();
}
partial void ValidateGetResponseBodyForInterception(string interceptionId);
///
/// Returns content served for the given currently intercepted request.
///
/// Identifier for the intercepted request to get body for.
/// returns System.Threading.Tasks.Task<GetResponseBodyForInterceptionResponse>
public async System.Threading.Tasks.Task GetResponseBodyForInterceptionAsync(string interceptionId)
{
ValidateGetResponseBodyForInterception(interceptionId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("interceptionId", interceptionId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.getResponseBodyForInterception", dict);
return methodResult.DeserializeJson();
}
partial void ValidateTakeResponseBodyForInterceptionAsStream(string interceptionId);
///
/// Returns a handle to the stream representing the response body. Note that after this command,
/// the intercepted request can't be continued as is -- you either need to cancel it or to provide
/// the response body. The stream only supports sequential read, IO.read will fail if the position
/// is specified.
///
/// interceptionId
/// returns System.Threading.Tasks.Task<TakeResponseBodyForInterceptionAsStreamResponse>
public async System.Threading.Tasks.Task TakeResponseBodyForInterceptionAsStreamAsync(string interceptionId)
{
ValidateTakeResponseBodyForInterceptionAsStream(interceptionId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("interceptionId", interceptionId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.takeResponseBodyForInterceptionAsStream", dict);
return methodResult.DeserializeJson();
}
partial void ValidateReplayXHR(string requestId);
///
/// This method sends a new XMLHttpRequest which is identical to the original one. The following
/// parameters should be identical: method, url, async, request body, extra headers, withCredentials
/// attribute, user, password.
///
/// Identifier of XHR to replay.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task ReplayXHRAsync(string requestId)
{
ValidateReplayXHR(requestId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("requestId", requestId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.replayXHR", dict);
return methodResult;
}
partial void ValidateSearchInResponseBody(string requestId, string query, bool? caseSensitive = null, bool? isRegex = null);
///
/// Searches for given string in response content.
///
/// Identifier of the network response to search.
/// String to search for.
/// If true, search is case sensitive.
/// If true, treats string parameter as regex.
/// returns System.Threading.Tasks.Task<SearchInResponseBodyResponse>
public async System.Threading.Tasks.Task SearchInResponseBodyAsync(string requestId, string query, bool? caseSensitive = null, bool? isRegex = null)
{
ValidateSearchInResponseBody(requestId, query, caseSensitive, isRegex);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("requestId", requestId);
dict.Add("query", query);
if (caseSensitive.HasValue)
{
dict.Add("caseSensitive", caseSensitive.Value);
}
if (isRegex.HasValue)
{
dict.Add("isRegex", isRegex.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.searchInResponseBody", dict);
return methodResult.DeserializeJson();
}
partial void ValidateSetBlockedURLs(string[] urls);
///
/// Blocks URLs from loading.
///
/// URL patterns to block. Wildcards ('*') are allowed.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetBlockedURLsAsync(string[] urls)
{
ValidateSetBlockedURLs(urls);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("urls", urls);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setBlockedURLs", dict);
return methodResult;
}
partial void ValidateSetBypassServiceWorker(bool bypass);
///
/// Toggles ignoring of service worker for each request.
///
/// Bypass service worker and load from network.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetBypassServiceWorkerAsync(bool bypass)
{
ValidateSetBypassServiceWorker(bypass);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("bypass", bypass);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setBypassServiceWorker", dict);
return methodResult;
}
partial void ValidateSetCacheDisabled(bool cacheDisabled);
///
/// Toggles ignoring cache for each request. If `true`, cache will not be used.
///
/// Cache disabled state.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetCacheDisabledAsync(bool cacheDisabled)
{
ValidateSetCacheDisabled(cacheDisabled);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("cacheDisabled", cacheDisabled);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setCacheDisabled", dict);
return methodResult;
}
partial void ValidateSetCookie(string name, string value, string url = null, string domain = null, string path = null, bool? secure = null, bool? httpOnly = null, CefSharp.DevTools.Network.CookieSameSite? sameSite = null, long? expires = null, CefSharp.DevTools.Network.CookiePriority? priority = null);
///
/// Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.
///
/// Cookie name.
/// Cookie value.
/// The request-URI to associate with the setting of the cookie. This value can affect thedefault domain and path values of the created cookie.
/// Cookie domain.
/// Cookie path.
/// True if cookie is secure.
/// True if cookie is http-only.
/// Cookie SameSite type.
/// Cookie expiration date, session cookie if not set
/// Cookie Priority type.
/// returns System.Threading.Tasks.Task<SetCookieResponse>
public async System.Threading.Tasks.Task SetCookieAsync(string name, string value, string url = null, string domain = null, string path = null, bool? secure = null, bool? httpOnly = null, CefSharp.DevTools.Network.CookieSameSite? sameSite = null, long? expires = null, CefSharp.DevTools.Network.CookiePriority? priority = null)
{
ValidateSetCookie(name, value, url, domain, path, secure, httpOnly, sameSite, expires, priority);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("name", name);
dict.Add("value", value);
if (!(string.IsNullOrEmpty(url)))
{
dict.Add("url", url);
}
if (!(string.IsNullOrEmpty(domain)))
{
dict.Add("domain", domain);
}
if (!(string.IsNullOrEmpty(path)))
{
dict.Add("path", path);
}
if (secure.HasValue)
{
dict.Add("secure", secure.Value);
}
if (httpOnly.HasValue)
{
dict.Add("httpOnly", httpOnly.Value);
}
if (sameSite.HasValue)
{
dict.Add("sameSite", this.EnumToString(sameSite));
}
if (expires.HasValue)
{
dict.Add("expires", expires.Value);
}
if (priority.HasValue)
{
dict.Add("priority", this.EnumToString(priority));
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setCookie", dict);
return methodResult.DeserializeJson();
}
partial void ValidateSetCookies(System.Collections.Generic.IList cookies);
///
/// Sets given cookies.
///
/// Cookies to be set.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetCookiesAsync(System.Collections.Generic.IList cookies)
{
ValidateSetCookies(cookies);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("cookies", cookies.Select(x => x.ToDictionary()));
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setCookies", dict);
return methodResult;
}
partial void ValidateSetDataSizeLimitsForTest(int maxTotalSize, int maxResourceSize);
///
/// For testing.
///
/// Maximum total buffer size.
/// Maximum per-resource size.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetDataSizeLimitsForTestAsync(int maxTotalSize, int maxResourceSize)
{
ValidateSetDataSizeLimitsForTest(maxTotalSize, maxResourceSize);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("maxTotalSize", maxTotalSize);
dict.Add("maxResourceSize", maxResourceSize);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setDataSizeLimitsForTest", dict);
return methodResult;
}
partial void ValidateSetExtraHTTPHeaders(CefSharp.DevTools.Network.Headers headers);
///
/// Specifies whether to always send extra HTTP headers with the requests from this page.
///
/// Map with extra HTTP headers.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetExtraHTTPHeadersAsync(CefSharp.DevTools.Network.Headers headers)
{
ValidateSetExtraHTTPHeaders(headers);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("headers", headers.ToDictionary());
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setExtraHTTPHeaders", dict);
return methodResult;
}
partial void ValidateSetUserAgentOverride(string userAgent, string acceptLanguage = null, string platform = null, CefSharp.DevTools.Emulation.UserAgentMetadata userAgentMetadata = null);
///
/// Allows overriding user agent with the given string.
///
/// User agent to use.
/// Browser langugage to emulate.
/// The platform navigator.platform should return.
/// To be sent in Sec-CH-UA-* headers and returned in navigator.userAgentData
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetUserAgentOverrideAsync(string userAgent, string acceptLanguage = null, string platform = null, CefSharp.DevTools.Emulation.UserAgentMetadata userAgentMetadata = null)
{
ValidateSetUserAgentOverride(userAgent, acceptLanguage, platform, userAgentMetadata);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("userAgent", userAgent);
if (!(string.IsNullOrEmpty(acceptLanguage)))
{
dict.Add("acceptLanguage", acceptLanguage);
}
if (!(string.IsNullOrEmpty(platform)))
{
dict.Add("platform", platform);
}
if ((userAgentMetadata) != (null))
{
dict.Add("userAgentMetadata", userAgentMetadata.ToDictionary());
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Network.setUserAgentOverride", dict);
return methodResult;
}
}
}