debugger.go 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. // Package debugger provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Debugger domain.
  3. //
  4. // Debugger domain exposes JavaScript debugging capabilities. It allows
  5. // setting and removing breakpoints, stepping through execution, exploring stack
  6. // traces, etc.
  7. //
  8. // Generated by the cdproto-gen command.
  9. package debugger
  10. // Code generated by cdproto-gen. DO NOT EDIT.
  11. import (
  12. "context"
  13. "encoding/base64"
  14. "github.com/chromedp/cdproto/cdp"
  15. "github.com/chromedp/cdproto/runtime"
  16. )
  17. // ContinueToLocationParams continues execution until specific location is
  18. // reached.
  19. type ContinueToLocationParams struct {
  20. Location *Location `json:"location"` // Location to continue to.
  21. TargetCallFrames ContinueToLocationTargetCallFrames `json:"targetCallFrames,omitempty"`
  22. }
  23. // ContinueToLocation continues execution until specific location is reached.
  24. //
  25. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-continueToLocation
  26. //
  27. // parameters:
  28. //
  29. // location - Location to continue to.
  30. func ContinueToLocation(location *Location) *ContinueToLocationParams {
  31. return &ContinueToLocationParams{
  32. Location: location,
  33. }
  34. }
  35. // WithTargetCallFrames [no description].
  36. func (p ContinueToLocationParams) WithTargetCallFrames(targetCallFrames ContinueToLocationTargetCallFrames) *ContinueToLocationParams {
  37. p.TargetCallFrames = targetCallFrames
  38. return &p
  39. }
  40. // Do executes Debugger.continueToLocation against the provided context.
  41. func (p *ContinueToLocationParams) Do(ctx context.Context) (err error) {
  42. return cdp.Execute(ctx, CommandContinueToLocation, p, nil)
  43. }
  44. // DisableParams disables debugger for given page.
  45. type DisableParams struct{}
  46. // Disable disables debugger for given page.
  47. //
  48. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-disable
  49. func Disable() *DisableParams {
  50. return &DisableParams{}
  51. }
  52. // Do executes Debugger.disable against the provided context.
  53. func (p *DisableParams) Do(ctx context.Context) (err error) {
  54. return cdp.Execute(ctx, CommandDisable, nil, nil)
  55. }
  56. // EnableParams enables debugger for the given page. Clients should not
  57. // assume that the debugging has been enabled until the result for this command
  58. // is received.
  59. type EnableParams struct {
  60. MaxScriptsCacheSize float64 `json:"maxScriptsCacheSize,omitempty"` // The maximum size in bytes of collected scripts (not referenced by other heap objects) the debugger can hold. Puts no limit if parameter is omitted.
  61. }
  62. // Enable enables debugger for the given page. Clients should not assume that
  63. // the debugging has been enabled until the result for this command is received.
  64. //
  65. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-enable
  66. //
  67. // parameters:
  68. func Enable() *EnableParams {
  69. return &EnableParams{}
  70. }
  71. // WithMaxScriptsCacheSize the maximum size in bytes of collected scripts
  72. // (not referenced by other heap objects) the debugger can hold. Puts no limit
  73. // if parameter is omitted.
  74. func (p EnableParams) WithMaxScriptsCacheSize(maxScriptsCacheSize float64) *EnableParams {
  75. p.MaxScriptsCacheSize = maxScriptsCacheSize
  76. return &p
  77. }
  78. // EnableReturns return values.
  79. type EnableReturns struct {
  80. DebuggerID runtime.UniqueDebuggerID `json:"debuggerId,omitempty"` // Unique identifier of the debugger.
  81. }
  82. // Do executes Debugger.enable against the provided context.
  83. //
  84. // returns:
  85. //
  86. // debuggerID - Unique identifier of the debugger.
  87. func (p *EnableParams) Do(ctx context.Context) (debuggerID runtime.UniqueDebuggerID, err error) {
  88. // execute
  89. var res EnableReturns
  90. err = cdp.Execute(ctx, CommandEnable, p, &res)
  91. if err != nil {
  92. return "", err
  93. }
  94. return res.DebuggerID, nil
  95. }
  96. // EvaluateOnCallFrameParams evaluates expression on a given call frame.
  97. type EvaluateOnCallFrameParams struct {
  98. CallFrameID CallFrameID `json:"callFrameId"` // Call frame identifier to evaluate on.
  99. Expression string `json:"expression"` // Expression to evaluate.
  100. ObjectGroup string `json:"objectGroup,omitempty"` // String object group name to put result into (allows rapid releasing resulting object handles using releaseObjectGroup).
  101. IncludeCommandLineAPI bool `json:"includeCommandLineAPI,omitempty"` // Specifies whether command line API should be available to the evaluated expression, defaults to false.
  102. Silent bool `json:"silent,omitempty"` // In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state.
  103. ReturnByValue bool `json:"returnByValue,omitempty"` // Whether the result is expected to be a JSON object that should be sent by value.
  104. GeneratePreview bool `json:"generatePreview,omitempty"` // Whether preview should be generated for the result.
  105. ThrowOnSideEffect bool `json:"throwOnSideEffect,omitempty"` // Whether to throw an exception if side effect cannot be ruled out during evaluation.
  106. Timeout runtime.TimeDelta `json:"timeout,omitempty"` // Terminate execution after timing out (number of milliseconds).
  107. }
  108. // EvaluateOnCallFrame evaluates expression on a given call frame.
  109. //
  110. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-evaluateOnCallFrame
  111. //
  112. // parameters:
  113. //
  114. // callFrameID - Call frame identifier to evaluate on.
  115. // expression - Expression to evaluate.
  116. func EvaluateOnCallFrame(callFrameID CallFrameID, expression string) *EvaluateOnCallFrameParams {
  117. return &EvaluateOnCallFrameParams{
  118. CallFrameID: callFrameID,
  119. Expression: expression,
  120. }
  121. }
  122. // WithObjectGroup string object group name to put result into (allows rapid
  123. // releasing resulting object handles using releaseObjectGroup).
  124. func (p EvaluateOnCallFrameParams) WithObjectGroup(objectGroup string) *EvaluateOnCallFrameParams {
  125. p.ObjectGroup = objectGroup
  126. return &p
  127. }
  128. // WithIncludeCommandLineAPI specifies whether command line API should be
  129. // available to the evaluated expression, defaults to false.
  130. func (p EvaluateOnCallFrameParams) WithIncludeCommandLineAPI(includeCommandLineAPI bool) *EvaluateOnCallFrameParams {
  131. p.IncludeCommandLineAPI = includeCommandLineAPI
  132. return &p
  133. }
  134. // WithSilent in silent mode exceptions thrown during evaluation are not
  135. // reported and do not pause execution. Overrides setPauseOnException state.
  136. func (p EvaluateOnCallFrameParams) WithSilent(silent bool) *EvaluateOnCallFrameParams {
  137. p.Silent = silent
  138. return &p
  139. }
  140. // WithReturnByValue whether the result is expected to be a JSON object that
  141. // should be sent by value.
  142. func (p EvaluateOnCallFrameParams) WithReturnByValue(returnByValue bool) *EvaluateOnCallFrameParams {
  143. p.ReturnByValue = returnByValue
  144. return &p
  145. }
  146. // WithGeneratePreview whether preview should be generated for the result.
  147. func (p EvaluateOnCallFrameParams) WithGeneratePreview(generatePreview bool) *EvaluateOnCallFrameParams {
  148. p.GeneratePreview = generatePreview
  149. return &p
  150. }
  151. // WithThrowOnSideEffect whether to throw an exception if side effect cannot
  152. // be ruled out during evaluation.
  153. func (p EvaluateOnCallFrameParams) WithThrowOnSideEffect(throwOnSideEffect bool) *EvaluateOnCallFrameParams {
  154. p.ThrowOnSideEffect = throwOnSideEffect
  155. return &p
  156. }
  157. // WithTimeout terminate execution after timing out (number of milliseconds).
  158. func (p EvaluateOnCallFrameParams) WithTimeout(timeout runtime.TimeDelta) *EvaluateOnCallFrameParams {
  159. p.Timeout = timeout
  160. return &p
  161. }
  162. // EvaluateOnCallFrameReturns return values.
  163. type EvaluateOnCallFrameReturns struct {
  164. Result *runtime.RemoteObject `json:"result,omitempty"` // Object wrapper for the evaluation result.
  165. ExceptionDetails *runtime.ExceptionDetails `json:"exceptionDetails,omitempty"` // Exception details.
  166. }
  167. // Do executes Debugger.evaluateOnCallFrame against the provided context.
  168. //
  169. // returns:
  170. //
  171. // result - Object wrapper for the evaluation result.
  172. // exceptionDetails - Exception details.
  173. func (p *EvaluateOnCallFrameParams) Do(ctx context.Context) (result *runtime.RemoteObject, exceptionDetails *runtime.ExceptionDetails, err error) {
  174. // execute
  175. var res EvaluateOnCallFrameReturns
  176. err = cdp.Execute(ctx, CommandEvaluateOnCallFrame, p, &res)
  177. if err != nil {
  178. return nil, nil, err
  179. }
  180. return res.Result, res.ExceptionDetails, nil
  181. }
  182. // GetPossibleBreakpointsParams returns possible locations for breakpoint.
  183. // scriptId in start and end range locations should be the same.
  184. type GetPossibleBreakpointsParams struct {
  185. Start *Location `json:"start"` // Start of range to search possible breakpoint locations in.
  186. End *Location `json:"end,omitempty"` // End of range to search possible breakpoint locations in (excluding). When not specified, end of scripts is used as end of range.
  187. RestrictToFunction bool `json:"restrictToFunction,omitempty"` // Only consider locations which are in the same (non-nested) function as start.
  188. }
  189. // GetPossibleBreakpoints returns possible locations for breakpoint. scriptId
  190. // in start and end range locations should be the same.
  191. //
  192. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-getPossibleBreakpoints
  193. //
  194. // parameters:
  195. //
  196. // start - Start of range to search possible breakpoint locations in.
  197. func GetPossibleBreakpoints(start *Location) *GetPossibleBreakpointsParams {
  198. return &GetPossibleBreakpointsParams{
  199. Start: start,
  200. }
  201. }
  202. // WithEnd end of range to search possible breakpoint locations in
  203. // (excluding). When not specified, end of scripts is used as end of range.
  204. func (p GetPossibleBreakpointsParams) WithEnd(end *Location) *GetPossibleBreakpointsParams {
  205. p.End = end
  206. return &p
  207. }
  208. // WithRestrictToFunction only consider locations which are in the same
  209. // (non-nested) function as start.
  210. func (p GetPossibleBreakpointsParams) WithRestrictToFunction(restrictToFunction bool) *GetPossibleBreakpointsParams {
  211. p.RestrictToFunction = restrictToFunction
  212. return &p
  213. }
  214. // GetPossibleBreakpointsReturns return values.
  215. type GetPossibleBreakpointsReturns struct {
  216. Locations []*BreakLocation `json:"locations,omitempty"` // List of the possible breakpoint locations.
  217. }
  218. // Do executes Debugger.getPossibleBreakpoints against the provided context.
  219. //
  220. // returns:
  221. //
  222. // locations - List of the possible breakpoint locations.
  223. func (p *GetPossibleBreakpointsParams) Do(ctx context.Context) (locations []*BreakLocation, err error) {
  224. // execute
  225. var res GetPossibleBreakpointsReturns
  226. err = cdp.Execute(ctx, CommandGetPossibleBreakpoints, p, &res)
  227. if err != nil {
  228. return nil, err
  229. }
  230. return res.Locations, nil
  231. }
  232. // GetScriptSourceParams returns source for the script with given id.
  233. type GetScriptSourceParams struct {
  234. ScriptID runtime.ScriptID `json:"scriptId"` // Id of the script to get source for.
  235. }
  236. // GetScriptSource returns source for the script with given id.
  237. //
  238. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-getScriptSource
  239. //
  240. // parameters:
  241. //
  242. // scriptID - Id of the script to get source for.
  243. func GetScriptSource(scriptID runtime.ScriptID) *GetScriptSourceParams {
  244. return &GetScriptSourceParams{
  245. ScriptID: scriptID,
  246. }
  247. }
  248. // GetScriptSourceReturns return values.
  249. type GetScriptSourceReturns struct {
  250. ScriptSource string `json:"scriptSource,omitempty"` // Script source (empty in case of Wasm bytecode).
  251. Bytecode string `json:"bytecode,omitempty"` // Wasm bytecode.
  252. }
  253. // Do executes Debugger.getScriptSource against the provided context.
  254. //
  255. // returns:
  256. //
  257. // scriptSource - Script source (empty in case of Wasm bytecode).
  258. // bytecode - Wasm bytecode.
  259. func (p *GetScriptSourceParams) Do(ctx context.Context) (scriptSource string, bytecode []byte, err error) {
  260. // execute
  261. var res GetScriptSourceReturns
  262. err = cdp.Execute(ctx, CommandGetScriptSource, p, &res)
  263. if err != nil {
  264. return "", nil, err
  265. }
  266. // decode
  267. var dec []byte
  268. dec, err = base64.StdEncoding.DecodeString(res.Bytecode)
  269. if err != nil {
  270. return "", nil, err
  271. }
  272. return res.ScriptSource, dec, nil
  273. }
  274. // DisassembleWasmModuleParams [no description].
  275. type DisassembleWasmModuleParams struct {
  276. ScriptID runtime.ScriptID `json:"scriptId"` // Id of the script to disassemble
  277. }
  278. // DisassembleWasmModule [no description].
  279. //
  280. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-disassembleWasmModule
  281. //
  282. // parameters:
  283. //
  284. // scriptID - Id of the script to disassemble
  285. func DisassembleWasmModule(scriptID runtime.ScriptID) *DisassembleWasmModuleParams {
  286. return &DisassembleWasmModuleParams{
  287. ScriptID: scriptID,
  288. }
  289. }
  290. // DisassembleWasmModuleReturns return values.
  291. type DisassembleWasmModuleReturns struct {
  292. StreamID string `json:"streamId,omitempty"` // For large modules, return a stream from which additional chunks of disassembly can be read successively.
  293. TotalNumberOfLines int64 `json:"totalNumberOfLines,omitempty"` // The total number of lines in the disassembly text.
  294. FunctionBodyOffsets []int64 `json:"functionBodyOffsets,omitempty"` // The offsets of all function bodies, in the format [start1, end1, start2, end2, ...] where all ends are exclusive.
  295. Chunk *WasmDisassemblyChunk `json:"chunk,omitempty"` // The first chunk of disassembly.
  296. }
  297. // Do executes Debugger.disassembleWasmModule against the provided context.
  298. //
  299. // returns:
  300. //
  301. // streamID - For large modules, return a stream from which additional chunks of disassembly can be read successively.
  302. // totalNumberOfLines - The total number of lines in the disassembly text.
  303. // functionBodyOffsets - The offsets of all function bodies, in the format [start1, end1, start2, end2, ...] where all ends are exclusive.
  304. // chunk - The first chunk of disassembly.
  305. func (p *DisassembleWasmModuleParams) Do(ctx context.Context) (streamID string, totalNumberOfLines int64, functionBodyOffsets []int64, chunk *WasmDisassemblyChunk, err error) {
  306. // execute
  307. var res DisassembleWasmModuleReturns
  308. err = cdp.Execute(ctx, CommandDisassembleWasmModule, p, &res)
  309. if err != nil {
  310. return "", 0, nil, nil, err
  311. }
  312. return res.StreamID, res.TotalNumberOfLines, res.FunctionBodyOffsets, res.Chunk, nil
  313. }
  314. // NextWasmDisassemblyChunkParams disassemble the next chunk of lines for the
  315. // module corresponding to the stream. If disassembly is complete, this API will
  316. // invalidate the streamId and return an empty chunk. Any subsequent calls for
  317. // the now invalid stream will return errors.
  318. type NextWasmDisassemblyChunkParams struct {
  319. StreamID string `json:"streamId"`
  320. }
  321. // NextWasmDisassemblyChunk disassemble the next chunk of lines for the
  322. // module corresponding to the stream. If disassembly is complete, this API will
  323. // invalidate the streamId and return an empty chunk. Any subsequent calls for
  324. // the now invalid stream will return errors.
  325. //
  326. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-nextWasmDisassemblyChunk
  327. //
  328. // parameters:
  329. //
  330. // streamID
  331. func NextWasmDisassemblyChunk(streamID string) *NextWasmDisassemblyChunkParams {
  332. return &NextWasmDisassemblyChunkParams{
  333. StreamID: streamID,
  334. }
  335. }
  336. // NextWasmDisassemblyChunkReturns return values.
  337. type NextWasmDisassemblyChunkReturns struct {
  338. Chunk *WasmDisassemblyChunk `json:"chunk,omitempty"` // The next chunk of disassembly.
  339. }
  340. // Do executes Debugger.nextWasmDisassemblyChunk against the provided context.
  341. //
  342. // returns:
  343. //
  344. // chunk - The next chunk of disassembly.
  345. func (p *NextWasmDisassemblyChunkParams) Do(ctx context.Context) (chunk *WasmDisassemblyChunk, err error) {
  346. // execute
  347. var res NextWasmDisassemblyChunkReturns
  348. err = cdp.Execute(ctx, CommandNextWasmDisassemblyChunk, p, &res)
  349. if err != nil {
  350. return nil, err
  351. }
  352. return res.Chunk, nil
  353. }
  354. // GetStackTraceParams returns stack trace with given stackTraceId.
  355. type GetStackTraceParams struct {
  356. StackTraceID *runtime.StackTraceID `json:"stackTraceId"`
  357. }
  358. // GetStackTrace returns stack trace with given stackTraceId.
  359. //
  360. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-getStackTrace
  361. //
  362. // parameters:
  363. //
  364. // stackTraceID
  365. func GetStackTrace(stackTraceID *runtime.StackTraceID) *GetStackTraceParams {
  366. return &GetStackTraceParams{
  367. StackTraceID: stackTraceID,
  368. }
  369. }
  370. // GetStackTraceReturns return values.
  371. type GetStackTraceReturns struct {
  372. StackTrace *runtime.StackTrace `json:"stackTrace,omitempty"`
  373. }
  374. // Do executes Debugger.getStackTrace against the provided context.
  375. //
  376. // returns:
  377. //
  378. // stackTrace
  379. func (p *GetStackTraceParams) Do(ctx context.Context) (stackTrace *runtime.StackTrace, err error) {
  380. // execute
  381. var res GetStackTraceReturns
  382. err = cdp.Execute(ctx, CommandGetStackTrace, p, &res)
  383. if err != nil {
  384. return nil, err
  385. }
  386. return res.StackTrace, nil
  387. }
  388. // PauseParams stops on the next JavaScript statement.
  389. type PauseParams struct{}
  390. // Pause stops on the next JavaScript statement.
  391. //
  392. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-pause
  393. func Pause() *PauseParams {
  394. return &PauseParams{}
  395. }
  396. // Do executes Debugger.pause against the provided context.
  397. func (p *PauseParams) Do(ctx context.Context) (err error) {
  398. return cdp.Execute(ctx, CommandPause, nil, nil)
  399. }
  400. // RemoveBreakpointParams removes JavaScript breakpoint.
  401. type RemoveBreakpointParams struct {
  402. BreakpointID BreakpointID `json:"breakpointId"`
  403. }
  404. // RemoveBreakpoint removes JavaScript breakpoint.
  405. //
  406. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-removeBreakpoint
  407. //
  408. // parameters:
  409. //
  410. // breakpointID
  411. func RemoveBreakpoint(breakpointID BreakpointID) *RemoveBreakpointParams {
  412. return &RemoveBreakpointParams{
  413. BreakpointID: breakpointID,
  414. }
  415. }
  416. // Do executes Debugger.removeBreakpoint against the provided context.
  417. func (p *RemoveBreakpointParams) Do(ctx context.Context) (err error) {
  418. return cdp.Execute(ctx, CommandRemoveBreakpoint, p, nil)
  419. }
  420. // RestartFrameParams restarts particular call frame from the beginning. The
  421. // old, deprecated behavior of restartFrame is to stay paused and allow further
  422. // CDP commands after a restart was scheduled. This can cause problems with
  423. // restarting, so we now continue execution immediately after it has been
  424. // scheduled until we reach the beginning of the restarted frame. To stay
  425. // back-wards compatible, restartFrame now expects a mode parameter to be
  426. // present. If the mode parameter is missing, restartFrame errors out. The
  427. // various return values are deprecated and callFrames is always empty. Use the
  428. // call frames from the Debugger#paused events instead, that fires once V8
  429. // pauses at the beginning of the restarted function.
  430. type RestartFrameParams struct {
  431. CallFrameID CallFrameID `json:"callFrameId"` // Call frame identifier to evaluate on.
  432. Mode RestartFrameMode `json:"mode,omitempty"` // The mode parameter must be present and set to 'StepInto', otherwise restartFrame will error out.
  433. }
  434. // RestartFrame restarts particular call frame from the beginning. The old,
  435. // deprecated behavior of restartFrame is to stay paused and allow further CDP
  436. // commands after a restart was scheduled. This can cause problems with
  437. // restarting, so we now continue execution immediately after it has been
  438. // scheduled until we reach the beginning of the restarted frame. To stay
  439. // back-wards compatible, restartFrame now expects a mode parameter to be
  440. // present. If the mode parameter is missing, restartFrame errors out. The
  441. // various return values are deprecated and callFrames is always empty. Use the
  442. // call frames from the Debugger#paused events instead, that fires once V8
  443. // pauses at the beginning of the restarted function.
  444. //
  445. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-restartFrame
  446. //
  447. // parameters:
  448. //
  449. // callFrameID - Call frame identifier to evaluate on.
  450. func RestartFrame(callFrameID CallFrameID) *RestartFrameParams {
  451. return &RestartFrameParams{
  452. CallFrameID: callFrameID,
  453. }
  454. }
  455. // WithMode the mode parameter must be present and set to 'StepInto',
  456. // otherwise restartFrame will error out.
  457. func (p RestartFrameParams) WithMode(mode RestartFrameMode) *RestartFrameParams {
  458. p.Mode = mode
  459. return &p
  460. }
  461. // Do executes Debugger.restartFrame against the provided context.
  462. func (p *RestartFrameParams) Do(ctx context.Context) (err error) {
  463. return cdp.Execute(ctx, CommandRestartFrame, p, nil)
  464. }
  465. // ResumeParams resumes JavaScript execution.
  466. type ResumeParams struct {
  467. TerminateOnResume bool `json:"terminateOnResume,omitempty"` // Set to true to terminate execution upon resuming execution. In contrast to Runtime.terminateExecution, this will allows to execute further JavaScript (i.e. via evaluation) until execution of the paused code is actually resumed, at which point termination is triggered. If execution is currently not paused, this parameter has no effect.
  468. }
  469. // Resume resumes JavaScript execution.
  470. //
  471. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-resume
  472. //
  473. // parameters:
  474. func Resume() *ResumeParams {
  475. return &ResumeParams{}
  476. }
  477. // WithTerminateOnResume set to true to terminate execution upon resuming
  478. // execution. In contrast to Runtime.terminateExecution, this will allows to
  479. // execute further JavaScript (i.e. via evaluation) until execution of the
  480. // paused code is actually resumed, at which point termination is triggered. If
  481. // execution is currently not paused, this parameter has no effect.
  482. func (p ResumeParams) WithTerminateOnResume(terminateOnResume bool) *ResumeParams {
  483. p.TerminateOnResume = terminateOnResume
  484. return &p
  485. }
  486. // Do executes Debugger.resume against the provided context.
  487. func (p *ResumeParams) Do(ctx context.Context) (err error) {
  488. return cdp.Execute(ctx, CommandResume, p, nil)
  489. }
  490. // SearchInContentParams searches for given string in script content.
  491. type SearchInContentParams struct {
  492. ScriptID runtime.ScriptID `json:"scriptId"` // Id of the script to search in.
  493. Query string `json:"query"` // String to search for.
  494. CaseSensitive bool `json:"caseSensitive,omitempty"` // If true, search is case sensitive.
  495. IsRegex bool `json:"isRegex,omitempty"` // If true, treats string parameter as regex.
  496. }
  497. // SearchInContent searches for given string in script content.
  498. //
  499. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-searchInContent
  500. //
  501. // parameters:
  502. //
  503. // scriptID - Id of the script to search in.
  504. // query - String to search for.
  505. func SearchInContent(scriptID runtime.ScriptID, query string) *SearchInContentParams {
  506. return &SearchInContentParams{
  507. ScriptID: scriptID,
  508. Query: query,
  509. }
  510. }
  511. // WithCaseSensitive if true, search is case sensitive.
  512. func (p SearchInContentParams) WithCaseSensitive(caseSensitive bool) *SearchInContentParams {
  513. p.CaseSensitive = caseSensitive
  514. return &p
  515. }
  516. // WithIsRegex if true, treats string parameter as regex.
  517. func (p SearchInContentParams) WithIsRegex(isRegex bool) *SearchInContentParams {
  518. p.IsRegex = isRegex
  519. return &p
  520. }
  521. // SearchInContentReturns return values.
  522. type SearchInContentReturns struct {
  523. Result []*SearchMatch `json:"result,omitempty"` // List of search matches.
  524. }
  525. // Do executes Debugger.searchInContent against the provided context.
  526. //
  527. // returns:
  528. //
  529. // result - List of search matches.
  530. func (p *SearchInContentParams) Do(ctx context.Context) (result []*SearchMatch, err error) {
  531. // execute
  532. var res SearchInContentReturns
  533. err = cdp.Execute(ctx, CommandSearchInContent, p, &res)
  534. if err != nil {
  535. return nil, err
  536. }
  537. return res.Result, nil
  538. }
  539. // SetAsyncCallStackDepthParams enables or disables async call stacks
  540. // tracking.
  541. type SetAsyncCallStackDepthParams struct {
  542. MaxDepth int64 `json:"maxDepth"` // Maximum depth of async call stacks. Setting to 0 will effectively disable collecting async call stacks (default).
  543. }
  544. // SetAsyncCallStackDepth enables or disables async call stacks tracking.
  545. //
  546. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setAsyncCallStackDepth
  547. //
  548. // parameters:
  549. //
  550. // maxDepth - Maximum depth of async call stacks. Setting to 0 will effectively disable collecting async call stacks (default).
  551. func SetAsyncCallStackDepth(maxDepth int64) *SetAsyncCallStackDepthParams {
  552. return &SetAsyncCallStackDepthParams{
  553. MaxDepth: maxDepth,
  554. }
  555. }
  556. // Do executes Debugger.setAsyncCallStackDepth against the provided context.
  557. func (p *SetAsyncCallStackDepthParams) Do(ctx context.Context) (err error) {
  558. return cdp.Execute(ctx, CommandSetAsyncCallStackDepth, p, nil)
  559. }
  560. // SetBlackboxPatternsParams replace previous blackbox patterns with passed
  561. // ones. Forces backend to skip stepping/pausing in scripts with url matching
  562. // one of the patterns. VM will try to leave blackboxed script by performing
  563. // 'step in' several times, finally resorting to 'step out' if unsuccessful.
  564. type SetBlackboxPatternsParams struct {
  565. Patterns []string `json:"patterns"` // Array of regexps that will be used to check script url for blackbox state.
  566. }
  567. // SetBlackboxPatterns replace previous blackbox patterns with passed ones.
  568. // Forces backend to skip stepping/pausing in scripts with url matching one of
  569. // the patterns. VM will try to leave blackboxed script by performing 'step in'
  570. // several times, finally resorting to 'step out' if unsuccessful.
  571. //
  572. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setBlackboxPatterns
  573. //
  574. // parameters:
  575. //
  576. // patterns - Array of regexps that will be used to check script url for blackbox state.
  577. func SetBlackboxPatterns(patterns []string) *SetBlackboxPatternsParams {
  578. return &SetBlackboxPatternsParams{
  579. Patterns: patterns,
  580. }
  581. }
  582. // Do executes Debugger.setBlackboxPatterns against the provided context.
  583. func (p *SetBlackboxPatternsParams) Do(ctx context.Context) (err error) {
  584. return cdp.Execute(ctx, CommandSetBlackboxPatterns, p, nil)
  585. }
  586. // SetBlackboxedRangesParams makes backend skip steps in the script in
  587. // blackboxed ranges. VM will try leave blacklisted scripts by performing 'step
  588. // in' several times, finally resorting to 'step out' if unsuccessful. Positions
  589. // array contains positions where blackbox state is changed. First interval
  590. // isn't blackboxed. Array should be sorted.
  591. type SetBlackboxedRangesParams struct {
  592. ScriptID runtime.ScriptID `json:"scriptId"` // Id of the script.
  593. Positions []*ScriptPosition `json:"positions"`
  594. }
  595. // SetBlackboxedRanges makes backend skip steps in the script in blackboxed
  596. // ranges. VM will try leave blacklisted scripts by performing 'step in' several
  597. // times, finally resorting to 'step out' if unsuccessful. Positions array
  598. // contains positions where blackbox state is changed. First interval isn't
  599. // blackboxed. Array should be sorted.
  600. //
  601. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setBlackboxedRanges
  602. //
  603. // parameters:
  604. //
  605. // scriptID - Id of the script.
  606. // positions
  607. func SetBlackboxedRanges(scriptID runtime.ScriptID, positions []*ScriptPosition) *SetBlackboxedRangesParams {
  608. return &SetBlackboxedRangesParams{
  609. ScriptID: scriptID,
  610. Positions: positions,
  611. }
  612. }
  613. // Do executes Debugger.setBlackboxedRanges against the provided context.
  614. func (p *SetBlackboxedRangesParams) Do(ctx context.Context) (err error) {
  615. return cdp.Execute(ctx, CommandSetBlackboxedRanges, p, nil)
  616. }
  617. // SetBreakpointParams sets JavaScript breakpoint at a given location.
  618. type SetBreakpointParams struct {
  619. Location *Location `json:"location"` // Location to set breakpoint in.
  620. Condition string `json:"condition,omitempty"` // Expression to use as a breakpoint condition. When specified, debugger will only stop on the breakpoint if this expression evaluates to true.
  621. }
  622. // SetBreakpoint sets JavaScript breakpoint at a given location.
  623. //
  624. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setBreakpoint
  625. //
  626. // parameters:
  627. //
  628. // location - Location to set breakpoint in.
  629. func SetBreakpoint(location *Location) *SetBreakpointParams {
  630. return &SetBreakpointParams{
  631. Location: location,
  632. }
  633. }
  634. // WithCondition expression to use as a breakpoint condition. When specified,
  635. // debugger will only stop on the breakpoint if this expression evaluates to
  636. // true.
  637. func (p SetBreakpointParams) WithCondition(condition string) *SetBreakpointParams {
  638. p.Condition = condition
  639. return &p
  640. }
  641. // SetBreakpointReturns return values.
  642. type SetBreakpointReturns struct {
  643. BreakpointID BreakpointID `json:"breakpointId,omitempty"` // Id of the created breakpoint for further reference.
  644. ActualLocation *Location `json:"actualLocation,omitempty"` // Location this breakpoint resolved into.
  645. }
  646. // Do executes Debugger.setBreakpoint against the provided context.
  647. //
  648. // returns:
  649. //
  650. // breakpointID - Id of the created breakpoint for further reference.
  651. // actualLocation - Location this breakpoint resolved into.
  652. func (p *SetBreakpointParams) Do(ctx context.Context) (breakpointID BreakpointID, actualLocation *Location, err error) {
  653. // execute
  654. var res SetBreakpointReturns
  655. err = cdp.Execute(ctx, CommandSetBreakpoint, p, &res)
  656. if err != nil {
  657. return "", nil, err
  658. }
  659. return res.BreakpointID, res.ActualLocation, nil
  660. }
  661. // SetInstrumentationBreakpointParams sets instrumentation breakpoint.
  662. type SetInstrumentationBreakpointParams struct {
  663. Instrumentation SetInstrumentationBreakpointInstrumentation `json:"instrumentation"` // Instrumentation name.
  664. }
  665. // SetInstrumentationBreakpoint sets instrumentation breakpoint.
  666. //
  667. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setInstrumentationBreakpoint
  668. //
  669. // parameters:
  670. //
  671. // instrumentation - Instrumentation name.
  672. func SetInstrumentationBreakpoint(instrumentation SetInstrumentationBreakpointInstrumentation) *SetInstrumentationBreakpointParams {
  673. return &SetInstrumentationBreakpointParams{
  674. Instrumentation: instrumentation,
  675. }
  676. }
  677. // SetInstrumentationBreakpointReturns return values.
  678. type SetInstrumentationBreakpointReturns struct {
  679. BreakpointID BreakpointID `json:"breakpointId,omitempty"` // Id of the created breakpoint for further reference.
  680. }
  681. // Do executes Debugger.setInstrumentationBreakpoint against the provided context.
  682. //
  683. // returns:
  684. //
  685. // breakpointID - Id of the created breakpoint for further reference.
  686. func (p *SetInstrumentationBreakpointParams) Do(ctx context.Context) (breakpointID BreakpointID, err error) {
  687. // execute
  688. var res SetInstrumentationBreakpointReturns
  689. err = cdp.Execute(ctx, CommandSetInstrumentationBreakpoint, p, &res)
  690. if err != nil {
  691. return "", err
  692. }
  693. return res.BreakpointID, nil
  694. }
  695. // SetBreakpointByURLParams sets JavaScript breakpoint at given location
  696. // specified either by URL or URL regex. Once this command is issued, all
  697. // existing parsed scripts will have breakpoints resolved and returned in
  698. // locations property. Further matching script parsing will result in subsequent
  699. // breakpointResolved events issued. This logical breakpoint will survive page
  700. // reloads.
  701. type SetBreakpointByURLParams struct {
  702. LineNumber int64 `json:"lineNumber"` // Line number to set breakpoint at.
  703. URL string `json:"url,omitempty"` // URL of the resources to set breakpoint on.
  704. URLRegex string `json:"urlRegex,omitempty"` // Regex pattern for the URLs of the resources to set breakpoints on. Either url or urlRegex must be specified.
  705. ScriptHash string `json:"scriptHash,omitempty"` // Script hash of the resources to set breakpoint on.
  706. ColumnNumber int64 `json:"columnNumber,omitempty"` // Offset in the line to set breakpoint at.
  707. Condition string `json:"condition,omitempty"` // Expression to use as a breakpoint condition. When specified, debugger will only stop on the breakpoint if this expression evaluates to true.
  708. }
  709. // SetBreakpointByURL sets JavaScript breakpoint at given location specified
  710. // either by URL or URL regex. Once this command is issued, all existing parsed
  711. // scripts will have breakpoints resolved and returned in locations property.
  712. // Further matching script parsing will result in subsequent breakpointResolved
  713. // events issued. This logical breakpoint will survive page reloads.
  714. //
  715. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setBreakpointByUrl
  716. //
  717. // parameters:
  718. //
  719. // lineNumber - Line number to set breakpoint at.
  720. func SetBreakpointByURL(lineNumber int64) *SetBreakpointByURLParams {
  721. return &SetBreakpointByURLParams{
  722. LineNumber: lineNumber,
  723. }
  724. }
  725. // WithURL URL of the resources to set breakpoint on.
  726. func (p SetBreakpointByURLParams) WithURL(url string) *SetBreakpointByURLParams {
  727. p.URL = url
  728. return &p
  729. }
  730. // WithURLRegex regex pattern for the URLs of the resources to set
  731. // breakpoints on. Either url or urlRegex must be specified.
  732. func (p SetBreakpointByURLParams) WithURLRegex(urlRegex string) *SetBreakpointByURLParams {
  733. p.URLRegex = urlRegex
  734. return &p
  735. }
  736. // WithScriptHash script hash of the resources to set breakpoint on.
  737. func (p SetBreakpointByURLParams) WithScriptHash(scriptHash string) *SetBreakpointByURLParams {
  738. p.ScriptHash = scriptHash
  739. return &p
  740. }
  741. // WithColumnNumber offset in the line to set breakpoint at.
  742. func (p SetBreakpointByURLParams) WithColumnNumber(columnNumber int64) *SetBreakpointByURLParams {
  743. p.ColumnNumber = columnNumber
  744. return &p
  745. }
  746. // WithCondition expression to use as a breakpoint condition. When specified,
  747. // debugger will only stop on the breakpoint if this expression evaluates to
  748. // true.
  749. func (p SetBreakpointByURLParams) WithCondition(condition string) *SetBreakpointByURLParams {
  750. p.Condition = condition
  751. return &p
  752. }
  753. // SetBreakpointByURLReturns return values.
  754. type SetBreakpointByURLReturns struct {
  755. BreakpointID BreakpointID `json:"breakpointId,omitempty"` // Id of the created breakpoint for further reference.
  756. Locations []*Location `json:"locations,omitempty"` // List of the locations this breakpoint resolved into upon addition.
  757. }
  758. // Do executes Debugger.setBreakpointByUrl against the provided context.
  759. //
  760. // returns:
  761. //
  762. // breakpointID - Id of the created breakpoint for further reference.
  763. // locations - List of the locations this breakpoint resolved into upon addition.
  764. func (p *SetBreakpointByURLParams) Do(ctx context.Context) (breakpointID BreakpointID, locations []*Location, err error) {
  765. // execute
  766. var res SetBreakpointByURLReturns
  767. err = cdp.Execute(ctx, CommandSetBreakpointByURL, p, &res)
  768. if err != nil {
  769. return "", nil, err
  770. }
  771. return res.BreakpointID, res.Locations, nil
  772. }
  773. // SetBreakpointOnFunctionCallParams sets JavaScript breakpoint before each
  774. // call to the given function. If another function was created from the same
  775. // source as a given one, calling it will also trigger the breakpoint.
  776. type SetBreakpointOnFunctionCallParams struct {
  777. ObjectID runtime.RemoteObjectID `json:"objectId"` // Function object id.
  778. Condition string `json:"condition,omitempty"` // Expression to use as a breakpoint condition. When specified, debugger will stop on the breakpoint if this expression evaluates to true.
  779. }
  780. // SetBreakpointOnFunctionCall sets JavaScript breakpoint before each call to
  781. // the given function. If another function was created from the same source as a
  782. // given one, calling it will also trigger the breakpoint.
  783. //
  784. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setBreakpointOnFunctionCall
  785. //
  786. // parameters:
  787. //
  788. // objectID - Function object id.
  789. func SetBreakpointOnFunctionCall(objectID runtime.RemoteObjectID) *SetBreakpointOnFunctionCallParams {
  790. return &SetBreakpointOnFunctionCallParams{
  791. ObjectID: objectID,
  792. }
  793. }
  794. // WithCondition expression to use as a breakpoint condition. When specified,
  795. // debugger will stop on the breakpoint if this expression evaluates to true.
  796. func (p SetBreakpointOnFunctionCallParams) WithCondition(condition string) *SetBreakpointOnFunctionCallParams {
  797. p.Condition = condition
  798. return &p
  799. }
  800. // SetBreakpointOnFunctionCallReturns return values.
  801. type SetBreakpointOnFunctionCallReturns struct {
  802. BreakpointID BreakpointID `json:"breakpointId,omitempty"` // Id of the created breakpoint for further reference.
  803. }
  804. // Do executes Debugger.setBreakpointOnFunctionCall against the provided context.
  805. //
  806. // returns:
  807. //
  808. // breakpointID - Id of the created breakpoint for further reference.
  809. func (p *SetBreakpointOnFunctionCallParams) Do(ctx context.Context) (breakpointID BreakpointID, err error) {
  810. // execute
  811. var res SetBreakpointOnFunctionCallReturns
  812. err = cdp.Execute(ctx, CommandSetBreakpointOnFunctionCall, p, &res)
  813. if err != nil {
  814. return "", err
  815. }
  816. return res.BreakpointID, nil
  817. }
  818. // SetBreakpointsActiveParams activates / deactivates all breakpoints on the
  819. // page.
  820. type SetBreakpointsActiveParams struct {
  821. Active bool `json:"active"` // New value for breakpoints active state.
  822. }
  823. // SetBreakpointsActive activates / deactivates all breakpoints on the page.
  824. //
  825. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setBreakpointsActive
  826. //
  827. // parameters:
  828. //
  829. // active - New value for breakpoints active state.
  830. func SetBreakpointsActive(active bool) *SetBreakpointsActiveParams {
  831. return &SetBreakpointsActiveParams{
  832. Active: active,
  833. }
  834. }
  835. // Do executes Debugger.setBreakpointsActive against the provided context.
  836. func (p *SetBreakpointsActiveParams) Do(ctx context.Context) (err error) {
  837. return cdp.Execute(ctx, CommandSetBreakpointsActive, p, nil)
  838. }
  839. // SetPauseOnExceptionsParams defines pause on exceptions state. Can be set
  840. // to stop on all exceptions, uncaught exceptions, or caught exceptions, no
  841. // exceptions. Initial pause on exceptions state is none.
  842. type SetPauseOnExceptionsParams struct {
  843. State ExceptionsState `json:"state"` // Pause on exceptions mode.
  844. }
  845. // SetPauseOnExceptions defines pause on exceptions state. Can be set to stop
  846. // on all exceptions, uncaught exceptions, or caught exceptions, no exceptions.
  847. // Initial pause on exceptions state is none.
  848. //
  849. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setPauseOnExceptions
  850. //
  851. // parameters:
  852. //
  853. // state - Pause on exceptions mode.
  854. func SetPauseOnExceptions(state ExceptionsState) *SetPauseOnExceptionsParams {
  855. return &SetPauseOnExceptionsParams{
  856. State: state,
  857. }
  858. }
  859. // Do executes Debugger.setPauseOnExceptions against the provided context.
  860. func (p *SetPauseOnExceptionsParams) Do(ctx context.Context) (err error) {
  861. return cdp.Execute(ctx, CommandSetPauseOnExceptions, p, nil)
  862. }
  863. // SetReturnValueParams changes return value in top frame. Available only at
  864. // return break position.
  865. type SetReturnValueParams struct {
  866. NewValue *runtime.CallArgument `json:"newValue"` // New return value.
  867. }
  868. // SetReturnValue changes return value in top frame. Available only at return
  869. // break position.
  870. //
  871. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setReturnValue
  872. //
  873. // parameters:
  874. //
  875. // newValue - New return value.
  876. func SetReturnValue(newValue *runtime.CallArgument) *SetReturnValueParams {
  877. return &SetReturnValueParams{
  878. NewValue: newValue,
  879. }
  880. }
  881. // Do executes Debugger.setReturnValue against the provided context.
  882. func (p *SetReturnValueParams) Do(ctx context.Context) (err error) {
  883. return cdp.Execute(ctx, CommandSetReturnValue, p, nil)
  884. }
  885. // SetScriptSourceParams edits JavaScript source live. In general, functions
  886. // that are currently on the stack can not be edited with a single exception: If
  887. // the edited function is the top-most stack frame and that is the only
  888. // activation of that function on the stack. In this case the live edit will be
  889. // successful and a Debugger.restartFrame for the top-most function is
  890. // automatically triggered.
  891. type SetScriptSourceParams struct {
  892. ScriptID runtime.ScriptID `json:"scriptId"` // Id of the script to edit.
  893. ScriptSource string `json:"scriptSource"` // New content of the script.
  894. DryRun bool `json:"dryRun,omitempty"` // If true the change will not actually be applied. Dry run may be used to get result description without actually modifying the code.
  895. AllowTopFrameEditing bool `json:"allowTopFrameEditing,omitempty"` // If true, then scriptSource is allowed to change the function on top of the stack as long as the top-most stack frame is the only activation of that function.
  896. }
  897. // SetScriptSource edits JavaScript source live. In general, functions that
  898. // are currently on the stack can not be edited with a single exception: If the
  899. // edited function is the top-most stack frame and that is the only activation
  900. // of that function on the stack. In this case the live edit will be successful
  901. // and a Debugger.restartFrame for the top-most function is automatically
  902. // triggered.
  903. //
  904. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setScriptSource
  905. //
  906. // parameters:
  907. //
  908. // scriptID - Id of the script to edit.
  909. // scriptSource - New content of the script.
  910. func SetScriptSource(scriptID runtime.ScriptID, scriptSource string) *SetScriptSourceParams {
  911. return &SetScriptSourceParams{
  912. ScriptID: scriptID,
  913. ScriptSource: scriptSource,
  914. }
  915. }
  916. // WithDryRun if true the change will not actually be applied. Dry run may be
  917. // used to get result description without actually modifying the code.
  918. func (p SetScriptSourceParams) WithDryRun(dryRun bool) *SetScriptSourceParams {
  919. p.DryRun = dryRun
  920. return &p
  921. }
  922. // WithAllowTopFrameEditing if true, then scriptSource is allowed to change
  923. // the function on top of the stack as long as the top-most stack frame is the
  924. // only activation of that function.
  925. func (p SetScriptSourceParams) WithAllowTopFrameEditing(allowTopFrameEditing bool) *SetScriptSourceParams {
  926. p.AllowTopFrameEditing = allowTopFrameEditing
  927. return &p
  928. }
  929. // SetScriptSourceReturns return values.
  930. type SetScriptSourceReturns struct {
  931. Status SetScriptSourceStatus `json:"status,omitempty"` // Whether the operation was successful or not. Only Ok denotes a successful live edit while the other enum variants denote why the live edit failed.
  932. ExceptionDetails *runtime.ExceptionDetails `json:"exceptionDetails,omitempty"` // Exception details if any. Only present when status is CompileError.
  933. }
  934. // Do executes Debugger.setScriptSource against the provided context.
  935. //
  936. // returns:
  937. //
  938. // status - Whether the operation was successful or not. Only Ok denotes a successful live edit while the other enum variants denote why the live edit failed.
  939. // exceptionDetails - Exception details if any. Only present when status is CompileError.
  940. func (p *SetScriptSourceParams) Do(ctx context.Context) (status SetScriptSourceStatus, exceptionDetails *runtime.ExceptionDetails, err error) {
  941. // execute
  942. var res SetScriptSourceReturns
  943. err = cdp.Execute(ctx, CommandSetScriptSource, p, &res)
  944. if err != nil {
  945. return "", nil, err
  946. }
  947. return res.Status, res.ExceptionDetails, nil
  948. }
  949. // SetSkipAllPausesParams makes page not interrupt on any pauses (breakpoint,
  950. // exception, dom exception etc).
  951. type SetSkipAllPausesParams struct {
  952. Skip bool `json:"skip"` // New value for skip pauses state.
  953. }
  954. // SetSkipAllPauses makes page not interrupt on any pauses (breakpoint,
  955. // exception, dom exception etc).
  956. //
  957. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setSkipAllPauses
  958. //
  959. // parameters:
  960. //
  961. // skip - New value for skip pauses state.
  962. func SetSkipAllPauses(skip bool) *SetSkipAllPausesParams {
  963. return &SetSkipAllPausesParams{
  964. Skip: skip,
  965. }
  966. }
  967. // Do executes Debugger.setSkipAllPauses against the provided context.
  968. func (p *SetSkipAllPausesParams) Do(ctx context.Context) (err error) {
  969. return cdp.Execute(ctx, CommandSetSkipAllPauses, p, nil)
  970. }
  971. // SetVariableValueParams changes value of variable in a callframe.
  972. // Object-based scopes are not supported and must be mutated manually.
  973. type SetVariableValueParams struct {
  974. ScopeNumber int64 `json:"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.
  975. VariableName string `json:"variableName"` // Variable name.
  976. NewValue *runtime.CallArgument `json:"newValue"` // New variable value.
  977. CallFrameID CallFrameID `json:"callFrameId"` // Id of callframe that holds variable.
  978. }
  979. // SetVariableValue changes value of variable in a callframe. Object-based
  980. // scopes are not supported and must be mutated manually.
  981. //
  982. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-setVariableValue
  983. //
  984. // parameters:
  985. //
  986. // 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.
  987. // variableName - Variable name.
  988. // newValue - New variable value.
  989. // callFrameID - Id of callframe that holds variable.
  990. func SetVariableValue(scopeNumber int64, variableName string, newValue *runtime.CallArgument, callFrameID CallFrameID) *SetVariableValueParams {
  991. return &SetVariableValueParams{
  992. ScopeNumber: scopeNumber,
  993. VariableName: variableName,
  994. NewValue: newValue,
  995. CallFrameID: callFrameID,
  996. }
  997. }
  998. // Do executes Debugger.setVariableValue against the provided context.
  999. func (p *SetVariableValueParams) Do(ctx context.Context) (err error) {
  1000. return cdp.Execute(ctx, CommandSetVariableValue, p, nil)
  1001. }
  1002. // StepIntoParams steps into the function call.
  1003. type StepIntoParams struct {
  1004. BreakOnAsyncCall bool `json:"breakOnAsyncCall,omitempty"` // Debugger will pause on the execution of the first async task which was scheduled before next pause.
  1005. SkipList []*LocationRange `json:"skipList,omitempty"` // The skipList specifies location ranges that should be skipped on step into.
  1006. }
  1007. // StepInto steps into the function call.
  1008. //
  1009. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-stepInto
  1010. //
  1011. // parameters:
  1012. func StepInto() *StepIntoParams {
  1013. return &StepIntoParams{}
  1014. }
  1015. // WithBreakOnAsyncCall debugger will pause on the execution of the first
  1016. // async task which was scheduled before next pause.
  1017. func (p StepIntoParams) WithBreakOnAsyncCall(breakOnAsyncCall bool) *StepIntoParams {
  1018. p.BreakOnAsyncCall = breakOnAsyncCall
  1019. return &p
  1020. }
  1021. // WithSkipList the skipList specifies location ranges that should be skipped
  1022. // on step into.
  1023. func (p StepIntoParams) WithSkipList(skipList []*LocationRange) *StepIntoParams {
  1024. p.SkipList = skipList
  1025. return &p
  1026. }
  1027. // Do executes Debugger.stepInto against the provided context.
  1028. func (p *StepIntoParams) Do(ctx context.Context) (err error) {
  1029. return cdp.Execute(ctx, CommandStepInto, p, nil)
  1030. }
  1031. // StepOutParams steps out of the function call.
  1032. type StepOutParams struct{}
  1033. // StepOut steps out of the function call.
  1034. //
  1035. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-stepOut
  1036. func StepOut() *StepOutParams {
  1037. return &StepOutParams{}
  1038. }
  1039. // Do executes Debugger.stepOut against the provided context.
  1040. func (p *StepOutParams) Do(ctx context.Context) (err error) {
  1041. return cdp.Execute(ctx, CommandStepOut, nil, nil)
  1042. }
  1043. // StepOverParams steps over the statement.
  1044. type StepOverParams struct {
  1045. SkipList []*LocationRange `json:"skipList,omitempty"` // The skipList specifies location ranges that should be skipped on step over.
  1046. }
  1047. // StepOver steps over the statement.
  1048. //
  1049. // See: https://chromedevtools.github.io/devtools-protocol/tot/Debugger#method-stepOver
  1050. //
  1051. // parameters:
  1052. func StepOver() *StepOverParams {
  1053. return &StepOverParams{}
  1054. }
  1055. // WithSkipList the skipList specifies location ranges that should be skipped
  1056. // on step over.
  1057. func (p StepOverParams) WithSkipList(skipList []*LocationRange) *StepOverParams {
  1058. p.SkipList = skipList
  1059. return &p
  1060. }
  1061. // Do executes Debugger.stepOver against the provided context.
  1062. func (p *StepOverParams) Do(ctx context.Context) (err error) {
  1063. return cdp.Execute(ctx, CommandStepOver, p, nil)
  1064. }
  1065. // Command names.
  1066. const (
  1067. CommandContinueToLocation = "Debugger.continueToLocation"
  1068. CommandDisable = "Debugger.disable"
  1069. CommandEnable = "Debugger.enable"
  1070. CommandEvaluateOnCallFrame = "Debugger.evaluateOnCallFrame"
  1071. CommandGetPossibleBreakpoints = "Debugger.getPossibleBreakpoints"
  1072. CommandGetScriptSource = "Debugger.getScriptSource"
  1073. CommandDisassembleWasmModule = "Debugger.disassembleWasmModule"
  1074. CommandNextWasmDisassemblyChunk = "Debugger.nextWasmDisassemblyChunk"
  1075. CommandGetStackTrace = "Debugger.getStackTrace"
  1076. CommandPause = "Debugger.pause"
  1077. CommandRemoveBreakpoint = "Debugger.removeBreakpoint"
  1078. CommandRestartFrame = "Debugger.restartFrame"
  1079. CommandResume = "Debugger.resume"
  1080. CommandSearchInContent = "Debugger.searchInContent"
  1081. CommandSetAsyncCallStackDepth = "Debugger.setAsyncCallStackDepth"
  1082. CommandSetBlackboxPatterns = "Debugger.setBlackboxPatterns"
  1083. CommandSetBlackboxedRanges = "Debugger.setBlackboxedRanges"
  1084. CommandSetBreakpoint = "Debugger.setBreakpoint"
  1085. CommandSetInstrumentationBreakpoint = "Debugger.setInstrumentationBreakpoint"
  1086. CommandSetBreakpointByURL = "Debugger.setBreakpointByUrl"
  1087. CommandSetBreakpointOnFunctionCall = "Debugger.setBreakpointOnFunctionCall"
  1088. CommandSetBreakpointsActive = "Debugger.setBreakpointsActive"
  1089. CommandSetPauseOnExceptions = "Debugger.setPauseOnExceptions"
  1090. CommandSetReturnValue = "Debugger.setReturnValue"
  1091. CommandSetScriptSource = "Debugger.setScriptSource"
  1092. CommandSetSkipAllPauses = "Debugger.setSkipAllPauses"
  1093. CommandSetVariableValue = "Debugger.setVariableValue"
  1094. CommandStepInto = "Debugger.stepInto"
  1095. CommandStepOut = "Debugger.stepOut"
  1096. CommandStepOver = "Debugger.stepOver"
  1097. )