All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.chrome.devtools.client.core.network.Network Maven / Gradle / Ivy

package com.hubspot.chrome.devtools.client.core.network;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.chrome.devtools.base.ChromeRequest;
import com.hubspot.chrome.devtools.base.ChromeSessionCore;
import com.hubspot.chrome.devtools.client.core.debugger.SearchMatch;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * 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 final class Network {
  ChromeSessionCore chromeSession;

  ObjectMapper objectMapper;

  public Network(ChromeSessionCore chromeSession, ObjectMapper objectMapper) {
    this.chromeSession = chromeSession;
    this.objectMapper = objectMapper;
  }

  /**
   * Tells whether clearing browser cache is supported.
   */
  @Deprecated
  public Boolean canClearBrowserCache() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.canClearBrowserCache");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Tells whether clearing browser cache is supported.
   */
  @Deprecated
  public CompletableFuture canClearBrowserCacheAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.canClearBrowserCache");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Tells whether clearing browser cookies is supported.
   */
  @Deprecated
  public Boolean canClearBrowserCookies() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.canClearBrowserCookies");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Tells whether clearing browser cookies is supported.
   */
  @Deprecated
  public CompletableFuture canClearBrowserCookiesAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.canClearBrowserCookies");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Tells whether emulation of network conditions is supported.
   */
  @Deprecated
  public Boolean canEmulateNetworkConditions() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.canEmulateNetworkConditions");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Tells whether emulation of network conditions is supported.
   */
  @Deprecated
  public CompletableFuture canEmulateNetworkConditionsAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.canEmulateNetworkConditions");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Clears browser cache.
   */
  public void clearBrowserCache() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.clearBrowserCache");
    chromeSession.send(chromeRequest);
  }

  /**
   * Clears browser cache.
   */
  public void clearBrowserCacheAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.clearBrowserCache");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Clears browser cookies.
   */
  public void clearBrowserCookies() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.clearBrowserCookies");
    chromeSession.send(chromeRequest);
  }

  /**
   * Clears browser cookies.
   */
  public void clearBrowserCookiesAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.clearBrowserCookies");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Response to Network.requestIntercepted which either modifies the request to continue with any
   * modifications, or blocks it, or completes it with the provided response bytes. If a network
   * fetch occurs as a result which encounters a redirect an additional Network.requestIntercepted
   * event will be sent with the same InterceptionId.
   *
   * @param errorReason [Optional] If set this causes the request to fail with the given reason. Passing `Aborted` for requests
   * marked with `isNavigationRequest` also cancels the navigation. Must not be set in response
   * to an authChallenge.
   * @param rawResponse [Optional] If set the requests completes using with the provided base64 encoded raw response, including
   * HTTP status line and headers etc... Must not be set in response to an authChallenge.
   * @param url [Optional] If set the request url will be modified in a way that's not observable by page. Must not be
   * set in response to an authChallenge.
   * @param method [Optional] If set this allows the request method to be overridden. Must not be set in response to an
   * authChallenge.
   * @param postData [Optional] If set this allows postData to be set. Must not be set in response to an authChallenge.
   * @param headers [Optional] If set this allows the request headers to be changed. Must not be set in response to an
   * authChallenge.
   * @param authChallengeResponse [Optional] Response to a requestIntercepted with an authChallenge. Must not be set otherwise.
   */
  public void continueInterceptedRequest(InterceptionId interceptionId, ErrorReason errorReason,
      String rawResponse, String url, String method, String postData, Headers headers,
      AuthChallengeResponse authChallengeResponse) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.continueInterceptedRequest");
    chromeRequest
        .putParams("interceptionId", interceptionId)
        .putParams("errorReason", errorReason)
        .putParams("rawResponse", rawResponse)
        .putParams("url", url)
        .putParams("method", method)
        .putParams("postData", postData)
        .putParams("headers", headers)
        .putParams("authChallengeResponse", authChallengeResponse);
    chromeSession.send(chromeRequest);
  }

  /**
   * Response to Network.requestIntercepted which either modifies the request to continue with any
   * modifications, or blocks it, or completes it with the provided response bytes. If a network
   * fetch occurs as a result which encounters a redirect an additional Network.requestIntercepted
   * event will be sent with the same InterceptionId.
   *
   * @param errorReason [Optional] If set this causes the request to fail with the given reason. Passing `Aborted` for requests
   * marked with `isNavigationRequest` also cancels the navigation. Must not be set in response
   * to an authChallenge.
   * @param rawResponse [Optional] If set the requests completes using with the provided base64 encoded raw response, including
   * HTTP status line and headers etc... Must not be set in response to an authChallenge.
   * @param url [Optional] If set the request url will be modified in a way that's not observable by page. Must not be
   * set in response to an authChallenge.
   * @param method [Optional] If set this allows the request method to be overridden. Must not be set in response to an
   * authChallenge.
   * @param postData [Optional] If set this allows postData to be set. Must not be set in response to an authChallenge.
   * @param headers [Optional] If set this allows the request headers to be changed. Must not be set in response to an
   * authChallenge.
   * @param authChallengeResponse [Optional] Response to a requestIntercepted with an authChallenge. Must not be set otherwise.
   */
  public void continueInterceptedRequestAsync(InterceptionId interceptionId,
      ErrorReason errorReason, String rawResponse, String url, String method, String postData,
      Headers headers, AuthChallengeResponse authChallengeResponse) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.continueInterceptedRequest");
    chromeRequest
        .putParams("interceptionId", interceptionId)
        .putParams("errorReason", errorReason)
        .putParams("rawResponse", rawResponse)
        .putParams("url", url)
        .putParams("method", method)
        .putParams("postData", postData)
        .putParams("headers", headers)
        .putParams("authChallengeResponse", authChallengeResponse);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Deletes browser cookies with matching name and url or domain/path pair.
   *
   * @param name  Name of the cookies to remove.
   * @param url [Optional] If specified, deletes all the cookies with the given name where domain and path match
   * provided URL.
   * @param domain [Optional] If specified, deletes only cookies with the exact domain.
   * @param path [Optional] If specified, deletes only cookies with the exact path.
   */
  public void deleteCookies(String name, String url, String domain, String path) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.deleteCookies");
    chromeRequest
        .putParams("name", name)
        .putParams("url", url)
        .putParams("domain", domain)
        .putParams("path", path);
    chromeSession.send(chromeRequest);
  }

  /**
   * Deletes browser cookies with matching name and url or domain/path pair.
   *
   * @param name  Name of the cookies to remove.
   * @param url [Optional] If specified, deletes all the cookies with the given name where domain and path match
   * provided URL.
   * @param domain [Optional] If specified, deletes only cookies with the exact domain.
   * @param path [Optional] If specified, deletes only cookies with the exact path.
   */
  public void deleteCookiesAsync(String name, String url, String domain, String path) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.deleteCookies");
    chromeRequest
        .putParams("name", name)
        .putParams("url", url)
        .putParams("domain", domain)
        .putParams("path", path);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Disables network tracking, prevents network events from being sent to the client.
   */
  public void disable() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.disable");
    chromeSession.send(chromeRequest);
  }

  /**
   * Disables network tracking, prevents network events from being sent to the client.
   */
  public void disableAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.disable");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Activates emulation of network conditions.
   *
   * @param offline  True to emulate internet disconnection.
   * @param latency  Minimum latency from request sent to response headers received (ms).
   * @param downloadThroughput  Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
   * @param uploadThroughput  Maximal aggregated upload throughput (bytes/sec).  -1 disables upload throttling.
   * @param connectionType [Optional] Connection type if known.
   */
  public void emulateNetworkConditions(Boolean offline, Number latency, Number downloadThroughput,
      Number uploadThroughput, ConnectionType connectionType) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.emulateNetworkConditions");
    chromeRequest
        .putParams("offline", offline)
        .putParams("latency", latency)
        .putParams("downloadThroughput", downloadThroughput)
        .putParams("uploadThroughput", uploadThroughput)
        .putParams("connectionType", connectionType);
    chromeSession.send(chromeRequest);
  }

  /**
   * Activates emulation of network conditions.
   *
   * @param offline  True to emulate internet disconnection.
   * @param latency  Minimum latency from request sent to response headers received (ms).
   * @param downloadThroughput  Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
   * @param uploadThroughput  Maximal aggregated upload throughput (bytes/sec).  -1 disables upload throttling.
   * @param connectionType [Optional] Connection type if known.
   */
  public void emulateNetworkConditionsAsync(Boolean offline, Number latency,
      Number downloadThroughput, Number uploadThroughput, ConnectionType connectionType) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.emulateNetworkConditions");
    chromeRequest
        .putParams("offline", offline)
        .putParams("latency", latency)
        .putParams("downloadThroughput", downloadThroughput)
        .putParams("uploadThroughput", uploadThroughput)
        .putParams("connectionType", connectionType);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Enables network tracking, network events will now be delivered to the client.
   *
   * @param maxTotalBufferSize [Optional] Buffer size in bytes to use when preserving network payloads (XHRs, etc).
   * @param maxResourceBufferSize [Optional] Per-resource buffer size in bytes to use when preserving network payloads (XHRs, etc).
   * @param maxPostDataSize [Optional] Longest post body size (in bytes) that would be included in requestWillBeSent notification
   */
  public void enable(Integer maxTotalBufferSize, Integer maxResourceBufferSize,
      Integer maxPostDataSize) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.enable");
    chromeRequest
        .putParams("maxTotalBufferSize", maxTotalBufferSize)
        .putParams("maxResourceBufferSize", maxResourceBufferSize)
        .putParams("maxPostDataSize", maxPostDataSize);
    chromeSession.send(chromeRequest);
  }

  /**
   * Enables network tracking, network events will now be delivered to the client.
   *
   * @param maxTotalBufferSize [Optional] Buffer size in bytes to use when preserving network payloads (XHRs, etc).
   * @param maxResourceBufferSize [Optional] Per-resource buffer size in bytes to use when preserving network payloads (XHRs, etc).
   * @param maxPostDataSize [Optional] Longest post body size (in bytes) that would be included in requestWillBeSent notification
   */
  public void enableAsync(Integer maxTotalBufferSize, Integer maxResourceBufferSize,
      Integer maxPostDataSize) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.enable");
    chromeRequest
        .putParams("maxTotalBufferSize", maxTotalBufferSize)
        .putParams("maxResourceBufferSize", maxResourceBufferSize)
        .putParams("maxPostDataSize", maxPostDataSize);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Returns all browser cookies. Depending on the backend support, will return detailed cookie
   * information in the `cookies` field.
   */
  public List getAllCookies() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getAllCookies");
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns all browser cookies. Depending on the backend support, will return detailed cookie
   * information in the `cookies` field.
   */
  public CompletableFuture> getAllCookiesAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getAllCookies");
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns the DER-encoded certificate.
   *
   * @param origin  Origin to get certificate for.
   */
  public List getCertificate(String origin) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getCertificate");
    chromeRequest
        .putParams("origin", origin);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns the DER-encoded certificate.
   *
   * @param origin  Origin to get certificate for.
   */
  public CompletableFuture> getCertificateAsync(String origin) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getCertificate");
    chromeRequest
        .putParams("origin", origin);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns all browser cookies for the current URL. Depending on the backend support, will return
   * detailed cookie information in the `cookies` field.
   *
   * @param urls [Optional] The list of URLs for which applicable cookies will be fetched
   */
  public List getCookies(List urls) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getCookies");
    chromeRequest
        .putParams("urls", urls);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns all browser cookies for the current URL. Depending on the backend support, will return
   * detailed cookie information in the `cookies` field.
   *
   * @param urls [Optional] The list of URLs for which applicable cookies will be fetched
   */
  public CompletableFuture> getCookiesAsync(List urls) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getCookies");
    chromeRequest
        .putParams("urls", urls);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns content served for the given request.
   *
   * @param requestId  Identifier of the network request to get content for.
   */
  public GetResponseBodyResult getResponseBody(RequestId requestId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getResponseBody");
    chromeRequest
        .putParams("requestId", requestId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns content served for the given request.
   *
   * @param requestId  Identifier of the network request to get content for.
   */
  public CompletableFuture getResponseBodyAsync(RequestId requestId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getResponseBody");
    chromeRequest
        .putParams("requestId", requestId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns post data sent with the request. Returns an error when no data was sent with the request.
   *
   * @param requestId  Identifier of the network request to get content for.
   */
  public String getRequestPostData(RequestId requestId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getRequestPostData");
    chromeRequest
        .putParams("requestId", requestId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns post data sent with the request. Returns an error when no data was sent with the request.
   *
   * @param requestId  Identifier of the network request to get content for.
   */
  public CompletableFuture getRequestPostDataAsync(RequestId requestId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getRequestPostData");
    chromeRequest
        .putParams("requestId", requestId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns content served for the given currently intercepted request.
   *
   * @param interceptionId  Identifier for the intercepted request to get body for.
   */
  public GetResponseBodyForInterceptionResult getResponseBodyForInterception(
      InterceptionId interceptionId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getResponseBodyForInterception");
    chromeRequest
        .putParams("interceptionId", interceptionId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns content served for the given currently intercepted request.
   *
   * @param interceptionId  Identifier for the intercepted request to get body for.
   */
  public CompletableFuture getResponseBodyForInterceptionAsync(
      InterceptionId interceptionId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.getResponseBodyForInterception");
    chromeRequest
        .putParams("interceptionId", interceptionId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * 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.
   *
   * @param requestId  Identifier of XHR to replay.
   */
  public void replayXHR(RequestId requestId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.replayXHR");
    chromeRequest
        .putParams("requestId", requestId);
    chromeSession.send(chromeRequest);
  }

  /**
   * 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.
   *
   * @param requestId  Identifier of XHR to replay.
   */
  public void replayXHRAsync(RequestId requestId) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.replayXHR");
    chromeRequest
        .putParams("requestId", requestId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Searches for given string in response content.
   *
   * @param requestId  Identifier of the network response to search.
   * @param query  String to search for.
   * @param caseSensitive [Optional] If true, search is case sensitive.
   * @param isRegex [Optional] If true, treats string parameter as regex.
   */
  public List searchInResponseBody(RequestId requestId, String query,
      Boolean caseSensitive, Boolean isRegex) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.searchInResponseBody");
    chromeRequest
        .putParams("requestId", requestId)
        .putParams("query", query)
        .putParams("caseSensitive", caseSensitive)
        .putParams("isRegex", isRegex);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Searches for given string in response content.
   *
   * @param requestId  Identifier of the network response to search.
   * @param query  String to search for.
   * @param caseSensitive [Optional] If true, search is case sensitive.
   * @param isRegex [Optional] If true, treats string parameter as regex.
   */
  public CompletableFuture> searchInResponseBodyAsync(RequestId requestId,
      String query, Boolean caseSensitive, Boolean isRegex) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.searchInResponseBody");
    chromeRequest
        .putParams("requestId", requestId)
        .putParams("query", query)
        .putParams("caseSensitive", caseSensitive)
        .putParams("isRegex", isRegex);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Blocks URLs from loading.
   *
   * @param urls  URL patterns to block. Wildcards ('*') are allowed.
   */
  public void setBlockedURLs(List urls) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setBlockedURLs");
    chromeRequest
        .putParams("urls", urls);
    chromeSession.send(chromeRequest);
  }

  /**
   * Blocks URLs from loading.
   *
   * @param urls  URL patterns to block. Wildcards ('*') are allowed.
   */
  public void setBlockedURLsAsync(List urls) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setBlockedURLs");
    chromeRequest
        .putParams("urls", urls);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Toggles ignoring of service worker for each request.
   *
   * @param bypass  Bypass service worker and load from network.
   */
  public void setBypassServiceWorker(Boolean bypass) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setBypassServiceWorker");
    chromeRequest
        .putParams("bypass", bypass);
    chromeSession.send(chromeRequest);
  }

  /**
   * Toggles ignoring of service worker for each request.
   *
   * @param bypass  Bypass service worker and load from network.
   */
  public void setBypassServiceWorkerAsync(Boolean bypass) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setBypassServiceWorker");
    chromeRequest
        .putParams("bypass", bypass);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Toggles ignoring cache for each request. If `true`, cache will not be used.
   *
   * @param cacheDisabled  Cache disabled state.
   */
  public void setCacheDisabled(Boolean cacheDisabled) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setCacheDisabled");
    chromeRequest
        .putParams("cacheDisabled", cacheDisabled);
    chromeSession.send(chromeRequest);
  }

  /**
   * Toggles ignoring cache for each request. If `true`, cache will not be used.
   *
   * @param cacheDisabled  Cache disabled state.
   */
  public void setCacheDisabledAsync(Boolean cacheDisabled) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setCacheDisabled");
    chromeRequest
        .putParams("cacheDisabled", cacheDisabled);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.
   *
   * @param name  Cookie name.
   * @param value  Cookie value.
   * @param url [Optional] The request-URI to associate with the setting of the cookie. This value can affect the
   * default domain and path values of the created cookie.
   * @param domain [Optional] Cookie domain.
   * @param path [Optional] Cookie path.
   * @param secure [Optional] True if cookie is secure.
   * @param httpOnly [Optional] True if cookie is http-only.
   * @param sameSite [Optional] Cookie SameSite type.
   * @param expires [Optional] Cookie expiration date, session cookie if not set
   */
  public Boolean setCookie(String name, String value, String url, String domain, String path,
      Boolean secure, Boolean httpOnly, CookieSameSite sameSite, TimeSinceEpoch expires) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setCookie");
    chromeRequest
        .putParams("name", name)
        .putParams("value", value)
        .putParams("url", url)
        .putParams("domain", domain)
        .putParams("path", path)
        .putParams("secure", secure)
        .putParams("httpOnly", httpOnly)
        .putParams("sameSite", sameSite)
        .putParams("expires", expires);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.
   *
   * @param name  Cookie name.
   * @param value  Cookie value.
   * @param url [Optional] The request-URI to associate with the setting of the cookie. This value can affect the
   * default domain and path values of the created cookie.
   * @param domain [Optional] Cookie domain.
   * @param path [Optional] Cookie path.
   * @param secure [Optional] True if cookie is secure.
   * @param httpOnly [Optional] True if cookie is http-only.
   * @param sameSite [Optional] Cookie SameSite type.
   * @param expires [Optional] Cookie expiration date, session cookie if not set
   */
  public CompletableFuture setCookieAsync(String name, String value, String url,
      String domain, String path, Boolean secure, Boolean httpOnly, CookieSameSite sameSite,
      TimeSinceEpoch expires) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setCookie");
    chromeRequest
        .putParams("name", name)
        .putParams("value", value)
        .putParams("url", url)
        .putParams("domain", domain)
        .putParams("path", path)
        .putParams("secure", secure)
        .putParams("httpOnly", httpOnly)
        .putParams("sameSite", sameSite)
        .putParams("expires", expires);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Sets given cookies.
   *
   * @param cookies  Cookies to be set.
   */
  public void setCookies(List cookies) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setCookies");
    chromeRequest
        .putParams("cookies", cookies);
    chromeSession.send(chromeRequest);
  }

  /**
   * Sets given cookies.
   *
   * @param cookies  Cookies to be set.
   */
  public void setCookiesAsync(List cookies) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setCookies");
    chromeRequest
        .putParams("cookies", cookies);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * For testing.
   *
   * @param maxTotalSize  Maximum total buffer size.
   * @param maxResourceSize  Maximum per-resource size.
   */
  public void setDataSizeLimitsForTest(Integer maxTotalSize, Integer maxResourceSize) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setDataSizeLimitsForTest");
    chromeRequest
        .putParams("maxTotalSize", maxTotalSize)
        .putParams("maxResourceSize", maxResourceSize);
    chromeSession.send(chromeRequest);
  }

  /**
   * For testing.
   *
   * @param maxTotalSize  Maximum total buffer size.
   * @param maxResourceSize  Maximum per-resource size.
   */
  public void setDataSizeLimitsForTestAsync(Integer maxTotalSize, Integer maxResourceSize) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setDataSizeLimitsForTest");
    chromeRequest
        .putParams("maxTotalSize", maxTotalSize)
        .putParams("maxResourceSize", maxResourceSize);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Specifies whether to always send extra HTTP headers with the requests from this page.
   *
   * @param headers  Map with extra HTTP headers.
   */
  public void setExtraHTTPHeaders(Headers headers) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setExtraHTTPHeaders");
    chromeRequest
        .putParams("headers", headers);
    chromeSession.send(chromeRequest);
  }

  /**
   * Specifies whether to always send extra HTTP headers with the requests from this page.
   *
   * @param headers  Map with extra HTTP headers.
   */
  public void setExtraHTTPHeadersAsync(Headers headers) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setExtraHTTPHeaders");
    chromeRequest
        .putParams("headers", headers);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Sets the requests to intercept that match a the provided patterns and optionally resource types.
   *
   * @param patterns  Requests matching any of these patterns will be forwarded and wait for the corresponding
   * continueInterceptedRequest call.
   */
  public void setRequestInterception(List patterns) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setRequestInterception");
    chromeRequest
        .putParams("patterns", patterns);
    chromeSession.send(chromeRequest);
  }

  /**
   * Sets the requests to intercept that match a the provided patterns and optionally resource types.
   *
   * @param patterns  Requests matching any of these patterns will be forwarded and wait for the corresponding
   * continueInterceptedRequest call.
   */
  public void setRequestInterceptionAsync(List patterns) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setRequestInterception");
    chromeRequest
        .putParams("patterns", patterns);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Allows overriding user agent with the given string.
   *
   * @param userAgent  User agent to use.
   */
  public void setUserAgentOverride(String userAgent) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setUserAgentOverride");
    chromeRequest
        .putParams("userAgent", userAgent);
    chromeSession.send(chromeRequest);
  }

  /**
   * Allows overriding user agent with the given string.
   *
   * @param userAgent  User agent to use.
   */
  public void setUserAgentOverrideAsync(String userAgent) {
    ChromeRequest chromeRequest = new ChromeRequest("Network.setUserAgentOverride");
    chromeRequest
        .putParams("userAgent", userAgent);
    chromeSession.sendAsync(chromeRequest);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy