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

com.hubspot.chrome.devtools.client.core.domsnapshot.DOMSnapshot Maven / Gradle / Ivy

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

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 java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * This domain facilitates obtaining document snapshots with DOM, layout, and style information.
 */
public final class DOMSnapshot {
  ChromeSessionCore chromeSession;

  ObjectMapper objectMapper;

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

  /**
   * Returns a document snapshot, including the full DOM tree of the root node (including iframes,
   * template contents, and imported documents) in a flattened array, as well as layout and
   * white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
   * flattened.
   *
   * @param computedStyleWhitelist  Whitelist of computed styles to return.
   * @param includeEventListeners [Optional] Whether or not to retrieve details of DOM listeners (default false).
   */
  public GetSnapshotResult getSnapshot(List computedStyleWhitelist,
      Boolean includeEventListeners) {
    ChromeRequest chromeRequest = new ChromeRequest("DOMSnapshot.getSnapshot");
    chromeRequest
        .putParams("computedStyleWhitelist", computedStyleWhitelist)
        .putParams("includeEventListeners", includeEventListeners);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns a document snapshot, including the full DOM tree of the root node (including iframes,
   * template contents, and imported documents) in a flattened array, as well as layout and
   * white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
   * flattened.
   *
   * @param computedStyleWhitelist  Whitelist of computed styles to return.
   * @param includeEventListeners [Optional] Whether or not to retrieve details of DOM listeners (default false).
   */
  public CompletableFuture getSnapshotAsync(List computedStyleWhitelist,
      Boolean includeEventListeners) {
    ChromeRequest chromeRequest = new ChromeRequest("DOMSnapshot.getSnapshot");
    chromeRequest
        .putParams("computedStyleWhitelist", computedStyleWhitelist)
        .putParams("includeEventListeners", includeEventListeners);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy