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

com.hubspot.chrome.devtools.client.core.debugger.Debugger Maven / Gradle / Ivy

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

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.runtime.CallArgument;
import com.hubspot.chrome.devtools.client.core.runtime.ScriptId;
import com.hubspot.chrome.devtools.client.core.runtime.StackTrace;
import com.hubspot.chrome.devtools.client.core.runtime.StackTraceId;
import com.hubspot.chrome.devtools.client.core.runtime.UniqueDebuggerId;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * Debugger domain exposes JavaScript debugging capabilities. It allows setting and removing
 * breakpoints, stepping through execution, exploring stack traces, etc.
 */
public final class Debugger {
  ChromeSessionCore chromeSession;

  ObjectMapper objectMapper;

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

  /**
   * Continues execution until specific location is reached.
   *
   * @param location  Location to continue to.
   */
  public void continueToLocation(Location location, String targetCallFrames) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.continueToLocation");
    chromeRequest
        .putParams("location", location)
        .putParams("targetCallFrames", targetCallFrames);
    chromeSession.send(chromeRequest);
  }

  /**
   * Continues execution until specific location is reached.
   *
   * @param location  Location to continue to.
   */
  public void continueToLocationAsync(Location location, String targetCallFrames) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.continueToLocation");
    chromeRequest
        .putParams("location", location)
        .putParams("targetCallFrames", targetCallFrames);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Disables debugger for given page.
   */
  public void disable() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.disable");
    chromeSession.send(chromeRequest);
  }

  /**
   * Disables debugger for given page.
   */
  public void disableAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.disable");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Enables debugger for the given page. Clients should not assume that the debugging has been
   * enabled until the result for this command is received.
   */
  public UniqueDebuggerId enable() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.enable");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Enables debugger for the given page. Clients should not assume that the debugging has been
   * enabled until the result for this command is received.
   */
  public CompletableFuture enableAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.enable");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Evaluates expression on a given call frame.
   *
   * @param callFrameId  Call frame identifier to evaluate on.
   * @param expression  Expression to evaluate.
   * @param objectGroup [Optional] String object group name to put result into (allows rapid releasing resulting object handles
   * using `releaseObjectGroup`).
   * @param includeCommandLineAPI [Optional] Specifies whether command line API should be available to the evaluated expression, defaults
   * to false.
   * @param silent [Optional] In silent mode exceptions thrown during evaluation are not reported and do not pause
   * execution. Overrides `setPauseOnException` state.
   * @param returnByValue [Optional] Whether the result is expected to be a JSON object that should be sent by value.
   * @param generatePreview [Optional] Whether preview should be generated for the result.
   * @param throwOnSideEffect [Optional] Whether to throw an exception if side effect cannot be ruled out during evaluation.
   */
  public EvaluateOnCallFrameResult evaluateOnCallFrame(CallFrameId callFrameId, String expression,
      String objectGroup, Boolean includeCommandLineAPI, Boolean silent, Boolean returnByValue,
      Boolean generatePreview, Boolean throwOnSideEffect) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.evaluateOnCallFrame");
    chromeRequest
        .putParams("callFrameId", callFrameId)
        .putParams("expression", expression)
        .putParams("objectGroup", objectGroup)
        .putParams("includeCommandLineAPI", includeCommandLineAPI)
        .putParams("silent", silent)
        .putParams("returnByValue", returnByValue)
        .putParams("generatePreview", generatePreview)
        .putParams("throwOnSideEffect", throwOnSideEffect);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Evaluates expression on a given call frame.
   *
   * @param callFrameId  Call frame identifier to evaluate on.
   * @param expression  Expression to evaluate.
   * @param objectGroup [Optional] String object group name to put result into (allows rapid releasing resulting object handles
   * using `releaseObjectGroup`).
   * @param includeCommandLineAPI [Optional] Specifies whether command line API should be available to the evaluated expression, defaults
   * to false.
   * @param silent [Optional] In silent mode exceptions thrown during evaluation are not reported and do not pause
   * execution. Overrides `setPauseOnException` state.
   * @param returnByValue [Optional] Whether the result is expected to be a JSON object that should be sent by value.
   * @param generatePreview [Optional] Whether preview should be generated for the result.
   * @param throwOnSideEffect [Optional] Whether to throw an exception if side effect cannot be ruled out during evaluation.
   */
  public CompletableFuture evaluateOnCallFrameAsync(
      CallFrameId callFrameId, String expression, String objectGroup, Boolean includeCommandLineAPI,
      Boolean silent, Boolean returnByValue, Boolean generatePreview, Boolean throwOnSideEffect) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.evaluateOnCallFrame");
    chromeRequest
        .putParams("callFrameId", callFrameId)
        .putParams("expression", expression)
        .putParams("objectGroup", objectGroup)
        .putParams("includeCommandLineAPI", includeCommandLineAPI)
        .putParams("silent", silent)
        .putParams("returnByValue", returnByValue)
        .putParams("generatePreview", generatePreview)
        .putParams("throwOnSideEffect", throwOnSideEffect);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns possible locations for breakpoint. scriptId in start and end range locations should be
   * the same.
   *
   * @param start  Start of range to search possible breakpoint locations in.
   * @param end [Optional] End of range to search possible breakpoint locations in (excluding). When not specified, end
   * of scripts is used as end of range.
   * @param restrictToFunction [Optional] Only consider locations which are in the same (non-nested) function as start.
   */
  public List getPossibleBreakpoints(Location start, Location end,
      Boolean restrictToFunction) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.getPossibleBreakpoints");
    chromeRequest
        .putParams("start", start)
        .putParams("end", end)
        .putParams("restrictToFunction", restrictToFunction);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns possible locations for breakpoint. scriptId in start and end range locations should be
   * the same.
   *
   * @param start  Start of range to search possible breakpoint locations in.
   * @param end [Optional] End of range to search possible breakpoint locations in (excluding). When not specified, end
   * of scripts is used as end of range.
   * @param restrictToFunction [Optional] Only consider locations which are in the same (non-nested) function as start.
   */
  public CompletableFuture> getPossibleBreakpointsAsync(Location start,
      Location end, Boolean restrictToFunction) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.getPossibleBreakpoints");
    chromeRequest
        .putParams("start", start)
        .putParams("end", end)
        .putParams("restrictToFunction", restrictToFunction);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Returns source for the script with given id.
   *
   * @param scriptId  Id of the script to get source for.
   */
  public String getScriptSource(ScriptId scriptId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.getScriptSource");
    chromeRequest
        .putParams("scriptId", scriptId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns source for the script with given id.
   *
   * @param scriptId  Id of the script to get source for.
   */
  public CompletableFuture getScriptSourceAsync(ScriptId scriptId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.getScriptSource");
    chromeRequest
        .putParams("scriptId", scriptId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns stack trace with given `stackTraceId`.
   */
  public StackTrace getStackTrace(StackTraceId stackTraceId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.getStackTrace");
    chromeRequest
        .putParams("stackTraceId", stackTraceId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns stack trace with given `stackTraceId`.
   */
  public CompletableFuture getStackTraceAsync(StackTraceId stackTraceId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.getStackTrace");
    chromeRequest
        .putParams("stackTraceId", stackTraceId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Stops on the next JavaScript statement.
   */
  public void pause() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.pause");
    chromeSession.send(chromeRequest);
  }

  /**
   * Stops on the next JavaScript statement.
   */
  public void pauseAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.pause");
    chromeSession.sendAsync(chromeRequest);
  }

  public void pauseOnAsyncCall(StackTraceId parentStackTraceId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.pauseOnAsyncCall");
    chromeRequest
        .putParams("parentStackTraceId", parentStackTraceId);
    chromeSession.send(chromeRequest);
  }

  public void pauseOnAsyncCallAsync(StackTraceId parentStackTraceId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.pauseOnAsyncCall");
    chromeRequest
        .putParams("parentStackTraceId", parentStackTraceId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Removes JavaScript breakpoint.
   */
  public void removeBreakpoint(BreakpointId breakpointId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.removeBreakpoint");
    chromeRequest
        .putParams("breakpointId", breakpointId);
    chromeSession.send(chromeRequest);
  }

  /**
   * Removes JavaScript breakpoint.
   */
  public void removeBreakpointAsync(BreakpointId breakpointId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.removeBreakpoint");
    chromeRequest
        .putParams("breakpointId", breakpointId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Restarts particular call frame from the beginning.
   *
   * @param callFrameId  Call frame identifier to evaluate on.
   */
  public RestartFrameResult restartFrame(CallFrameId callFrameId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.restartFrame");
    chromeRequest
        .putParams("callFrameId", callFrameId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Restarts particular call frame from the beginning.
   *
   * @param callFrameId  Call frame identifier to evaluate on.
   */
  public CompletableFuture restartFrameAsync(CallFrameId callFrameId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.restartFrame");
    chromeRequest
        .putParams("callFrameId", callFrameId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Resumes JavaScript execution.
   */
  public void resume() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.resume");
    chromeSession.send(chromeRequest);
  }

  /**
   * Resumes JavaScript execution.
   */
  public void resumeAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.resume");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * This method is deprecated - use Debugger.stepInto with breakOnAsyncCall and
   * Debugger.pauseOnAsyncTask instead. Steps into next scheduled async task if any is scheduled
   * before next pause. Returns success when async task is actually scheduled, returns error if no
   * task were scheduled or another scheduleStepIntoAsync was called.
   */
  public void scheduleStepIntoAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.scheduleStepIntoAsync");
    chromeSession.send(chromeRequest);
  }

  /**
   * This method is deprecated - use Debugger.stepInto with breakOnAsyncCall and
   * Debugger.pauseOnAsyncTask instead. Steps into next scheduled async task if any is scheduled
   * before next pause. Returns success when async task is actually scheduled, returns error if no
   * task were scheduled or another scheduleStepIntoAsync was called.
   */
  public void scheduleStepIntoAsyncAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.scheduleStepIntoAsync");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Searches for given string in script content.
   *
   * @param scriptId  Id of the script 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 searchInContent(ScriptId scriptId, String query, Boolean caseSensitive,
      Boolean isRegex) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.searchInContent");
    chromeRequest
        .putParams("scriptId", scriptId)
        .putParams("query", query)
        .putParams("caseSensitive", caseSensitive)
        .putParams("isRegex", isRegex);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Searches for given string in script content.
   *
   * @param scriptId  Id of the script 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> searchInContentAsync(ScriptId scriptId, String query,
      Boolean caseSensitive, Boolean isRegex) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.searchInContent");
    chromeRequest
        .putParams("scriptId", scriptId)
        .putParams("query", query)
        .putParams("caseSensitive", caseSensitive)
        .putParams("isRegex", isRegex);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Enables or disables async call stacks tracking.
   *
   * @param maxDepth  Maximum depth of async call stacks. Setting to `0` will effectively disable collecting async
   * call stacks (default).
   */
  public void setAsyncCallStackDepth(Integer maxDepth) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setAsyncCallStackDepth");
    chromeRequest
        .putParams("maxDepth", maxDepth);
    chromeSession.send(chromeRequest);
  }

  /**
   * Enables or disables async call stacks tracking.
   *
   * @param maxDepth  Maximum depth of async call stacks. Setting to `0` will effectively disable collecting async
   * call stacks (default).
   */
  public void setAsyncCallStackDepthAsync(Integer maxDepth) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setAsyncCallStackDepth");
    chromeRequest
        .putParams("maxDepth", maxDepth);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Replace previous blackbox patterns with passed ones. Forces backend to skip stepping/pausing in
   * scripts with url matching one of the patterns. VM will try to leave blackboxed script by
   * performing 'step in' several times, finally resorting to 'step out' if unsuccessful.
   *
   * @param patterns  Array of regexps that will be used to check script url for blackbox state.
   */
  public void setBlackboxPatterns(List patterns) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBlackboxPatterns");
    chromeRequest
        .putParams("patterns", patterns);
    chromeSession.send(chromeRequest);
  }

  /**
   * Replace previous blackbox patterns with passed ones. Forces backend to skip stepping/pausing in
   * scripts with url matching one of the patterns. VM will try to leave blackboxed script by
   * performing 'step in' several times, finally resorting to 'step out' if unsuccessful.
   *
   * @param patterns  Array of regexps that will be used to check script url for blackbox state.
   */
  public void setBlackboxPatternsAsync(List patterns) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBlackboxPatterns");
    chromeRequest
        .putParams("patterns", patterns);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Makes backend skip steps in the script in blackboxed ranges. VM will try leave blacklisted
   * scripts by performing 'step in' several times, finally resorting to 'step out' if unsuccessful.
   * Positions array contains positions where blackbox state is changed. First interval isn't
   * blackboxed. Array should be sorted.
   *
   * @param scriptId  Id of the script.
   */
  public void setBlackboxedRanges(ScriptId scriptId, List positions) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBlackboxedRanges");
    chromeRequest
        .putParams("scriptId", scriptId)
        .putParams("positions", positions);
    chromeSession.send(chromeRequest);
  }

  /**
   * Makes backend skip steps in the script in blackboxed ranges. VM will try leave blacklisted
   * scripts by performing 'step in' several times, finally resorting to 'step out' if unsuccessful.
   * Positions array contains positions where blackbox state is changed. First interval isn't
   * blackboxed. Array should be sorted.
   *
   * @param scriptId  Id of the script.
   */
  public void setBlackboxedRangesAsync(ScriptId scriptId, List positions) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBlackboxedRanges");
    chromeRequest
        .putParams("scriptId", scriptId)
        .putParams("positions", positions);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Sets JavaScript breakpoint at a given location.
   *
   * @param location  Location to set breakpoint in.
   * @param condition [Optional] Expression to use as a breakpoint condition. When specified, debugger will only stop on the
   * breakpoint if this expression evaluates to true.
   */
  public SetBreakpointResult setBreakpoint(Location location, String condition) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBreakpoint");
    chromeRequest
        .putParams("location", location)
        .putParams("condition", condition);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Sets JavaScript breakpoint at a given location.
   *
   * @param location  Location to set breakpoint in.
   * @param condition [Optional] Expression to use as a breakpoint condition. When specified, debugger will only stop on the
   * breakpoint if this expression evaluates to true.
   */
  public CompletableFuture setBreakpointAsync(Location location,
      String condition) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBreakpoint");
    chromeRequest
        .putParams("location", location)
        .putParams("condition", condition);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Sets JavaScript breakpoint at given location specified either by URL or URL regex. Once this
   * command is issued, all existing parsed scripts will have breakpoints resolved and returned in
   * `locations` property. Further matching script parsing will result in subsequent
   * `breakpointResolved` events issued. This logical breakpoint will survive page reloads.
   *
   * @param lineNumber  Line number to set breakpoint at.
   * @param url [Optional] URL of the resources to set breakpoint on.
   * @param urlRegex [Optional] Regex pattern for the URLs of the resources to set breakpoints on. Either `url` or
   * `urlRegex` must be specified.
   * @param scriptHash [Optional] Script hash of the resources to set breakpoint on.
   * @param columnNumber [Optional] Offset in the line to set breakpoint at.
   * @param condition [Optional] Expression to use as a breakpoint condition. When specified, debugger will only stop on the
   * breakpoint if this expression evaluates to true.
   */
  public SetBreakpointByUrlResult setBreakpointByUrl(Integer lineNumber, String url,
      String urlRegex, String scriptHash, Integer columnNumber, String condition) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBreakpointByUrl");
    chromeRequest
        .putParams("lineNumber", lineNumber)
        .putParams("url", url)
        .putParams("urlRegex", urlRegex)
        .putParams("scriptHash", scriptHash)
        .putParams("columnNumber", columnNumber)
        .putParams("condition", condition);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Sets JavaScript breakpoint at given location specified either by URL or URL regex. Once this
   * command is issued, all existing parsed scripts will have breakpoints resolved and returned in
   * `locations` property. Further matching script parsing will result in subsequent
   * `breakpointResolved` events issued. This logical breakpoint will survive page reloads.
   *
   * @param lineNumber  Line number to set breakpoint at.
   * @param url [Optional] URL of the resources to set breakpoint on.
   * @param urlRegex [Optional] Regex pattern for the URLs of the resources to set breakpoints on. Either `url` or
   * `urlRegex` must be specified.
   * @param scriptHash [Optional] Script hash of the resources to set breakpoint on.
   * @param columnNumber [Optional] Offset in the line to set breakpoint at.
   * @param condition [Optional] Expression to use as a breakpoint condition. When specified, debugger will only stop on the
   * breakpoint if this expression evaluates to true.
   */
  public CompletableFuture setBreakpointByUrlAsync(Integer lineNumber,
      String url, String urlRegex, String scriptHash, Integer columnNumber, String condition) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBreakpointByUrl");
    chromeRequest
        .putParams("lineNumber", lineNumber)
        .putParams("url", url)
        .putParams("urlRegex", urlRegex)
        .putParams("scriptHash", scriptHash)
        .putParams("columnNumber", columnNumber)
        .putParams("condition", condition);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Activates / deactivates all breakpoints on the page.
   *
   * @param active  New value for breakpoints active state.
   */
  public void setBreakpointsActive(Boolean active) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBreakpointsActive");
    chromeRequest
        .putParams("active", active);
    chromeSession.send(chromeRequest);
  }

  /**
   * Activates / deactivates all breakpoints on the page.
   *
   * @param active  New value for breakpoints active state.
   */
  public void setBreakpointsActiveAsync(Boolean active) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setBreakpointsActive");
    chromeRequest
        .putParams("active", active);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Defines pause on exceptions state. Can be set to stop on all exceptions, uncaught exceptions or
   * no exceptions. Initial pause on exceptions state is `none`.
   *
   * @param state  Pause on exceptions mode.
   */
  public void setPauseOnExceptions(String state) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setPauseOnExceptions");
    chromeRequest
        .putParams("state", state);
    chromeSession.send(chromeRequest);
  }

  /**
   * Defines pause on exceptions state. Can be set to stop on all exceptions, uncaught exceptions or
   * no exceptions. Initial pause on exceptions state is `none`.
   *
   * @param state  Pause on exceptions mode.
   */
  public void setPauseOnExceptionsAsync(String state) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setPauseOnExceptions");
    chromeRequest
        .putParams("state", state);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Changes return value in top frame. Available only at return break position.
   *
   * @param newValue  New return value.
   */
  public void setReturnValue(CallArgument newValue) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setReturnValue");
    chromeRequest
        .putParams("newValue", newValue);
    chromeSession.send(chromeRequest);
  }

  /**
   * Changes return value in top frame. Available only at return break position.
   *
   * @param newValue  New return value.
   */
  public void setReturnValueAsync(CallArgument newValue) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setReturnValue");
    chromeRequest
        .putParams("newValue", newValue);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Edits JavaScript source live.
   *
   * @param scriptId  Id of the script to edit.
   * @param scriptSource  New content of the script.
   * @param dryRun [Optional] If true the change will not actually be applied. Dry run may be used to get result
   * description without actually modifying the code.
   */
  public SetScriptSourceResult setScriptSource(ScriptId scriptId, String scriptSource,
      Boolean dryRun) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setScriptSource");
    chromeRequest
        .putParams("scriptId", scriptId)
        .putParams("scriptSource", scriptSource)
        .putParams("dryRun", dryRun);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Edits JavaScript source live.
   *
   * @param scriptId  Id of the script to edit.
   * @param scriptSource  New content of the script.
   * @param dryRun [Optional] If true the change will not actually be applied. Dry run may be used to get result
   * description without actually modifying the code.
   */
  public CompletableFuture setScriptSourceAsync(ScriptId scriptId,
      String scriptSource, Boolean dryRun) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setScriptSource");
    chromeRequest
        .putParams("scriptId", scriptId)
        .putParams("scriptSource", scriptSource)
        .putParams("dryRun", dryRun);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Makes page not interrupt on any pauses (breakpoint, exception, dom exception etc).
   *
   * @param skip  New value for skip pauses state.
   */
  public void setSkipAllPauses(Boolean skip) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setSkipAllPauses");
    chromeRequest
        .putParams("skip", skip);
    chromeSession.send(chromeRequest);
  }

  /**
   * Makes page not interrupt on any pauses (breakpoint, exception, dom exception etc).
   *
   * @param skip  New value for skip pauses state.
   */
  public void setSkipAllPausesAsync(Boolean skip) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setSkipAllPauses");
    chromeRequest
        .putParams("skip", skip);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Changes value of variable in a callframe. Object-based scopes are not supported and must be
   * mutated manually.
   *
   * @param scopeNumber  0-based number of scope as was listed in scope chain. Only 'local', 'closure' and 'catch'
   * scope types are allowed. Other scopes could be manipulated manually.
   * @param variableName  Variable name.
   * @param newValue  New variable value.
   * @param callFrameId  Id of callframe that holds variable.
   */
  public void setVariableValue(Integer scopeNumber, String variableName, CallArgument newValue,
      CallFrameId callFrameId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setVariableValue");
    chromeRequest
        .putParams("scopeNumber", scopeNumber)
        .putParams("variableName", variableName)
        .putParams("newValue", newValue)
        .putParams("callFrameId", callFrameId);
    chromeSession.send(chromeRequest);
  }

  /**
   * Changes value of variable in a callframe. Object-based scopes are not supported and must be
   * mutated manually.
   *
   * @param scopeNumber  0-based number of scope as was listed in scope chain. Only 'local', 'closure' and 'catch'
   * scope types are allowed. Other scopes could be manipulated manually.
   * @param variableName  Variable name.
   * @param newValue  New variable value.
   * @param callFrameId  Id of callframe that holds variable.
   */
  public void setVariableValueAsync(Integer scopeNumber, String variableName, CallArgument newValue,
      CallFrameId callFrameId) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.setVariableValue");
    chromeRequest
        .putParams("scopeNumber", scopeNumber)
        .putParams("variableName", variableName)
        .putParams("newValue", newValue)
        .putParams("callFrameId", callFrameId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Steps into the function call.
   *
   * @param breakOnAsyncCall [Optional] Debugger will issue additional Debugger.paused notification if any async task is scheduled
   * before next pause.
   */
  public void stepInto(Boolean breakOnAsyncCall) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.stepInto");
    chromeRequest
        .putParams("breakOnAsyncCall", breakOnAsyncCall);
    chromeSession.send(chromeRequest);
  }

  /**
   * Steps into the function call.
   *
   * @param breakOnAsyncCall [Optional] Debugger will issue additional Debugger.paused notification if any async task is scheduled
   * before next pause.
   */
  public void stepIntoAsync(Boolean breakOnAsyncCall) {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.stepInto");
    chromeRequest
        .putParams("breakOnAsyncCall", breakOnAsyncCall);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Steps out of the function call.
   */
  public void stepOut() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.stepOut");
    chromeSession.send(chromeRequest);
  }

  /**
   * Steps out of the function call.
   */
  public void stepOutAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.stepOut");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Steps over the statement.
   */
  public void stepOver() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.stepOver");
    chromeSession.send(chromeRequest);
  }

  /**
   * Steps over the statement.
   */
  public void stepOverAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Debugger.stepOver");
    chromeSession.sendAsync(chromeRequest);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy