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

com.hubspot.chrome.devtools.client.core.page.Page Maven / Gradle / Ivy

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

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 com.hubspot.chrome.devtools.client.core.emulation.ScreenOrientation;
import com.hubspot.chrome.devtools.client.core.network.Cookie;
import com.hubspot.chrome.devtools.client.core.runtime.ExecutionContextId;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * Actions and events related to the inspected page belong to the page domain.
 */
public final class Page {
  ChromeSessionCore chromeSession;

  ObjectMapper objectMapper;

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

  /**
   * Deprecated, please use addScriptToEvaluateOnNewDocument instead.
   */
  @Deprecated
  public ScriptIdentifier addScriptToEvaluateOnLoad(String scriptSource) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.addScriptToEvaluateOnLoad");
    chromeRequest
        .putParams("scriptSource", scriptSource);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Deprecated, please use addScriptToEvaluateOnNewDocument instead.
   */
  @Deprecated
  public CompletableFuture addScriptToEvaluateOnLoadAsync(String scriptSource) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.addScriptToEvaluateOnLoad");
    chromeRequest
        .putParams("scriptSource", scriptSource);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Evaluates given script in every frame upon creation (before loading frame's scripts).
   */
  public ScriptIdentifier addScriptToEvaluateOnNewDocument(String source) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.addScriptToEvaluateOnNewDocument");
    chromeRequest
        .putParams("source", source);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Evaluates given script in every frame upon creation (before loading frame's scripts).
   */
  public CompletableFuture addScriptToEvaluateOnNewDocumentAsync(String source) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.addScriptToEvaluateOnNewDocument");
    chromeRequest
        .putParams("source", source);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Brings page to front (activates tab).
   */
  public void bringToFront() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.bringToFront");
    chromeSession.send(chromeRequest);
  }

  /**
   * Brings page to front (activates tab).
   */
  public void bringToFrontAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.bringToFront");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Capture page screenshot.
   *
   * @param format [Optional] Image compression format (defaults to png).
   * @param quality [Optional] Compression quality from range [0..100] (jpeg only).
   * @param clip [Optional] Capture the screenshot of a given region only.
   * @param fromSurface [Optional] Capture the screenshot from the surface, rather than the view. Defaults to true.
   */
  public String captureScreenshot(String format, Integer quality, Viewport clip,
      Boolean fromSurface) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.captureScreenshot");
    chromeRequest
        .putParams("format", format)
        .putParams("quality", quality)
        .putParams("clip", clip)
        .putParams("fromSurface", fromSurface);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Capture page screenshot.
   *
   * @param format [Optional] Image compression format (defaults to png).
   * @param quality [Optional] Compression quality from range [0..100] (jpeg only).
   * @param clip [Optional] Capture the screenshot of a given region only.
   * @param fromSurface [Optional] Capture the screenshot from the surface, rather than the view. Defaults to true.
   */
  public CompletableFuture captureScreenshotAsync(String format, Integer quality,
      Viewport clip, Boolean fromSurface) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.captureScreenshot");
    chromeRequest
        .putParams("format", format)
        .putParams("quality", quality)
        .putParams("clip", clip)
        .putParams("fromSurface", fromSurface);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Clears the overriden device metrics.
   */
  @Deprecated
  public void clearDeviceMetricsOverride() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.clearDeviceMetricsOverride");
    chromeSession.send(chromeRequest);
  }

