// Copyright © 2020 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. namespace CefSharp.DevTools.Debugger { using System.Linq; /// /// Debugger domain exposes JavaScript debugging capabilities. It allows setting and removing /// breakpoints, stepping through execution, exploring stack traces, etc. /// public partial class Debugger : DevToolsDomainBase { private CefSharp.DevTools.IDevToolsClient _client; public Debugger(CefSharp.DevTools.IDevToolsClient client) { _client = (client); } partial void ValidateContinueToLocation(CefSharp.DevTools.Debugger.Location location, string targetCallFrames = null); /// /// Continues execution until specific location is reached. /// /// Location to continue to. /// targetCallFrames /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task ContinueToLocationAsync(CefSharp.DevTools.Debugger.Location location, string targetCallFrames = null) { ValidateContinueToLocation(location, targetCallFrames); var dict = new System.Collections.Generic.Dictionary(); dict.Add("location", location.ToDictionary()); if (!(string.IsNullOrEmpty(targetCallFrames))) { dict.Add("targetCallFrames", targetCallFrames); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.continueToLocation", dict); return methodResult; } /// /// Disables debugger for given page. /// /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task DisableAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.disable", dict); return methodResult; } partial void ValidateEnable(long? maxScriptsCacheSize = null); /// /// Enables debugger for the given page. Clients should not assume that the debugging has been /// enabled until the result for this command is received. /// /// The maximum size in bytes of collected scripts (not referenced by other heap objects) public async System.Threading.Tasks.Task EnableAsync(long? maxScriptsCacheSize = null) { ValidateEnable(maxScriptsCacheSize); var dict = new System.Collections.Generic.Dictionary(); if (maxScriptsCacheSize.HasValue) { dict.Add("maxScriptsCacheSize", maxScriptsCacheSize.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.enable", dict); return methodResult.DeserializeJson(); } partial void ValidateEvaluateOnCallFrame(string callFrameId, string expression, string objectGroup = null, bool? includeCommandLineAPI = null, bool? silent = null, bool? returnByValue = null, bool? generatePreview = null, bool? throwOnSideEffect = null, long? timeout = null); /// /// Evaluates expression on a given call frame. /// /// Call frame identifier to evaluate on. /// Expression to evaluate. /// String object group name to put result into (allows rapid releasing resulting object handles public async System.Threading.Tasks.Task EvaluateOnCallFrameAsync(string callFrameId, string expression, string objectGroup = null, bool? includeCommandLineAPI = null, bool? silent = null, bool? returnByValue = null, bool? generatePreview = null, bool? throwOnSideEffect = null, long? timeout = null) { ValidateEvaluateOnCallFrame(callFrameId, expression, objectGroup, includeCommandLineAPI, silent, returnByValue, generatePreview, throwOnSideEffect, timeout); var dict = new System.Collections.Generic.Dictionary(); dict.Add("callFrameId", callFrameId); dict.Add("expression", expression); if (!(string.IsNullOrEmpty(objectGroup))) { dict.Add("objectGroup", objectGroup); } if (includeCommandLineAPI.HasValue) { dict.Add("includeCommandLineAPI", includeCommandLineAPI.Value); } if (silent.HasValue) { dict.Add("silent", silent.Value); } if (returnByValue.HasValue) { dict.Add("returnByValue", returnByValue.Value); } if (generatePreview.HasValue) { dict.Add("generatePreview", generatePreview.Value); } if (throwOnSideEffect.HasValue) { dict.Add("throwOnSideEffect", throwOnSideEffect.Value); } if (timeout.HasValue) { dict.Add("timeout", timeout.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.evaluateOnCallFrame", dict); return methodResult.DeserializeJson(); } partial void ValidateExecuteWasmEvaluator(string callFrameId, byte[] evaluator, long? timeout = null); /// /// Execute a Wasm Evaluator module on a given call frame. /// /// WebAssembly call frame identifier to evaluate on. /// Code of the evaluator module. /// Terminate execution after timing out (number of milliseconds). /// returns System.Threading.Tasks.Task<ExecuteWasmEvaluatorResponse> public async System.Threading.Tasks.Task ExecuteWasmEvaluatorAsync(string callFrameId, byte[] evaluator, long? timeout = null) { ValidateExecuteWasmEvaluator(callFrameId, evaluator, timeout); var dict = new System.Collections.Generic.Dictionary(); dict.Add("callFrameId", callFrameId); dict.Add("evaluator", ToBase64String(evaluator)); if (timeout.HasValue) { dict.Add("timeout", timeout.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.executeWasmEvaluator", dict); return methodResult.DeserializeJson(); } partial void ValidateGetPossibleBreakpoints(CefSharp.DevTools.Debugger.Location start, CefSharp.DevTools.Debugger.Location end = null, bool? restrictToFunction = null); /// /// Returns possible locations for breakpoint. scriptId in start and end range locations should be /// the same. /// /// Start of range to search possible breakpoint locations in. /// End of range to search possible breakpoint locations in (excluding). When not specified, end public async System.Threading.Tasks.Task GetPossibleBreakpointsAsync(CefSharp.DevTools.Debugger.Location start, CefSharp.DevTools.Debugger.Location end = null, bool? restrictToFunction = null) { ValidateGetPossibleBreakpoints(start, end, restrictToFunction); var dict = new System.Collections.Generic.Dictionary(); dict.Add("start", start.ToDictionary()); if ((end) != (null)) { dict.Add("end", end.ToDictionary()); } if (restrictToFunction.HasValue) { dict.Add("restrictToFunction", restrictToFunction.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.getPossibleBreakpoints", dict); return methodResult.DeserializeJson(); } partial void ValidateGetScriptSource(string scriptId); /// /// Returns source for the script with given id. /// /// Id of the script to get source for. /// returns System.Threading.Tasks.Task<GetScriptSourceResponse> public async System.Threading.Tasks.Task GetScriptSourceAsync(string scriptId) { ValidateGetScriptSource(scriptId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("scriptId", scriptId); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.getScriptSource", dict); return methodResult.DeserializeJson(); } partial void ValidateGetStackTrace(CefSharp.DevTools.Runtime.StackTraceId stackTraceId); /// /// Returns stack trace with given `stackTraceId`. /// /// stackTraceId /// returns System.Threading.Tasks.Task<GetStackTraceResponse> public async System.Threading.Tasks.Task GetStackTraceAsync(CefSharp.DevTools.Runtime.StackTraceId stackTraceId) { ValidateGetStackTrace(stackTraceId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("stackTraceId", stackTraceId.ToDictionary()); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.getStackTrace", dict); return methodResult.DeserializeJson(); } /// /// Stops on the next JavaScript statement. /// /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task PauseAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.pause", dict); return methodResult; } partial void ValidateRemoveBreakpoint(string breakpointId); /// /// Removes JavaScript breakpoint. /// /// breakpointId /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task RemoveBreakpointAsync(string breakpointId) { ValidateRemoveBreakpoint(breakpointId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("breakpointId", breakpointId); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.removeBreakpoint", dict); return methodResult; } partial void ValidateRestartFrame(string callFrameId); /// /// Restarts particular call frame from the beginning. /// /// Call frame identifier to evaluate on. /// returns System.Threading.Tasks.Task<RestartFrameResponse> public async System.Threading.Tasks.Task RestartFrameAsync(string callFrameId) { ValidateRestartFrame(callFrameId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("callFrameId", callFrameId); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.restartFrame", dict); return methodResult.DeserializeJson(); } partial void ValidateResume(bool? terminateOnResume = null); /// /// Resumes JavaScript execution. /// /// Set to true to terminate execution upon resuming execution. In contrast public async System.Threading.Tasks.Task ResumeAsync(bool? terminateOnResume = null) { ValidateResume(terminateOnResume); var dict = new System.Collections.Generic.Dictionary(); if (terminateOnResume.HasValue) { dict.Add("terminateOnResume", terminateOnResume.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.resume", dict); return methodResult; } partial void ValidateSearchInContent(string scriptId, string query, bool? caseSensitive = null, bool? isRegex = null); /// /// Searches for given string in script content. /// /// Id of the script to search in. /// String to search for. /// If true, search is case sensitive. /// If true, treats string parameter as regex. /// returns System.Threading.Tasks.Task<SearchInContentResponse> public async System.Threading.Tasks.Task SearchInContentAsync(string scriptId, string query, bool? caseSensitive = null, bool? isRegex = null) { ValidateSearchInContent(scriptId, query, caseSensitive, isRegex); var dict = new System.Collections.Generic.Dictionary(); dict.Add("scriptId", scriptId); dict.Add("query", query); if (caseSensitive.HasValue) { dict.Add("caseSensitive", caseSensitive.Value); } if (isRegex.HasValue) { dict.Add("isRegex", isRegex.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.searchInContent", dict); return methodResult.DeserializeJson(); } partial void ValidateSetAsyncCallStackDepth(int maxDepth); /// /// Enables or disables async call stacks tracking. /// /// Maximum depth of async call stacks. Setting to `0` will effectively disable collecting async public async System.Threading.Tasks.Task SetAsyncCallStackDepthAsync(int maxDepth) { ValidateSetAsyncCallStackDepth(maxDepth); var dict = new System.Collections.Generic.Dictionary(); dict.Add("maxDepth", maxDepth); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setAsyncCallStackDepth", dict); return methodResult; } partial void ValidateSetBlackboxPatterns(string[] patterns); /// /// 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. /// /// Array of regexps that will be used to check script url for blackbox state. /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task SetBlackboxPatternsAsync(string[] patterns) { ValidateSetBlackboxPatterns(patterns); var dict = new System.Collections.Generic.Dictionary(); dict.Add("patterns", patterns); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setBlackboxPatterns", dict); return methodResult; } partial void ValidateSetBlackboxedRanges(string scriptId, System.Collections.Generic.IList positions); /// /// 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. /// /// Id of the script. /// positions /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task SetBlackboxedRangesAsync(string scriptId, System.Collections.Generic.IList positions) { ValidateSetBlackboxedRanges(scriptId, positions); var dict = new System.Collections.Generic.Dictionary(); dict.Add("scriptId", scriptId); dict.Add("positions", positions.Select(x => x.ToDictionary())); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setBlackboxedRanges", dict); return methodResult; } partial void ValidateSetBreakpoint(CefSharp.DevTools.Debugger.Location location, string condition = null); /// /// Sets JavaScript breakpoint at a given location. /// /// Location to set breakpoint in. /// Expression to use as a breakpoint condition. When specified, debugger will only stop on the public async System.Threading.Tasks.Task SetBreakpointAsync(CefSharp.DevTools.Debugger.Location location, string condition = null) { ValidateSetBreakpoint(location, condition); var dict = new System.Collections.Generic.Dictionary(); dict.Add("location", location.ToDictionary()); if (!(string.IsNullOrEmpty(condition))) { dict.Add("condition", condition); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setBreakpoint", dict); return methodResult.DeserializeJson(); } partial void ValidateSetInstrumentationBreakpoint(string instrumentation); /// /// Sets instrumentation breakpoint. /// /// Instrumentation name. /// returns System.Threading.Tasks.Task<SetInstrumentationBreakpointResponse> public async System.Threading.Tasks.Task SetInstrumentationBreakpointAsync(string instrumentation) { ValidateSetInstrumentationBreakpoint(instrumentation); var dict = new System.Collections.Generic.Dictionary(); dict.Add("instrumentation", instrumentation); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setInstrumentationBreakpoint", dict); return methodResult.DeserializeJson(); } partial void ValidateSetBreakpointByUrl(int lineNumber, string url = null, string urlRegex = null, string scriptHash = null, int? columnNumber = null, string condition = null); /// /// 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. /// /// Line number to set breakpoint at. /// URL of the resources to set breakpoint on. /// Regex pattern for the URLs of the resources to set breakpoints on. Either `url` or public async System.Threading.Tasks.Task SetBreakpointByUrlAsync(int lineNumber, string url = null, string urlRegex = null, string scriptHash = null, int? columnNumber = null, string condition = null) { ValidateSetBreakpointByUrl(lineNumber, url, urlRegex, scriptHash, columnNumber, condition); var dict = new System.Collections.Generic.Dictionary(); dict.Add("lineNumber", lineNumber); if (!(string.IsNullOrEmpty(url))) { dict.Add("url", url); } if (!(string.IsNullOrEmpty(urlRegex))) { dict.Add("urlRegex", urlRegex); } if (!(string.IsNullOrEmpty(scriptHash))) { dict.Add("scriptHash", scriptHash); } if (columnNumber.HasValue) { dict.Add("columnNumber", columnNumber.Value); } if (!(string.IsNullOrEmpty(condition))) { dict.Add("condition", condition); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setBreakpointByUrl", dict); return methodResult.DeserializeJson(); } partial void ValidateSetBreakpointOnFunctionCall(string objectId, string condition = null); /// /// Sets JavaScript breakpoint before each call to the given function. /// If another function was created from the same source as a given one, /// calling it will also trigger the breakpoint. /// /// Function object id. /// Expression to use as a breakpoint condition. When specified, debugger will public async System.Threading.Tasks.Task SetBreakpointOnFunctionCallAsync(string objectId, string condition = null) { ValidateSetBreakpointOnFunctionCall(objectId, condition); var dict = new System.Collections.Generic.Dictionary(); dict.Add("objectId", objectId); if (!(string.IsNullOrEmpty(condition))) { dict.Add("condition", condition); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setBreakpointOnFunctionCall", dict); return methodResult.DeserializeJson(); } partial void ValidateSetBreakpointsActive(bool active); /// /// Activates / deactivates all breakpoints on the page. /// /// New value for breakpoints active state. /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task SetBreakpointsActiveAsync(bool active) { ValidateSetBreakpointsActive(active); var dict = new System.Collections.Generic.Dictionary(); dict.Add("active", active); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setBreakpointsActive", dict); return methodResult; } partial void ValidateSetPauseOnExceptions(string state); /// /// 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`. /// /// Pause on exceptions mode. /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task SetPauseOnExceptionsAsync(string state) { ValidateSetPauseOnExceptions(state); var dict = new System.Collections.Generic.Dictionary(); dict.Add("state", state); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setPauseOnExceptions", dict); return methodResult; } partial void ValidateSetReturnValue(CefSharp.DevTools.Runtime.CallArgument newValue); /// /// Changes return value in top frame. Available only at return break position. /// /// New return value. /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task SetReturnValueAsync(CefSharp.DevTools.Runtime.CallArgument newValue) { ValidateSetReturnValue(newValue); var dict = new System.Collections.Generic.Dictionary(); dict.Add("newValue", newValue.ToDictionary()); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setReturnValue", dict); return methodResult; } partial void ValidateSetScriptSource(string scriptId, string scriptSource, bool? dryRun = null); /// /// Edits JavaScript source live. /// /// Id of the script to edit. /// New content of the script. /// If true the change will not actually be applied. Dry run may be used to get result public async System.Threading.Tasks.Task SetScriptSourceAsync(string scriptId, string scriptSource, bool? dryRun = null) { ValidateSetScriptSource(scriptId, scriptSource, dryRun); var dict = new System.Collections.Generic.Dictionary(); dict.Add("scriptId", scriptId); dict.Add("scriptSource", scriptSource); if (dryRun.HasValue) { dict.Add("dryRun", dryRun.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setScriptSource", dict); return methodResult.DeserializeJson(); } partial void ValidateSetSkipAllPauses(bool skip); /// /// Makes page not interrupt on any pauses (breakpoint, exception, dom exception etc). /// /// New value for skip pauses state. /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task SetSkipAllPausesAsync(bool skip) { ValidateSetSkipAllPauses(skip); var dict = new System.Collections.Generic.Dictionary(); dict.Add("skip", skip); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setSkipAllPauses", dict); return methodResult; } partial void ValidateSetVariableValue(int scopeNumber, string variableName, CefSharp.DevTools.Runtime.CallArgument newValue, string callFrameId); /// /// Changes value of variable in a callframe. Object-based scopes are not supported and must be /// mutated manually. /// /// 0-based number of scope as was listed in scope chain. Only 'local', 'closure' and 'catch' public async System.Threading.Tasks.Task SetVariableValueAsync(int scopeNumber, string variableName, CefSharp.DevTools.Runtime.CallArgument newValue, string callFrameId) { ValidateSetVariableValue(scopeNumber, variableName, newValue, callFrameId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("scopeNumber", scopeNumber); dict.Add("variableName", variableName); dict.Add("newValue", newValue.ToDictionary()); dict.Add("callFrameId", callFrameId); var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.setVariableValue", dict); return methodResult; } partial void ValidateStepInto(bool? breakOnAsyncCall = null); /// /// Steps into the function call. /// /// Debugger will pause on the execution of the first async task which was scheduled public async System.Threading.Tasks.Task StepIntoAsync(bool? breakOnAsyncCall = null) { ValidateStepInto(breakOnAsyncCall); var dict = new System.Collections.Generic.Dictionary(); if (breakOnAsyncCall.HasValue) { dict.Add("breakOnAsyncCall", breakOnAsyncCall.Value); } var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.stepInto", dict); return methodResult; } /// /// Steps out of the function call. /// /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task StepOutAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.stepOut", dict); return methodResult; } /// /// Steps over the statement. /// /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task StepOverAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("Debugger.stepOver", dict); return methodResult; } } }