  /**
   * Clears the overriden device metrics.
   */
  @Deprecated
  public void clearDeviceMetricsOverrideAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.clearDeviceMetricsOverride");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Clears the overridden Device Orientation.
   */
  @Deprecated
  public void clearDeviceOrientationOverride() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.clearDeviceOrientationOverride");
    chromeSession.send(chromeRequest);
  }

  /**
   * Clears the overridden Device Orientation.
   */
  @Deprecated
  public void clearDeviceOrientationOverrideAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.clearDeviceOrientationOverride");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Clears the overriden Geolocation Position and Error.
   */
  @Deprecated
  public void clearGeolocationOverride() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.clearGeolocationOverride");
    chromeSession.send(chromeRequest);
  }

  /**
   * Clears the overriden Geolocation Position and Error.
   */
  @Deprecated
  public void clearGeolocationOverrideAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.clearGeolocationOverride");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Creates an isolated world for the given frame.
   *
   * @param frameId  Id of the frame in which the isolated world should be created.
   * @param worldName [Optional] An optional name which is reported in the Execution Context.
   * @param grantUniveralAccess [Optional] Whether or not universal access should be granted to the isolated world. This is a powerful
   * option, use with caution.
   */
  public ExecutionContextId createIsolatedWorld(FrameId frameId, String worldName,
      Boolean grantUniveralAccess) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.createIsolatedWorld");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("worldName", worldName)
        .putParams("grantUniveralAccess", grantUniveralAccess);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Creates an isolated world for the given frame.
   *
   * @param frameId  Id of the frame in which the isolated world should be created.
   * @param worldName [Optional] An optional name which is reported in the Execution Context.
   * @param grantUniveralAccess [Optional] Whether or not universal access should be granted to the isolated world. This is a powerful
   * option, use with caution.
   */
  public CompletableFuture createIsolatedWorldAsync(FrameId frameId,
      String worldName, Boolean grantUniveralAccess) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.createIsolatedWorld");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("worldName", worldName)
        .putParams("grantUniveralAccess", grantUniveralAccess);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Deletes browser cookie with given name, domain and path.
   *
   * @param cookieName  Name of the cookie to remove.
   * @param url  URL to match cooke domain and path.
   */
  @Deprecated
  public void deleteCookie(String cookieName, String url) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.deleteCookie");
    chromeRequest
        .putParams("cookieName", cookieName)
        .putParams("url", url);
    chromeSession.send(chromeRequest);
  }

  /**
   * Deletes browser cookie with given name, domain and path.
   *
   * @param cookieName  Name of the cookie to remove.
   * @param url  URL to match cooke domain and path.
   */
  @Deprecated
  public void deleteCookieAsync(String cookieName, String url) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.deleteCookie");
    chromeRequest
        .putParams("cookieName", cookieName)
        .putParams("url", url);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Disables page domain notifications.
   */
  public void disable() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.disable");
    chromeSession.send(chromeRequest);
  }

  /**
   * Disables page domain notifications.
   */
  public void disableAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.disable");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Enables page domain notifications.
   */
  public void enable() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.enable");
    chromeSession.send(chromeRequest);
  }

  /**
   * Enables page domain notifications.
   */
  public void enableAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.enable");
    chromeSession.sendAsync(chromeRequest);
  }

  public GetAppManifestResult getAppManifest() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getAppManifest");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  public CompletableFuture getAppManifestAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getAppManifest");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

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

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

  /**
   * Returns present frame tree structure.
   */
  public FrameTree getFrameTree() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getFrameTree");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns present frame tree structure.
   */
  public CompletableFuture getFrameTreeAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getFrameTree");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns metrics relating to the layouting of the page, such as viewport bounds/scale.
   */
  public GetLayoutMetricsResult getLayoutMetrics() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getLayoutMetrics");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns metrics relating to the layouting of the page, such as viewport bounds/scale.
   */
  public CompletableFuture getLayoutMetricsAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getLayoutMetrics");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns navigation history for the current page.
   */
  public GetNavigationHistoryResult getNavigationHistory() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getNavigationHistory");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns navigation history for the current page.
   */
  public CompletableFuture getNavigationHistoryAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getNavigationHistory");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns content of the given resource.
   *
   * @param frameId  Frame id to get resource for.
   * @param url  URL of the resource to get content for.
   */
  public GetResourceContentResult getResourceContent(FrameId frameId, String url) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getResourceContent");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("url", url);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns content of the given resource.
   *
   * @param frameId  Frame id to get resource for.
   * @param url  URL of the resource to get content for.
   */
  public CompletableFuture getResourceContentAsync(FrameId frameId,
      String url) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getResourceContent");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("url", url);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns present frame / resource tree structure.
   */
  public FrameResourceTree getResourceTree() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getResourceTree");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns present frame / resource tree structure.
   */
  public CompletableFuture getResourceTreeAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.getResourceTree");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).
   *
   * @param accept  Whether to accept or dismiss the dialog.
   * @param promptText [Optional] The text to enter into the dialog prompt before accepting. Used only if this is a prompt
   * dialog.
   */
  public void handleJavaScriptDialog(Boolean accept, String promptText) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.handleJavaScriptDialog");
    chromeRequest
        .putParams("accept", accept)
        .putParams("promptText", promptText);
    chromeSession.send(chromeRequest);
  }

  /**
   * Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).
   *
   * @param accept  Whether to accept or dismiss the dialog.
   * @param promptText [Optional] The text to enter into the dialog prompt before accepting. Used only if this is a prompt
   * dialog.
   */
  public void handleJavaScriptDialogAsync(Boolean accept, String promptText) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.handleJavaScriptDialog");
    chromeRequest
        .putParams("accept", accept)
        .putParams("promptText", promptText);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Navigates current page to the given URL.
   *
   * @param url  URL to navigate the page to.
   * @param referrer [Optional] Referrer URL.
   * @param transitionType [Optional] Intended transition type.
   * @param frameId [Optional] Frame id to navigate, if not specified navigates the top frame.
   */
  public NavigateResult navigate(String url, String referrer, TransitionType transitionType,
      FrameId frameId) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.navigate");
    chromeRequest
        .putParams("url", url)
        .putParams("referrer", referrer)
        .putParams("transitionType", transitionType)
        .putParams("frameId", frameId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Navigates current page to the given URL.
   *
   * @param url  URL to navigate the page to.
   * @param referrer [Optional] Referrer URL.
   * @param transitionType [Optional] Intended transition type.
   * @param frameId [Optional] Frame id to navigate, if not specified navigates the top frame.
   */
  public CompletableFuture navigateAsync(String url, String referrer,
      TransitionType transitionType, FrameId frameId) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.navigate");
    chromeRequest
        .putParams("url", url)
        .putParams("referrer", referrer)
        .putParams("transitionType", transitionType)
        .putParams("frameId", frameId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Navigates current page to the given history entry.
   *
   * @param entryId  Unique id of the entry to navigate to.
   */
  public void navigateToHistoryEntry(Integer entryId) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.navigateToHistoryEntry");
    chromeRequest
        .putParams("entryId", entryId);
    chromeSession.send(chromeRequest);
  }

  /**
   * Navigates current page to the given history entry.
   *
   * @param entryId  Unique id of the entry to navigate to.
   */
  public void navigateToHistoryEntryAsync(Integer entryId) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.navigateToHistoryEntry");
    chromeRequest
        .putParams("entryId", entryId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Print page as PDF.
   *
   * @param landscape [Optional] Paper orientation. Defaults to false.
   * @param displayHeaderFooter [Optional] Display header and footer. Defaults to false.
   * @param printBackground [Optional] Print background graphics. Defaults to false.
   * @param scale [Optional] Scale of the webpage rendering. Defaults to 1.
   * @param paperWidth [Optional] Paper width in inches. Defaults to 8.5 inches.
   * @param paperHeight [Optional] Paper height in inches. Defaults to 11 inches.
   * @param marginTop [Optional] Top margin in inches. Defaults to 1cm (~0.4 inches).
   * @param marginBottom [Optional] Bottom margin in inches. Defaults to 1cm (~0.4 inches).
   * @param marginLeft [Optional] Left margin in inches. Defaults to 1cm (~0.4 inches).
   * @param marginRight [Optional] Right margin in inches. Defaults to 1cm (~0.4 inches).
   * @param pageRanges [Optional] Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means
   * print all pages.
   * @param ignoreInvalidPageRanges [Optional] Whether to silently ignore invalid but successfully parsed page ranges, such as '3-2'.
   * Defaults to false.
   * @param headerTemplate [Optional] HTML template for the print header. Should be valid HTML markup with following
   * classes used to inject printing values into them:
   * - date - formatted print date
   * - title - document title
   * - url - document location
   * - pageNumber - current page number
   * - totalPages - total pages in the document
   *
   * For example,  would generate span containing the title.
   * @param footerTemplate [Optional] HTML template for the print footer. Should use the same format as the `headerTemplate`.
   * @param preferCSSPageSize [Optional] Whether or not to prefer page size as defined by css. Defaults to false,
   * in which case the content will be scaled to fit the paper size.
   */
  public String printToPDF(Boolean landscape, Boolean displayHeaderFooter, Boolean printBackground,
      Number scale, Number paperWidth, Number paperHeight, Number marginTop, Number marginBottom,
      Number marginLeft, Number marginRight, String pageRanges, Boolean ignoreInvalidPageRanges,
      String headerTemplate, String footerTemplate, Boolean preferCSSPageSize) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.printToPDF");
    chromeRequest
        .putParams("landscape", landscape)
        .putParams("displayHeaderFooter", displayHeaderFooter)
        .putParams("printBackground", printBackground)
        .putParams("scale", scale)
        .putParams("paperWidth", paperWidth)
        .putParams("paperHeight", paperHeight)
        .putParams("marginTop", marginTop)
        .putParams("marginBottom", marginBottom)
        .putParams("marginLeft", marginLeft)
        .putParams("marginRight", marginRight)
        .putParams("pageRanges", pageRanges)
        .putParams("ignoreInvalidPageRanges", ignoreInvalidPageRanges)
        .putParams("headerTemplate", headerTemplate)
        .putParams("footerTemplate", footerTemplate)
        .putParams("preferCSSPageSize", preferCSSPageSize);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Print page as PDF.
   *
   * @param landscape [Optional] Paper orientation. Defaults to false.
   * @param displayHeaderFooter [Optional] Display header and footer. Defaults to false.
   * @param printBackground [Optional] Print background graphics. Defaults to false.
   * @param scale [Optional] Scale of the webpage rendering. Defaults to 1.
   * @param paperWidth [Optional] Paper width in inches. Defaults to 8.5 inches.
   * @param paperHeight [Optional] Paper height in inches. Defaults to 11 inches.
   * @param marginTop [Optional] Top margin in inches. Defaults to 1cm (~0.4 inches).
   * @param marginBottom [Optional] Bottom margin in inches. Defaults to 1cm (~0.4 inches).
   * @param marginLeft [Optional] Left margin in inches. Defaults to 1cm (~0.4 inches).
   * @param marginRight [Optional] Right margin in inches. Defaults to 1cm (~0.4 inches).
   * @param pageRanges [Optional] Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means
   * print all pages.
   * @param ignoreInvalidPageRanges [Optional] Whether to silently ignore invalid but successfully parsed page ranges, such as '3-2'.
   * Defaults to false.
   * @param headerTemplate [Optional] HTML template for the print header. Should be valid HTML markup with following
   * classes used to inject printing values into them:
   * - date - formatted print date
   * - title - document title
   * - url - document location
   * - pageNumber - current page number
   * - totalPages - total pages in the document
   *
   * For example,  would generate span containing the title.
   * @param footerTemplate [Optional] HTML template for the print footer. Should use the same format as the `headerTemplate`.
   * @param preferCSSPageSize [Optional] Whether or not to prefer page size as defined by css. Defaults to false,
   * in which case the content will be scaled to fit the paper size.
   */
  public CompletableFuture printToPDFAsync(Boolean landscape, Boolean displayHeaderFooter,
      Boolean printBackground, Number scale, Number paperWidth, Number paperHeight,
      Number marginTop, Number marginBottom, Number marginLeft, Number marginRight,
      String pageRanges, Boolean ignoreInvalidPageRanges, String headerTemplate,
      String footerTemplate, Boolean preferCSSPageSize) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.printToPDF");
    chromeRequest
        .putParams("landscape", landscape)
        .putParams("displayHeaderFooter", displayHeaderFooter)
        .putParams("printBackground", printBackground)
        .putParams("scale", scale)
        .putParams("paperWidth", paperWidth)
        .putParams("paperHeight", paperHeight)
        .putParams("marginTop", marginTop)
        .putParams("marginBottom", marginBottom)
        .putParams("marginLeft", marginLeft)
        .putParams("marginRight", marginRight)
        .putParams("pageRanges", pageRanges)
        .putParams("ignoreInvalidPageRanges", ignoreInvalidPageRanges)
        .putParams("headerTemplate", headerTemplate)
        .putParams("footerTemplate", footerTemplate)
        .putParams("preferCSSPageSize", preferCSSPageSize);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Reloads given page optionally ignoring the cache.
   *
   * @param ignoreCache [Optional] If true, browser cache is ignored (as if the user pressed Shift+refresh).
   * @param scriptToEvaluateOnLoad [Optional] If set, the script will be injected into all frames of the inspected page after reload.
   * Argument will be ignored if reloading dataURL origin.
   */
  public void reload(Boolean ignoreCache, String scriptToEvaluateOnLoad) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.reload");
    chromeRequest
        .putParams("ignoreCache", ignoreCache)
        .putParams("scriptToEvaluateOnLoad", scriptToEvaluateOnLoad);
    chromeSession.send(chromeRequest);
  }

  /**
   * Reloads given page optionally ignoring the cache.
   *
   * @param ignoreCache [Optional] If true, browser cache is ignored (as if the user pressed Shift+refresh).
   * @param scriptToEvaluateOnLoad [Optional] If set, the script will be injected into all frames of the inspected page after reload.
   * Argument will be ignored if reloading dataURL origin.
   */
  public void reloadAsync(Boolean ignoreCache, String scriptToEvaluateOnLoad) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.reload");
    chromeRequest
        .putParams("ignoreCache", ignoreCache)
        .putParams("scriptToEvaluateOnLoad", scriptToEvaluateOnLoad);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Deprecated, please use removeScriptToEvaluateOnNewDocument instead.
   */
  @Deprecated
  public void removeScriptToEvaluateOnLoad(ScriptIdentifier identifier) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.removeScriptToEvaluateOnLoad");
    chromeRequest
        .putParams("identifier", identifier);
    chromeSession.send(chromeRequest);
  }

  /**
   * Deprecated, please use removeScriptToEvaluateOnNewDocument instead.
   */
  @Deprecated
  public void removeScriptToEvaluateOnLoadAsync(ScriptIdentifier identifier) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.removeScriptToEvaluateOnLoad");
    chromeRequest
        .putParams("identifier", identifier);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Removes given script from the list.
   */
  public void removeScriptToEvaluateOnNewDocument(ScriptIdentifier identifier) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.removeScriptToEvaluateOnNewDocument");
    chromeRequest
        .putParams("identifier", identifier);
    chromeSession.send(chromeRequest);
  }

  /**
   * Removes given script from the list.
   */
  public void removeScriptToEvaluateOnNewDocumentAsync(ScriptIdentifier identifier) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.removeScriptToEvaluateOnNewDocument");
    chromeRequest
        .putParams("identifier", identifier);
    chromeSession.sendAsync(chromeRequest);
  }

  public void requestAppBanner() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.requestAppBanner");
    chromeSession.send(chromeRequest);
  }

  public void requestAppBannerAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.requestAppBanner");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Acknowledges that a screencast frame has been received by the frontend.
   *
   * @param sessionId  Frame number.
   */
  public void screencastFrameAck(Integer sessionId) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.screencastFrameAck");
    chromeRequest
        .putParams("sessionId", sessionId);
    chromeSession.send(chromeRequest);
  }

  /**
   * Acknowledges that a screencast frame has been received by the frontend.
   *
   * @param sessionId  Frame number.
   */
  public void screencastFrameAckAsync(Integer sessionId) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.screencastFrameAck");
    chromeRequest
        .putParams("sessionId", sessionId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Searches for given string in resource content.
   *
   * @param frameId  Frame id for resource to search in.
   * @param url  URL of the resource to search in.
   * @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 searchInResource(FrameId frameId, String url, String query,
      Boolean caseSensitive, Boolean isRegex) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.searchInResource");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("url", url)
        .putParams("query", query)
        .putParams("caseSensitive", caseSensitive)
        .putParams("isRegex", isRegex);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Searches for given string in resource content.
   *
   * @param frameId  Frame id for resource to search in.
   * @param url  URL of the resource to search in.
   * @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> searchInResourceAsync(FrameId frameId, String url,
      String query, Boolean caseSensitive, Boolean isRegex) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.searchInResource");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("url", url)
        .putParams("query", query)
        .putParams("caseSensitive", caseSensitive)
        .putParams("isRegex", isRegex);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Enable Chrome's experimental ad filter on all sites.
   *
   * @param enabled  Whether to block ads.
   */
  public void setAdBlockingEnabled(Boolean enabled) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setAdBlockingEnabled");
    chromeRequest
        .putParams("enabled", enabled);
    chromeSession.send(chromeRequest);
  }

  /**
   * Enable Chrome's experimental ad filter on all sites.
   *
   * @param enabled  Whether to block ads.
   */
  public void setAdBlockingEnabledAsync(Boolean enabled) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setAdBlockingEnabled");
    chromeRequest
        .putParams("enabled", enabled);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Overrides the values of device screen dimensions (window.screen.width, window.screen.height,
   * window.innerWidth, window.innerHeight, and "device-width"/"device-height"-related CSS media
   * query results).
   *
   * @param width  Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
   * @param height  Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
   * @param deviceScaleFactor  Overriding device scale factor value. 0 disables the override.
   * @param mobile  Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text
   * autosizing and more.
   * @param scale [Optional] Scale to apply to resulting view image.
   * @param screenWidth [Optional] Overriding screen width value in pixels (minimum 0, maximum 10000000).
   * @param screenHeight [Optional] Overriding screen height value in pixels (minimum 0, maximum 10000000).
   * @param positionX [Optional] Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
   * @param positionY [Optional] Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
   * @param dontSetVisibleSize [Optional] Do not set visible view size, rely upon explicit setVisibleSize call.
   * @param screenOrientation [Optional] Screen orientation override.
   * @param viewport [Optional] The viewport dimensions and scale. If not set, the override is cleared.
   */
  @Deprecated
  public void setDeviceMetricsOverride(Integer width, Integer height, Number deviceScaleFactor,
      Boolean mobile, Number scale, Integer screenWidth, Integer screenHeight, Integer positionX,
      Integer positionY, Boolean dontSetVisibleSize, ScreenOrientation screenOrientation,
      Viewport viewport) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDeviceMetricsOverride");
    chromeRequest
        .putParams("width", width)
        .putParams("height", height)
        .putParams("deviceScaleFactor", deviceScaleFactor)
        .putParams("mobile", mobile)
        .putParams("scale", scale)
        .putParams("screenWidth", screenWidth)
        .putParams("screenHeight", screenHeight)
        .putParams("positionX", positionX)
        .putParams("positionY", positionY)
        .putParams("dontSetVisibleSize", dontSetVisibleSize)
        .putParams("screenOrientation", screenOrientation)
        .putParams("viewport", viewport);
    chromeSession.send(chromeRequest);
  }

  /**
   * Overrides the values of device screen dimensions (window.screen.width, window.screen.height,
   * window.innerWidth, window.innerHeight, and "device-width"/"device-height"-related CSS media
   * query results).
   *
   * @param width  Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
   * @param height  Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
   * @param deviceScaleFactor  Overriding device scale factor value. 0 disables the override.
   * @param mobile  Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text
   * autosizing and more.
   * @param scale [Optional] Scale to apply to resulting view image.
   * @param screenWidth [Optional] Overriding screen width value in pixels (minimum 0, maximum 10000000).
   * @param screenHeight [Optional] Overriding screen height value in pixels (minimum 0, maximum 10000000).
   * @param positionX [Optional] Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
   * @param positionY [Optional] Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
   * @param dontSetVisibleSize [Optional] Do not set visible view size, rely upon explicit setVisibleSize call.
   * @param screenOrientation [Optional] Screen orientation override.
   * @param viewport [Optional] The viewport dimensions and scale. If not set, the override is cleared.
   */
  @Deprecated
  public void setDeviceMetricsOverrideAsync(Integer width, Integer height, Number deviceScaleFactor,
      Boolean mobile, Number scale, Integer screenWidth, Integer screenHeight, Integer positionX,
      Integer positionY, Boolean dontSetVisibleSize, ScreenOrientation screenOrientation,
      Viewport viewport) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDeviceMetricsOverride");
    chromeRequest
        .putParams("width", width)
        .putParams("height", height)
        .putParams("deviceScaleFactor", deviceScaleFactor)
        .putParams("mobile", mobile)
        .putParams("scale", scale)
        .putParams("screenWidth", screenWidth)
        .putParams("screenHeight", screenHeight)
        .putParams("positionX", positionX)
        .putParams("positionY", positionY)
        .putParams("dontSetVisibleSize", dontSetVisibleSize)
        .putParams("screenOrientation", screenOrientation)
        .putParams("viewport", viewport);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Overrides the Device Orientation.
   *
   * @param alpha  Mock alpha
   * @param beta  Mock beta
   * @param gamma  Mock gamma
   */
  @Deprecated
  public void setDeviceOrientationOverride(Number alpha, Number beta, Number gamma) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDeviceOrientationOverride");
    chromeRequest
        .putParams("alpha", alpha)
        .putParams("beta", beta)
        .putParams("gamma", gamma);
    chromeSession.send(chromeRequest);
  }

  /**
   * Overrides the Device Orientation.
   *
   * @param alpha  Mock alpha
   * @param beta  Mock beta
   * @param gamma  Mock gamma
   */
  @Deprecated
  public void setDeviceOrientationOverrideAsync(Number alpha, Number beta, Number gamma) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDeviceOrientationOverride");
    chromeRequest
        .putParams("alpha", alpha)
        .putParams("beta", beta)
        .putParams("gamma", gamma);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Sets given markup as the document's HTML.
   *
   * @param frameId  Frame id to set HTML for.
   * @param html  HTML content to set.
   */
  public void setDocumentContent(FrameId frameId, String html) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDocumentContent");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("html", html);
    chromeSession.send(chromeRequest);
  }

  /**
   * Sets given markup as the document's HTML.
   *
   * @param frameId  Frame id to set HTML for.
   * @param html  HTML content to set.
   */
  public void setDocumentContentAsync(FrameId frameId, String html) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDocumentContent");
    chromeRequest
        .putParams("frameId", frameId)
        .putParams("html", html);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Set the behavior when downloading a file.
   *
   * @param behavior  Whether to allow all or deny all download requests, or use default Chrome behavior if
   * available (otherwise deny).
   * @param downloadPath [Optional] The default path to save downloaded files to. This is requred if behavior is set to 'allow'
   */
  public void setDownloadBehavior(String behavior, String downloadPath) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDownloadBehavior");
    chromeRequest
        .putParams("behavior", behavior)
        .putParams("downloadPath", downloadPath);
    chromeSession.send(chromeRequest);
  }

  /**
   * Set the behavior when downloading a file.
   *
   * @param behavior  Whether to allow all or deny all download requests, or use default Chrome behavior if
   * available (otherwise deny).
   * @param downloadPath [Optional] The default path to save downloaded files to. This is requred if behavior is set to 'allow'
   */
  public void setDownloadBehaviorAsync(String behavior, String downloadPath) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setDownloadBehavior");
    chromeRequest
        .putParams("behavior", behavior)
        .putParams("downloadPath", downloadPath);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position
   * unavailable.
   *
   * @param latitude [Optional] Mock latitude
   * @param longitude [Optional] Mock longitude
   * @param accuracy [Optional] Mock accuracy
   */
  @Deprecated
  public void setGeolocationOverride(Number latitude, Number longitude, Number accuracy) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setGeolocationOverride");
    chromeRequest
        .putParams("latitude", latitude)
        .putParams("longitude", longitude)
        .putParams("accuracy", accuracy);
    chromeSession.send(chromeRequest);
  }

  /**
   * Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position
   * unavailable.
   *
   * @param latitude [Optional] Mock latitude
   * @param longitude [Optional] Mock longitude
   * @param accuracy [Optional] Mock accuracy
   */
  @Deprecated
  public void setGeolocationOverrideAsync(Number latitude, Number longitude, Number accuracy) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setGeolocationOverride");
    chromeRequest
        .putParams("latitude", latitude)
        .putParams("longitude", longitude)
        .putParams("accuracy", accuracy);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Controls whether page will emit lifecycle events.
   *
   * @param enabled  If true, starts emitting lifecycle events.
   */
  public void setLifecycleEventsEnabled(Boolean enabled) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setLifecycleEventsEnabled");
    chromeRequest
        .putParams("enabled", enabled);
    chromeSession.send(chromeRequest);
  }

  /**
   * Controls whether page will emit lifecycle events.
   *
   * @param enabled  If true, starts emitting lifecycle events.
   */
  public void setLifecycleEventsEnabledAsync(Boolean enabled) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setLifecycleEventsEnabled");
    chromeRequest
        .putParams("enabled", enabled);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Toggles mouse event-based touch event emulation.
   *
   * @param enabled  Whether the touch event emulation should be enabled.
   * @param configuration [Optional] Touch/gesture events configuration. Default: current platform.
   */
  @Deprecated
  public void setTouchEmulationEnabled(Boolean enabled, String configuration) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setTouchEmulationEnabled");
    chromeRequest
        .putParams("enabled", enabled)
        .putParams("configuration", configuration);
    chromeSession.send(chromeRequest);
  }

  /**
   * Toggles mouse event-based touch event emulation.
   *
   * @param enabled  Whether the touch event emulation should be enabled.
   * @param configuration [Optional] Touch/gesture events configuration. Default: current platform.
   */
  @Deprecated
  public void setTouchEmulationEnabledAsync(Boolean enabled, String configuration) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.setTouchEmulationEnabled");
    chromeRequest
        .putParams("enabled", enabled)
        .putParams("configuration", configuration);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Starts sending each frame using the `screencastFrame` event.
   *
   * @param format [Optional] Image compression format.
   * @param quality [Optional] Compression quality from range [0..100].
   * @param maxWidth [Optional] Maximum screenshot width.
   * @param maxHeight [Optional] Maximum screenshot height.
   * @param everyNthFrame [Optional] Send every n-th frame.
   */
  public void startScreencast(String format, Integer quality, Integer maxWidth, Integer maxHeight,
      Integer everyNthFrame) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.startScreencast");
    chromeRequest
        .putParams("format", format)
        .putParams("quality", quality)
        .putParams("maxWidth", maxWidth)
        .putParams("maxHeight", maxHeight)
        .putParams("everyNthFrame", everyNthFrame);
    chromeSession.send(chromeRequest);
  }

  /**
   * Starts sending each frame using the `screencastFrame` event.
   *
   * @param format [Optional] Image compression format.
   * @param quality [Optional] Compression quality from range [0..100].
   * @param maxWidth [Optional] Maximum screenshot width.
   * @param maxHeight [Optional] Maximum screenshot height.
   * @param everyNthFrame [Optional] Send every n-th frame.
   */
  public void startScreencastAsync(String format, Integer quality, Integer maxWidth,
      Integer maxHeight, Integer everyNthFrame) {
    ChromeRequest chromeRequest = new ChromeRequest("Page.startScreencast");
    chromeRequest
        .putParams("format", format)
        .putParams("quality", quality)
        .putParams("maxWidth", maxWidth)
        .putParams("maxHeight", maxHeight)
        .putParams("everyNthFrame", everyNthFrame);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Force the page stop all navigations and pending resource fetches.
   */
  public void stopLoading() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.stopLoading");
    chromeSession.send(chromeRequest);
  }

  /**
   * Force the page stop all navigations and pending resource fetches.
   */
  public void stopLoadingAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.stopLoading");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Crashes renderer on the IO thread, generates minidumps.
   */
  public void crash() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.crash");
    chromeSession.send(chromeRequest);
  }

  /**
   * Crashes renderer on the IO thread, generates minidumps.
   */
  public void crashAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.crash");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Stops sending each frame in the `screencastFrame`.
   */
  public void stopScreencast() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.stopScreencast");
    chromeSession.send(chromeRequest);
  }

  /**
   * Stops sending each frame in the `screencastFrame`.
   */
  public void stopScreencastAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Page.stopScreencast");
    chromeSession.sendAsync(chromeRequest);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy