runtime.go 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. // Package runtime provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Runtime domain.
  3. //
  4. // Runtime domain exposes JavaScript runtime by means of remote evaluation
  5. // and mirror objects. Evaluation results are returned as mirror object that
  6. // expose object type, string representation and unique identifier that can be
  7. // used for further object reference. Original objects are maintained in memory
  8. // unless they are either explicitly released or are released along with the
  9. // other objects in their object group.
  10. //
  11. // Generated by the cdproto-gen command.
  12. package runtime
  13. // Code generated by cdproto-gen. DO NOT EDIT.
  14. import (
  15. "context"
  16. "github.com/chromedp/cdproto/cdp"
  17. )
  18. // AwaitPromiseParams add handler to promise with given promise object id.
  19. type AwaitPromiseParams struct {
  20. PromiseObjectID RemoteObjectID `json:"promiseObjectId"` // Identifier of the promise.
  21. ReturnByValue bool `json:"returnByValue"` // Whether the result is expected to be a JSON object that should be sent by value.
  22. GeneratePreview bool `json:"generatePreview"` // Whether preview should be generated for the result.
  23. }
  24. // AwaitPromise add handler to promise with given promise object id.
  25. //
  26. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-awaitPromise
  27. //
  28. // parameters:
  29. //
  30. // promiseObjectID - Identifier of the promise.
  31. func AwaitPromise(promiseObjectID RemoteObjectID) *AwaitPromiseParams {
  32. return &AwaitPromiseParams{
  33. PromiseObjectID: promiseObjectID,
  34. ReturnByValue: false,
  35. GeneratePreview: false,
  36. }
  37. }
  38. // WithReturnByValue whether the result is expected to be a JSON object that
  39. // should be sent by value.
  40. func (p AwaitPromiseParams) WithReturnByValue(returnByValue bool) *AwaitPromiseParams {
  41. p.ReturnByValue = returnByValue
  42. return &p
  43. }
  44. // WithGeneratePreview whether preview should be generated for the result.
  45. func (p AwaitPromiseParams) WithGeneratePreview(generatePreview bool) *AwaitPromiseParams {
  46. p.GeneratePreview = generatePreview
  47. return &p
  48. }
  49. // AwaitPromiseReturns return values.
  50. type AwaitPromiseReturns struct {
  51. Result *RemoteObject `json:"result,omitempty,omitzero"` // Promise result. Will contain rejected value if promise was rejected.
  52. ExceptionDetails *ExceptionDetails `json:"exceptionDetails,omitempty,omitzero"` // Exception details if stack strace is available.
  53. }
  54. // Do executes Runtime.awaitPromise against the provided context.
  55. //
  56. // returns:
  57. //
  58. // result - Promise result. Will contain rejected value if promise was rejected.
  59. // exceptionDetails - Exception details if stack strace is available.
  60. func (p *AwaitPromiseParams) Do(ctx context.Context) (result *RemoteObject, exceptionDetails *ExceptionDetails, err error) {
  61. // execute
  62. var res AwaitPromiseReturns
  63. err = cdp.Execute(ctx, CommandAwaitPromise, p, &res)
  64. if err != nil {
  65. return nil, nil, err
  66. }
  67. return res.Result, res.ExceptionDetails, nil
  68. }
  69. // CallFunctionOnParams calls function with given declaration on the given
  70. // object. Object group of the result is inherited from the target object.
  71. type CallFunctionOnParams struct {
  72. FunctionDeclaration string `json:"functionDeclaration"` // Declaration of the function to call.
  73. ObjectID RemoteObjectID `json:"objectId,omitempty,omitzero"` // Identifier of the object to call function on. Either objectId or executionContextId should be specified.
  74. Arguments []*CallArgument `json:"arguments,omitempty,omitzero"` // Call arguments. All call arguments must belong to the same JavaScript world as the target object.
  75. Silent bool `json:"silent"` // In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state.
  76. ReturnByValue bool `json:"returnByValue"` // Whether the result is expected to be a JSON object which should be sent by value. Can be overridden by serializationOptions.
  77. GeneratePreview bool `json:"generatePreview"` // Whether preview should be generated for the result.
  78. UserGesture bool `json:"userGesture"` // Whether execution should be treated as initiated by user in the UI.
  79. AwaitPromise bool `json:"awaitPromise"` // Whether execution should await for resulting value and return once awaited promise is resolved.
  80. ExecutionContextID ExecutionContextID `json:"executionContextId,omitempty,omitzero"` // Specifies execution context which global object will be used to call function on. Either executionContextId or objectId should be specified.
  81. ObjectGroup string `json:"objectGroup,omitempty,omitzero"` // Symbolic group name that can be used to release multiple objects. If objectGroup is not specified and objectId is, objectGroup will be inherited from object.
  82. ThrowOnSideEffect bool `json:"throwOnSideEffect"` // Whether to throw an exception if side effect cannot be ruled out during evaluation.
  83. UniqueContextID string `json:"uniqueContextId,omitempty,omitzero"` // An alternative way to specify the execution context to call function on. Compared to contextId that may be reused across processes, this is guaranteed to be system-unique, so it can be used to prevent accidental function call in context different than intended (e.g. as a result of navigation across process boundaries). This is mutually exclusive with executionContextId.
  84. SerializationOptions *SerializationOptions `json:"serializationOptions,omitempty,omitzero"` // Specifies the result serialization. If provided, overrides generatePreview and returnByValue.
  85. }
  86. // CallFunctionOn calls function with given declaration on the given object.
  87. // Object group of the result is inherited from the target object.
  88. //
  89. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-callFunctionOn
  90. //
  91. // parameters:
  92. //
  93. // functionDeclaration - Declaration of the function to call.
  94. func CallFunctionOn(functionDeclaration string) *CallFunctionOnParams {
  95. return &CallFunctionOnParams{
  96. FunctionDeclaration: functionDeclaration,
  97. Silent: false,
  98. ReturnByValue: false,
  99. GeneratePreview: false,
  100. UserGesture: false,
  101. AwaitPromise: false,
  102. ThrowOnSideEffect: false,
  103. }
  104. }
  105. // WithObjectID identifier of the object to call function on. Either objectId
  106. // or executionContextId should be specified.
  107. func (p CallFunctionOnParams) WithObjectID(objectID RemoteObjectID) *CallFunctionOnParams {
  108. p.ObjectID = objectID
  109. return &p
  110. }
  111. // WithArguments call arguments. All call arguments must belong to the same
  112. // JavaScript world as the target object.
  113. func (p CallFunctionOnParams) WithArguments(arguments []*CallArgument) *CallFunctionOnParams {
  114. p.Arguments = arguments
  115. return &p
  116. }
  117. // WithSilent in silent mode exceptions thrown during evaluation are not
  118. // reported and do not pause execution. Overrides setPauseOnException state.
  119. func (p CallFunctionOnParams) WithSilent(silent bool) *CallFunctionOnParams {
  120. p.Silent = silent
  121. return &p
  122. }
  123. // WithReturnByValue whether the result is expected to be a JSON object which
  124. // should be sent by value. Can be overridden by serializationOptions.
  125. func (p CallFunctionOnParams) WithReturnByValue(returnByValue bool) *CallFunctionOnParams {
  126. p.ReturnByValue = returnByValue
  127. return &p
  128. }
  129. // WithGeneratePreview whether preview should be generated for the result.
  130. func (p CallFunctionOnParams) WithGeneratePreview(generatePreview bool) *CallFunctionOnParams {
  131. p.GeneratePreview = generatePreview
  132. return &p
  133. }
  134. // WithUserGesture whether execution should be treated as initiated by user
  135. // in the UI.
  136. func (p CallFunctionOnParams) WithUserGesture(userGesture bool) *CallFunctionOnParams {
  137. p.UserGesture = userGesture
  138. return &p
  139. }
  140. // WithAwaitPromise whether execution should await for resulting value and
  141. // return once awaited promise is resolved.
  142. func (p CallFunctionOnParams) WithAwaitPromise(awaitPromise bool) *CallFunctionOnParams {
  143. p.AwaitPromise = awaitPromise
  144. return &p
  145. }
  146. // WithExecutionContextID specifies execution context which global object
  147. // will be used to call function on. Either executionContextId or objectId
  148. // should be specified.
  149. func (p CallFunctionOnParams) WithExecutionContextID(executionContextID ExecutionContextID) *CallFunctionOnParams {
  150. p.ExecutionContextID = executionContextID
  151. return &p
  152. }
  153. // WithObjectGroup symbolic group name that can be used to release multiple
  154. // objects. If objectGroup is not specified and objectId is, objectGroup will be
  155. // inherited from object.
  156. func (p CallFunctionOnParams) WithObjectGroup(objectGroup string) *CallFunctionOnParams {
  157. p.ObjectGroup = objectGroup
  158. return &p
  159. }
  160. // WithThrowOnSideEffect whether to throw an exception if side effect cannot
  161. // be ruled out during evaluation.
  162. func (p CallFunctionOnParams) WithThrowOnSideEffect(throwOnSideEffect bool) *CallFunctionOnParams {
  163. p.ThrowOnSideEffect = throwOnSideEffect
  164. return &p
  165. }
  166. // WithUniqueContextID an alternative way to specify the execution context to
  167. // call function on. Compared to contextId that may be reused across processes,
  168. // this is guaranteed to be system-unique, so it can be used to prevent
  169. // accidental function call in context different than intended (e.g. as a result
  170. // of navigation across process boundaries). This is mutually exclusive with
  171. // executionContextId.
  172. func (p CallFunctionOnParams) WithUniqueContextID(uniqueContextID string) *CallFunctionOnParams {
  173. p.UniqueContextID = uniqueContextID
  174. return &p
  175. }
  176. // WithSerializationOptions specifies the result serialization. If provided,
  177. // overrides generatePreview and returnByValue.
  178. func (p CallFunctionOnParams) WithSerializationOptions(serializationOptions *SerializationOptions) *CallFunctionOnParams {
  179. p.SerializationOptions = serializationOptions
  180. return &p
  181. }
  182. // CallFunctionOnReturns return values.
  183. type CallFunctionOnReturns struct {
  184. Result *RemoteObject `json:"result,omitempty,omitzero"` // Call result.
  185. ExceptionDetails *ExceptionDetails `json:"exceptionDetails,omitempty,omitzero"` // Exception details.
  186. }
  187. // Do executes Runtime.callFunctionOn against the provided context.
  188. //
  189. // returns:
  190. //
  191. // result - Call result.
  192. // exceptionDetails - Exception details.
  193. func (p *CallFunctionOnParams) Do(ctx context.Context) (result *RemoteObject, exceptionDetails *ExceptionDetails, err error) {
  194. // execute
  195. var res CallFunctionOnReturns
  196. err = cdp.Execute(ctx, CommandCallFunctionOn, p, &res)
  197. if err != nil {
  198. return nil, nil, err
  199. }
  200. return res.Result, res.ExceptionDetails, nil
  201. }
  202. // CompileScriptParams compiles expression.
  203. type CompileScriptParams struct {
  204. Expression string `json:"expression"` // Expression to compile.
  205. SourceURL string `json:"sourceURL"` // Source url to be set for the script.
  206. PersistScript bool `json:"persistScript"` // Specifies whether the compiled script should be persisted.
  207. ExecutionContextID ExecutionContextID `json:"executionContextId,omitempty,omitzero"` // Specifies in which execution context to perform script run. If the parameter is omitted the evaluation will be performed in the context of the inspected page.
  208. }
  209. // CompileScript compiles expression.
  210. //
  211. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-compileScript
  212. //
  213. // parameters:
  214. //
  215. // expression - Expression to compile.
  216. // sourceURL - Source url to be set for the script.
  217. // persistScript - Specifies whether the compiled script should be persisted.
  218. func CompileScript(expression string, sourceURL string, persistScript bool) *CompileScriptParams {
  219. return &CompileScriptParams{
  220. Expression: expression,
  221. SourceURL: sourceURL,
  222. PersistScript: persistScript,
  223. }
  224. }
  225. // WithExecutionContextID specifies in which execution context to perform
  226. // script run. If the parameter is omitted the evaluation will be performed in
  227. // the context of the inspected page.
  228. func (p CompileScriptParams) WithExecutionContextID(executionContextID ExecutionContextID) *CompileScriptParams {
  229. p.ExecutionContextID = executionContextID
  230. return &p
  231. }
  232. // CompileScriptReturns return values.
  233. type CompileScriptReturns struct {
  234. ScriptID ScriptID `json:"scriptId,omitempty,omitzero"` // Id of the script.
  235. ExceptionDetails *ExceptionDetails `json:"exceptionDetails,omitempty,omitzero"` // Exception details.
  236. }
  237. // Do executes Runtime.compileScript against the provided context.
  238. //
  239. // returns:
  240. //
  241. // scriptID - Id of the script.
  242. // exceptionDetails - Exception details.
  243. func (p *CompileScriptParams) Do(ctx context.Context) (scriptID ScriptID, exceptionDetails *ExceptionDetails, err error) {
  244. // execute
  245. var res CompileScriptReturns
  246. err = cdp.Execute(ctx, CommandCompileScript, p, &res)
  247. if err != nil {
  248. return "", nil, err
  249. }
  250. return res.ScriptID, res.ExceptionDetails, nil
  251. }
  252. // DisableParams disables reporting of execution contexts creation.
  253. type DisableParams struct{}
  254. // Disable disables reporting of execution contexts creation.
  255. //
  256. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-disable
  257. func Disable() *DisableParams {
  258. return &DisableParams{}
  259. }
  260. // Do executes Runtime.disable against the provided context.
  261. func (p *DisableParams) Do(ctx context.Context) (err error) {
  262. return cdp.Execute(ctx, CommandDisable, nil, nil)
  263. }
  264. // DiscardConsoleEntriesParams discards collected exceptions and console API
  265. // calls.
  266. type DiscardConsoleEntriesParams struct{}
  267. // DiscardConsoleEntries discards collected exceptions and console API calls.
  268. //
  269. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-discardConsoleEntries
  270. func DiscardConsoleEntries() *DiscardConsoleEntriesParams {
  271. return &DiscardConsoleEntriesParams{}
  272. }
  273. // Do executes Runtime.discardConsoleEntries against the provided context.
  274. func (p *DiscardConsoleEntriesParams) Do(ctx context.Context) (err error) {
  275. return cdp.Execute(ctx, CommandDiscardConsoleEntries, nil, nil)
  276. }
  277. // EnableParams enables reporting of execution contexts creation by means of
  278. // executionContextCreated event. When the reporting gets enabled the event will
  279. // be sent immediately for each existing execution context.
  280. type EnableParams struct{}
  281. // Enable enables reporting of execution contexts creation by means of
  282. // executionContextCreated event. When the reporting gets enabled the event will
  283. // be sent immediately for each existing execution context.
  284. //
  285. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-enable
  286. func Enable() *EnableParams {
  287. return &EnableParams{}
  288. }
  289. // Do executes Runtime.enable against the provided context.
  290. func (p *EnableParams) Do(ctx context.Context) (err error) {
  291. return cdp.Execute(ctx, CommandEnable, nil, nil)
  292. }
  293. // EvaluateParams evaluates expression on global object.
  294. type EvaluateParams struct {
  295. Expression string `json:"expression"` // Expression to evaluate.
  296. ObjectGroup string `json:"objectGroup,omitempty,omitzero"` // Symbolic group name that can be used to release multiple objects.
  297. IncludeCommandLineAPI bool `json:"includeCommandLineAPI"` // Determines whether Command Line API should be available during the evaluation.
  298. Silent bool `json:"silent"` // In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state.
  299. ContextID ExecutionContextID `json:"contextId,omitempty,omitzero"` // Specifies in which execution context to perform evaluation. If the parameter is omitted the evaluation will be performed in the context of the inspected page. This is mutually exclusive with uniqueContextId, which offers an alternative way to identify the execution context that is more reliable in a multi-process environment.
  300. ReturnByValue bool `json:"returnByValue"` // Whether the result is expected to be a JSON object that should be sent by value.
  301. GeneratePreview bool `json:"generatePreview"` // Whether preview should be generated for the result.
  302. UserGesture bool `json:"userGesture"` // Whether execution should be treated as initiated by user in the UI.
  303. AwaitPromise bool `json:"awaitPromise"` // Whether execution should await for resulting value and return once awaited promise is resolved.
  304. ThrowOnSideEffect bool `json:"throwOnSideEffect"` // Whether to throw an exception if side effect cannot be ruled out during evaluation. This implies disableBreaks below.
  305. Timeout TimeDelta `json:"timeout,omitempty,omitzero"` // Terminate execution after timing out (number of milliseconds).
  306. DisableBreaks bool `json:"disableBreaks"` // Disable breakpoints during execution.
  307. ReplMode bool `json:"replMode"` // Setting this flag to true enables let re-declaration and top-level await. Note that let variables can only be re-declared if they originate from replMode themselves.
  308. AllowUnsafeEvalBlockedByCSP bool `json:"allowUnsafeEvalBlockedByCSP"` // The Content Security Policy (CSP) for the target might block 'unsafe-eval' which includes eval(), Function(), setTimeout() and setInterval() when called with non-callable arguments. This flag bypasses CSP for this evaluation and allows unsafe-eval. Defaults to true.
  309. UniqueContextID string `json:"uniqueContextId,omitempty,omitzero"` // An alternative way to specify the execution context to evaluate in. Compared to contextId that may be reused across processes, this is guaranteed to be system-unique, so it can be used to prevent accidental evaluation of the expression in context different than intended (e.g. as a result of navigation across process boundaries). This is mutually exclusive with contextId.
  310. SerializationOptions *SerializationOptions `json:"serializationOptions,omitempty,omitzero"` // Specifies the result serialization. If provided, overrides generatePreview and returnByValue.
  311. }
  312. // Evaluate evaluates expression on global object.
  313. //
  314. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-evaluate
  315. //
  316. // parameters:
  317. //
  318. // expression - Expression to evaluate.
  319. func Evaluate(expression string) *EvaluateParams {
  320. return &EvaluateParams{
  321. Expression: expression,
  322. IncludeCommandLineAPI: false,
  323. Silent: false,
  324. ReturnByValue: false,
  325. GeneratePreview: false,
  326. UserGesture: false,
  327. AwaitPromise: false,
  328. ThrowOnSideEffect: false,
  329. DisableBreaks: false,
  330. ReplMode: false,
  331. AllowUnsafeEvalBlockedByCSP: true,
  332. }
  333. }
  334. // WithObjectGroup symbolic group name that can be used to release multiple
  335. // objects.
  336. func (p EvaluateParams) WithObjectGroup(objectGroup string) *EvaluateParams {
  337. p.ObjectGroup = objectGroup
  338. return &p
  339. }
  340. // WithIncludeCommandLineAPI determines whether Command Line API should be
  341. // available during the evaluation.
  342. func (p EvaluateParams) WithIncludeCommandLineAPI(includeCommandLineAPI bool) *EvaluateParams {
  343. p.IncludeCommandLineAPI = includeCommandLineAPI
  344. return &p
  345. }
  346. // WithSilent in silent mode exceptions thrown during evaluation are not
  347. // reported and do not pause execution. Overrides setPauseOnException state.
  348. func (p EvaluateParams) WithSilent(silent bool) *EvaluateParams {
  349. p.Silent = silent
  350. return &p
  351. }
  352. // WithContextID specifies in which execution context to perform evaluation.
  353. // If the parameter is omitted the evaluation will be performed in the context
  354. // of the inspected page. This is mutually exclusive with uniqueContextId, which
  355. // offers an alternative way to identify the execution context that is more
  356. // reliable in a multi-process environment.
  357. func (p EvaluateParams) WithContextID(contextID ExecutionContextID) *EvaluateParams {
  358. p.ContextID = contextID
  359. return &p
  360. }
  361. // WithReturnByValue whether the result is expected to be a JSON object that
  362. // should be sent by value.
  363. func (p EvaluateParams) WithReturnByValue(returnByValue bool) *EvaluateParams {
  364. p.ReturnByValue = returnByValue
  365. return &p
  366. }
  367. // WithGeneratePreview whether preview should be generated for the result.
  368. func (p EvaluateParams) WithGeneratePreview(generatePreview bool) *EvaluateParams {
  369. p.GeneratePreview = generatePreview
  370. return &p
  371. }
  372. // WithUserGesture whether execution should be treated as initiated by user
  373. // in the UI.
  374. func (p EvaluateParams) WithUserGesture(userGesture bool) *EvaluateParams {
  375. p.UserGesture = userGesture
  376. return &p
  377. }
  378. // WithAwaitPromise whether execution should await for resulting value and
  379. // return once awaited promise is resolved.
  380. func (p EvaluateParams) WithAwaitPromise(awaitPromise bool) *EvaluateParams {
  381. p.AwaitPromise = awaitPromise
  382. return &p
  383. }
  384. // WithThrowOnSideEffect whether to throw an exception if side effect cannot
  385. // be ruled out during evaluation. This implies disableBreaks below.
  386. func (p EvaluateParams) WithThrowOnSideEffect(throwOnSideEffect bool) *EvaluateParams {
  387. p.ThrowOnSideEffect = throwOnSideEffect
  388. return &p
  389. }
  390. // WithTimeout terminate execution after timing out (number of milliseconds).
  391. func (p EvaluateParams) WithTimeout(timeout TimeDelta) *EvaluateParams {
  392. p.Timeout = timeout
  393. return &p
  394. }
  395. // WithDisableBreaks disable breakpoints during execution.
  396. func (p EvaluateParams) WithDisableBreaks(disableBreaks bool) *EvaluateParams {
  397. p.DisableBreaks = disableBreaks
  398. return &p
  399. }
  400. // WithReplMode setting this flag to true enables let re-declaration and
  401. // top-level await. Note that let variables can only be re-declared if they
  402. // originate from replMode themselves.
  403. func (p EvaluateParams) WithReplMode(replMode bool) *EvaluateParams {
  404. p.ReplMode = replMode
  405. return &p
  406. }
  407. // WithAllowUnsafeEvalBlockedByCSP the Content Security Policy (CSP) for the
  408. // target might block 'unsafe-eval' which includes eval(), Function(),
  409. // setTimeout() and setInterval() when called with non-callable arguments. This
  410. // flag bypasses CSP for this evaluation and allows unsafe-eval. Defaults to
  411. // true.
  412. func (p EvaluateParams) WithAllowUnsafeEvalBlockedByCSP(allowUnsafeEvalBlockedByCSP bool) *EvaluateParams {
  413. p.AllowUnsafeEvalBlockedByCSP = allowUnsafeEvalBlockedByCSP
  414. return &p
  415. }
  416. // WithUniqueContextID an alternative way to specify the execution context to
  417. // evaluate in. Compared to contextId that may be reused across processes, this
  418. // is guaranteed to be system-unique, so it can be used to prevent accidental
  419. // evaluation of the expression in context different than intended (e.g. as a
  420. // result of navigation across process boundaries). This is mutually exclusive
  421. // with contextId.
  422. func (p EvaluateParams) WithUniqueContextID(uniqueContextID string) *EvaluateParams {
  423. p.UniqueContextID = uniqueContextID
  424. return &p
  425. }
  426. // WithSerializationOptions specifies the result serialization. If provided,
  427. // overrides generatePreview and returnByValue.
  428. func (p EvaluateParams) WithSerializationOptions(serializationOptions *SerializationOptions) *EvaluateParams {
  429. p.SerializationOptions = serializationOptions
  430. return &p
  431. }
  432. // EvaluateReturns return values.
  433. type EvaluateReturns struct {
  434. Result *RemoteObject `json:"result,omitempty,omitzero"` // Evaluation result.
  435. ExceptionDetails *ExceptionDetails `json:"exceptionDetails,omitempty,omitzero"` // Exception details.
  436. }
  437. // Do executes Runtime.evaluate against the provided context.
  438. //
  439. // returns:
  440. //
  441. // result - Evaluation result.
  442. // exceptionDetails - Exception details.
  443. func (p *EvaluateParams) Do(ctx context.Context) (result *RemoteObject, exceptionDetails *ExceptionDetails, err error) {
  444. // execute
  445. var res EvaluateReturns
  446. err = cdp.Execute(ctx, CommandEvaluate, p, &res)
  447. if err != nil {
  448. return nil, nil, err
  449. }
  450. return res.Result, res.ExceptionDetails, nil
  451. }
  452. // GetIsolateIDParams returns the isolate id.
  453. type GetIsolateIDParams struct{}
  454. // GetIsolateID returns the isolate id.
  455. //
  456. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-getIsolateId
  457. func GetIsolateID() *GetIsolateIDParams {
  458. return &GetIsolateIDParams{}
  459. }
  460. // GetIsolateIDReturns return values.
  461. type GetIsolateIDReturns struct {
  462. ID string `json:"id,omitempty,omitzero"` // The isolate id.
  463. }
  464. // Do executes Runtime.getIsolateId against the provided context.
  465. //
  466. // returns:
  467. //
  468. // id - The isolate id.
  469. func (p *GetIsolateIDParams) Do(ctx context.Context) (id string, err error) {
  470. // execute
  471. var res GetIsolateIDReturns
  472. err = cdp.Execute(ctx, CommandGetIsolateID, nil, &res)
  473. if err != nil {
  474. return "", err
  475. }
  476. return res.ID, nil
  477. }
  478. // GetHeapUsageParams returns the JavaScript heap usage. It is the total
  479. // usage of the corresponding isolate not scoped to a particular Runtime.
  480. type GetHeapUsageParams struct{}
  481. // GetHeapUsage returns the JavaScript heap usage. It is the total usage of
  482. // the corresponding isolate not scoped to a particular Runtime.
  483. //
  484. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-getHeapUsage
  485. func GetHeapUsage() *GetHeapUsageParams {
  486. return &GetHeapUsageParams{}
  487. }
  488. // GetHeapUsageReturns return values.
  489. type GetHeapUsageReturns struct {
  490. UsedSize float64 `json:"usedSize,omitempty,omitzero"` // Used JavaScript heap size in bytes.
  491. TotalSize float64 `json:"totalSize,omitempty,omitzero"` // Allocated JavaScript heap size in bytes.
  492. EmbedderHeapUsedSize float64 `json:"embedderHeapUsedSize,omitempty,omitzero"` // Used size in bytes in the embedder's garbage-collected heap.
  493. BackingStorageSize float64 `json:"backingStorageSize,omitempty,omitzero"` // Size in bytes of backing storage for array buffers and external strings.
  494. }
  495. // Do executes Runtime.getHeapUsage against the provided context.
  496. //
  497. // returns:
  498. //
  499. // usedSize - Used JavaScript heap size in bytes.
  500. // totalSize - Allocated JavaScript heap size in bytes.
  501. // embedderHeapUsedSize - Used size in bytes in the embedder's garbage-collected heap.
  502. // backingStorageSize - Size in bytes of backing storage for array buffers and external strings.
  503. func (p *GetHeapUsageParams) Do(ctx context.Context) (usedSize float64, totalSize float64, embedderHeapUsedSize float64, backingStorageSize float64, err error) {
  504. // execute
  505. var res GetHeapUsageReturns
  506. err = cdp.Execute(ctx, CommandGetHeapUsage, nil, &res)
  507. if err != nil {
  508. return 0, 0, 0, 0, err
  509. }
  510. return res.UsedSize, res.TotalSize, res.EmbedderHeapUsedSize, res.BackingStorageSize, nil
  511. }
  512. // GetPropertiesParams returns properties of a given object. Object group of
  513. // the result is inherited from the target object.
  514. type GetPropertiesParams struct {
  515. ObjectID RemoteObjectID `json:"objectId"` // Identifier of the object to return properties for.
  516. OwnProperties bool `json:"ownProperties"` // If true, returns properties belonging only to the element itself, not to its prototype chain.
  517. AccessorPropertiesOnly bool `json:"accessorPropertiesOnly"` // If true, returns accessor properties (with getter/setter) only; internal properties are not returned either.
  518. GeneratePreview bool `json:"generatePreview"` // Whether preview should be generated for the results.
  519. NonIndexedPropertiesOnly bool `json:"nonIndexedPropertiesOnly"` // If true, returns non-indexed properties only.
  520. }
  521. // GetProperties returns properties of a given object. Object group of the
  522. // result is inherited from the target object.
  523. //
  524. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-getProperties
  525. //
  526. // parameters:
  527. //
  528. // objectID - Identifier of the object to return properties for.
  529. func GetProperties(objectID RemoteObjectID) *GetPropertiesParams {
  530. return &GetPropertiesParams{
  531. ObjectID: objectID,
  532. OwnProperties: false,
  533. AccessorPropertiesOnly: false,
  534. GeneratePreview: false,
  535. NonIndexedPropertiesOnly: false,
  536. }
  537. }
  538. // WithOwnProperties if true, returns properties belonging only to the
  539. // element itself, not to its prototype chain.
  540. func (p GetPropertiesParams) WithOwnProperties(ownProperties bool) *GetPropertiesParams {
  541. p.OwnProperties = ownProperties
  542. return &p
  543. }
  544. // WithAccessorPropertiesOnly if true, returns accessor properties (with
  545. // getter/setter) only; internal properties are not returned either.
  546. func (p GetPropertiesParams) WithAccessorPropertiesOnly(accessorPropertiesOnly bool) *GetPropertiesParams {
  547. p.AccessorPropertiesOnly = accessorPropertiesOnly
  548. return &p
  549. }
  550. // WithGeneratePreview whether preview should be generated for the results.
  551. func (p GetPropertiesParams) WithGeneratePreview(generatePreview bool) *GetPropertiesParams {
  552. p.GeneratePreview = generatePreview
  553. return &p
  554. }
  555. // WithNonIndexedPropertiesOnly if true, returns non-indexed properties only.
  556. func (p GetPropertiesParams) WithNonIndexedPropertiesOnly(nonIndexedPropertiesOnly bool) *GetPropertiesParams {
  557. p.NonIndexedPropertiesOnly = nonIndexedPropertiesOnly
  558. return &p
  559. }
  560. // GetPropertiesReturns return values.
  561. type GetPropertiesReturns struct {
  562. Result []*PropertyDescriptor `json:"result,omitempty,omitzero"` // Object properties.
  563. InternalProperties []*InternalPropertyDescriptor `json:"internalProperties,omitempty,omitzero"` // Internal object properties (only of the element itself).
  564. PrivateProperties []*PrivatePropertyDescriptor `json:"privateProperties,omitempty,omitzero"` // Object private properties.
  565. ExceptionDetails *ExceptionDetails `json:"exceptionDetails,omitempty,omitzero"` // Exception details.
  566. }
  567. // Do executes Runtime.getProperties against the provided context.
  568. //
  569. // returns:
  570. //
  571. // result - Object properties.
  572. // internalProperties - Internal object properties (only of the element itself).
  573. // privateProperties - Object private properties.
  574. // exceptionDetails - Exception details.
  575. func (p *GetPropertiesParams) Do(ctx context.Context) (result []*PropertyDescriptor, internalProperties []*InternalPropertyDescriptor, privateProperties []*PrivatePropertyDescriptor, exceptionDetails *ExceptionDetails, err error) {
  576. // execute
  577. var res GetPropertiesReturns
  578. err = cdp.Execute(ctx, CommandGetProperties, p, &res)
  579. if err != nil {
  580. return nil, nil, nil, nil, err
  581. }
  582. return res.Result, res.InternalProperties, res.PrivateProperties, res.ExceptionDetails, nil
  583. }
  584. // GlobalLexicalScopeNamesParams returns all let, const and class variables
  585. // from global scope.
  586. type GlobalLexicalScopeNamesParams struct {
  587. ExecutionContextID ExecutionContextID `json:"executionContextId,omitempty,omitzero"` // Specifies in which execution context to lookup global scope variables.
  588. }
  589. // GlobalLexicalScopeNames returns all let, const and class variables from
  590. // global scope.
  591. //
  592. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-globalLexicalScopeNames
  593. //
  594. // parameters:
  595. func GlobalLexicalScopeNames() *GlobalLexicalScopeNamesParams {
  596. return &GlobalLexicalScopeNamesParams{}
  597. }
  598. // WithExecutionContextID specifies in which execution context to lookup
  599. // global scope variables.
  600. func (p GlobalLexicalScopeNamesParams) WithExecutionContextID(executionContextID ExecutionContextID) *GlobalLexicalScopeNamesParams {
  601. p.ExecutionContextID = executionContextID
  602. return &p
  603. }
  604. // GlobalLexicalScopeNamesReturns return values.
  605. type GlobalLexicalScopeNamesReturns struct {
  606. Names []string `json:"names,omitempty,omitzero"`
  607. }
  608. // Do executes Runtime.globalLexicalScopeNames against the provided context.
  609. //
  610. // returns:
  611. //
  612. // names
  613. func (p *GlobalLexicalScopeNamesParams) Do(ctx context.Context) (names []string, err error) {
  614. // execute
  615. var res GlobalLexicalScopeNamesReturns
  616. err = cdp.Execute(ctx, CommandGlobalLexicalScopeNames, p, &res)
  617. if err != nil {
  618. return nil, err
  619. }
  620. return res.Names, nil
  621. }
  622. // QueryObjectsParams [no description].
  623. type QueryObjectsParams struct {
  624. PrototypeObjectID RemoteObjectID `json:"prototypeObjectId"` // Identifier of the prototype to return objects for.
  625. ObjectGroup string `json:"objectGroup,omitempty,omitzero"` // Symbolic group name that can be used to release the results.
  626. }
  627. // QueryObjects [no description].
  628. //
  629. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-queryObjects
  630. //
  631. // parameters:
  632. //
  633. // prototypeObjectID - Identifier of the prototype to return objects for.
  634. func QueryObjects(prototypeObjectID RemoteObjectID) *QueryObjectsParams {
  635. return &QueryObjectsParams{
  636. PrototypeObjectID: prototypeObjectID,
  637. }
  638. }
  639. // WithObjectGroup symbolic group name that can be used to release the
  640. // results.
  641. func (p QueryObjectsParams) WithObjectGroup(objectGroup string) *QueryObjectsParams {
  642. p.ObjectGroup = objectGroup
  643. return &p
  644. }
  645. // QueryObjectsReturns return values.
  646. type QueryObjectsReturns struct {
  647. Objects *RemoteObject `json:"objects,omitempty,omitzero"` // Array with objects.
  648. }
  649. // Do executes Runtime.queryObjects against the provided context.
  650. //
  651. // returns:
  652. //
  653. // objects - Array with objects.
  654. func (p *QueryObjectsParams) Do(ctx context.Context) (objects *RemoteObject, err error) {
  655. // execute
  656. var res QueryObjectsReturns
  657. err = cdp.Execute(ctx, CommandQueryObjects, p, &res)
  658. if err != nil {
  659. return nil, err
  660. }
  661. return res.Objects, nil
  662. }
  663. // ReleaseObjectParams releases remote object with given id.
  664. type ReleaseObjectParams struct {
  665. ObjectID RemoteObjectID `json:"objectId"` // Identifier of the object to release.
  666. }
  667. // ReleaseObject releases remote object with given id.
  668. //
  669. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-releaseObject
  670. //
  671. // parameters:
  672. //
  673. // objectID - Identifier of the object to release.
  674. func ReleaseObject(objectID RemoteObjectID) *ReleaseObjectParams {
  675. return &ReleaseObjectParams{
  676. ObjectID: objectID,
  677. }
  678. }
  679. // Do executes Runtime.releaseObject against the provided context.
  680. func (p *ReleaseObjectParams) Do(ctx context.Context) (err error) {
  681. return cdp.Execute(ctx, CommandReleaseObject, p, nil)
  682. }
  683. // ReleaseObjectGroupParams releases all remote objects that belong to a
  684. // given group.
  685. type ReleaseObjectGroupParams struct {
  686. ObjectGroup string `json:"objectGroup"` // Symbolic object group name.
  687. }
  688. // ReleaseObjectGroup releases all remote objects that belong to a given
  689. // group.
  690. //
  691. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-releaseObjectGroup
  692. //
  693. // parameters:
  694. //
  695. // objectGroup - Symbolic object group name.
  696. func ReleaseObjectGroup(objectGroup string) *ReleaseObjectGroupParams {
  697. return &ReleaseObjectGroupParams{
  698. ObjectGroup: objectGroup,
  699. }
  700. }
  701. // Do executes Runtime.releaseObjectGroup against the provided context.
  702. func (p *ReleaseObjectGroupParams) Do(ctx context.Context) (err error) {
  703. return cdp.Execute(ctx, CommandReleaseObjectGroup, p, nil)
  704. }
  705. // RunIfWaitingForDebuggerParams tells inspected instance to run if it was
  706. // waiting for debugger to attach.
  707. type RunIfWaitingForDebuggerParams struct{}
  708. // RunIfWaitingForDebugger tells inspected instance to run if it was waiting
  709. // for debugger to attach.
  710. //
  711. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-runIfWaitingForDebugger
  712. func RunIfWaitingForDebugger() *RunIfWaitingForDebuggerParams {
  713. return &RunIfWaitingForDebuggerParams{}
  714. }
  715. // Do executes Runtime.runIfWaitingForDebugger against the provided context.
  716. func (p *RunIfWaitingForDebuggerParams) Do(ctx context.Context) (err error) {
  717. return cdp.Execute(ctx, CommandRunIfWaitingForDebugger, nil, nil)
  718. }
  719. // RunScriptParams runs script with given id in a given context.
  720. type RunScriptParams struct {
  721. ScriptID ScriptID `json:"scriptId"` // Id of the script to run.
  722. ExecutionContextID ExecutionContextID `json:"executionContextId,omitempty,omitzero"` // Specifies in which execution context to perform script run. If the parameter is omitted the evaluation will be performed in the context of the inspected page.
  723. ObjectGroup string `json:"objectGroup,omitempty,omitzero"` // Symbolic group name that can be used to release multiple objects.
  724. Silent bool `json:"silent"` // In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state.
  725. IncludeCommandLineAPI bool `json:"includeCommandLineAPI"` // Determines whether Command Line API should be available during the evaluation.
  726. ReturnByValue bool `json:"returnByValue"` // Whether the result is expected to be a JSON object which should be sent by value.
  727. GeneratePreview bool `json:"generatePreview"` // Whether preview should be generated for the result.
  728. AwaitPromise bool `json:"awaitPromise"` // Whether execution should await for resulting value and return once awaited promise is resolved.
  729. }
  730. // RunScript runs script with given id in a given context.
  731. //
  732. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-runScript
  733. //
  734. // parameters:
  735. //
  736. // scriptID - Id of the script to run.
  737. func RunScript(scriptID ScriptID) *RunScriptParams {
  738. return &RunScriptParams{
  739. ScriptID: scriptID,
  740. Silent: false,
  741. IncludeCommandLineAPI: false,
  742. ReturnByValue: false,
  743. GeneratePreview: false,
  744. AwaitPromise: false,
  745. }
  746. }
  747. // WithExecutionContextID specifies in which execution context to perform
  748. // script run. If the parameter is omitted the evaluation will be performed in
  749. // the context of the inspected page.
  750. func (p RunScriptParams) WithExecutionContextID(executionContextID ExecutionContextID) *RunScriptParams {
  751. p.ExecutionContextID = executionContextID
  752. return &p
  753. }
  754. // WithObjectGroup symbolic group name that can be used to release multiple
  755. // objects.
  756. func (p RunScriptParams) WithObjectGroup(objectGroup string) *RunScriptParams {
  757. p.ObjectGroup = objectGroup
  758. return &p
  759. }
  760. // WithSilent in silent mode exceptions thrown during evaluation are not
  761. // reported and do not pause execution. Overrides setPauseOnException state.
  762. func (p RunScriptParams) WithSilent(silent bool) *RunScriptParams {
  763. p.Silent = silent
  764. return &p
  765. }
  766. // WithIncludeCommandLineAPI determines whether Command Line API should be
  767. // available during the evaluation.
  768. func (p RunScriptParams) WithIncludeCommandLineAPI(includeCommandLineAPI bool) *RunScriptParams {
  769. p.IncludeCommandLineAPI = includeCommandLineAPI
  770. return &p
  771. }
  772. // WithReturnByValue whether the result is expected to be a JSON object which
  773. // should be sent by value.
  774. func (p RunScriptParams) WithReturnByValue(returnByValue bool) *RunScriptParams {
  775. p.ReturnByValue = returnByValue
  776. return &p
  777. }
  778. // WithGeneratePreview whether preview should be generated for the result.
  779. func (p RunScriptParams) WithGeneratePreview(generatePreview bool) *RunScriptParams {
  780. p.GeneratePreview = generatePreview
  781. return &p
  782. }
  783. // WithAwaitPromise whether execution should await for resulting value and
  784. // return once awaited promise is resolved.
  785. func (p RunScriptParams) WithAwaitPromise(awaitPromise bool) *RunScriptParams {
  786. p.AwaitPromise = awaitPromise
  787. return &p
  788. }
  789. // RunScriptReturns return values.
  790. type RunScriptReturns struct {
  791. Result *RemoteObject `json:"result,omitempty,omitzero"` // Run result.
  792. ExceptionDetails *ExceptionDetails `json:"exceptionDetails,omitempty,omitzero"` // Exception details.
  793. }
  794. // Do executes Runtime.runScript against the provided context.
  795. //
  796. // returns:
  797. //
  798. // result - Run result.
  799. // exceptionDetails - Exception details.
  800. func (p *RunScriptParams) Do(ctx context.Context) (result *RemoteObject, exceptionDetails *ExceptionDetails, err error) {
  801. // execute
  802. var res RunScriptReturns
  803. err = cdp.Execute(ctx, CommandRunScript, p, &res)
  804. if err != nil {
  805. return nil, nil, err
  806. }
  807. return res.Result, res.ExceptionDetails, nil
  808. }
  809. // SetCustomObjectFormatterEnabledParams [no description].
  810. type SetCustomObjectFormatterEnabledParams struct {
  811. Enabled bool `json:"enabled"`
  812. }
  813. // SetCustomObjectFormatterEnabled [no description].
  814. //
  815. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-setCustomObjectFormatterEnabled
  816. //
  817. // parameters:
  818. //
  819. // enabled
  820. func SetCustomObjectFormatterEnabled(enabled bool) *SetCustomObjectFormatterEnabledParams {
  821. return &SetCustomObjectFormatterEnabledParams{
  822. Enabled: enabled,
  823. }
  824. }
  825. // Do executes Runtime.setCustomObjectFormatterEnabled against the provided context.
  826. func (p *SetCustomObjectFormatterEnabledParams) Do(ctx context.Context) (err error) {
  827. return cdp.Execute(ctx, CommandSetCustomObjectFormatterEnabled, p, nil)
  828. }
  829. // SetMaxCallStackSizeToCaptureParams [no description].
  830. type SetMaxCallStackSizeToCaptureParams struct {
  831. Size int64 `json:"size"`
  832. }
  833. // SetMaxCallStackSizeToCapture [no description].
  834. //
  835. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-setMaxCallStackSizeToCapture
  836. //
  837. // parameters:
  838. //
  839. // size
  840. func SetMaxCallStackSizeToCapture(size int64) *SetMaxCallStackSizeToCaptureParams {
  841. return &SetMaxCallStackSizeToCaptureParams{
  842. Size: size,
  843. }
  844. }
  845. // Do executes Runtime.setMaxCallStackSizeToCapture against the provided context.
  846. func (p *SetMaxCallStackSizeToCaptureParams) Do(ctx context.Context) (err error) {
  847. return cdp.Execute(ctx, CommandSetMaxCallStackSizeToCapture, p, nil)
  848. }
  849. // TerminateExecutionParams terminate current or next JavaScript execution.
  850. // Will cancel the termination when the outer-most script execution ends.
  851. type TerminateExecutionParams struct{}
  852. // TerminateExecution terminate current or next JavaScript execution. Will
  853. // cancel the termination when the outer-most script execution ends.
  854. //
  855. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-terminateExecution
  856. func TerminateExecution() *TerminateExecutionParams {
  857. return &TerminateExecutionParams{}
  858. }
  859. // Do executes Runtime.terminateExecution against the provided context.
  860. func (p *TerminateExecutionParams) Do(ctx context.Context) (err error) {
  861. return cdp.Execute(ctx, CommandTerminateExecution, nil, nil)
  862. }
  863. // AddBindingParams if executionContextId is empty, adds binding with the
  864. // given name on the global objects of all inspected contexts, including those
  865. // created later, bindings survive reloads. Binding function takes exactly one
  866. // argument, this argument should be string, in case of any other input,
  867. // function throws an exception. Each binding function call produces
  868. // Runtime.bindingCalled notification.
  869. type AddBindingParams struct {
  870. Name string `json:"name"`
  871. ExecutionContextName string `json:"executionContextName,omitempty,omitzero"` // If specified, the binding is exposed to the executionContext with matching name, even for contexts created after the binding is added. See also ExecutionContext.name and worldName parameter to Page.addScriptToEvaluateOnNewDocument. This parameter is mutually exclusive with executionContextId.
  872. }
  873. // AddBinding if executionContextId is empty, adds binding with the given
  874. // name on the global objects of all inspected contexts, including those created
  875. // later, bindings survive reloads. Binding function takes exactly one argument,
  876. // this argument should be string, in case of any other input, function throws
  877. // an exception. Each binding function call produces Runtime.bindingCalled
  878. // notification.
  879. //
  880. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-addBinding
  881. //
  882. // parameters:
  883. //
  884. // name
  885. func AddBinding(name string) *AddBindingParams {
  886. return &AddBindingParams{
  887. Name: name,
  888. }
  889. }
  890. // WithExecutionContextName if specified, the binding is exposed to the
  891. // executionContext with matching name, even for contexts created after the
  892. // binding is added. See also ExecutionContext.name and worldName parameter to
  893. // Page.addScriptToEvaluateOnNewDocument. This parameter is mutually exclusive
  894. // with executionContextId.
  895. func (p AddBindingParams) WithExecutionContextName(executionContextName string) *AddBindingParams {
  896. p.ExecutionContextName = executionContextName
  897. return &p
  898. }
  899. // Do executes Runtime.addBinding against the provided context.
  900. func (p *AddBindingParams) Do(ctx context.Context) (err error) {
  901. return cdp.Execute(ctx, CommandAddBinding, p, nil)
  902. }
  903. // RemoveBindingParams this method does not remove binding function from
  904. // global object but unsubscribes current runtime agent from
  905. // Runtime.bindingCalled notifications.
  906. type RemoveBindingParams struct {
  907. Name string `json:"name"`
  908. }
  909. // RemoveBinding this method does not remove binding function from global
  910. // object but unsubscribes current runtime agent from Runtime.bindingCalled
  911. // notifications.
  912. //
  913. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-removeBinding
  914. //
  915. // parameters:
  916. //
  917. // name
  918. func RemoveBinding(name string) *RemoveBindingParams {
  919. return &RemoveBindingParams{
  920. Name: name,
  921. }
  922. }
  923. // Do executes Runtime.removeBinding against the provided context.
  924. func (p *RemoveBindingParams) Do(ctx context.Context) (err error) {
  925. return cdp.Execute(ctx, CommandRemoveBinding, p, nil)
  926. }
  927. // GetExceptionDetailsParams this method tries to lookup and populate
  928. // exception details for a JavaScript Error object. Note that the stackTrace
  929. // portion of the resulting exceptionDetails will only be populated if the
  930. // Runtime domain was enabled at the time when the Error was thrown.
  931. type GetExceptionDetailsParams struct {
  932. ErrorObjectID RemoteObjectID `json:"errorObjectId"` // The error object for which to resolve the exception details.
  933. }
  934. // GetExceptionDetails this method tries to lookup and populate exception
  935. // details for a JavaScript Error object. Note that the stackTrace portion of
  936. // the resulting exceptionDetails will only be populated if the Runtime domain
  937. // was enabled at the time when the Error was thrown.
  938. //
  939. // See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-getExceptionDetails
  940. //
  941. // parameters:
  942. //
  943. // errorObjectID - The error object for which to resolve the exception details.
  944. func GetExceptionDetails(errorObjectID RemoteObjectID) *GetExceptionDetailsParams {
  945. return &GetExceptionDetailsParams{
  946. ErrorObjectID: errorObjectID,
  947. }
  948. }
  949. // GetExceptionDetailsReturns return values.
  950. type GetExceptionDetailsReturns struct {
  951. ExceptionDetails *ExceptionDetails `json:"exceptionDetails,omitempty,omitzero"`
  952. }
  953. // Do executes Runtime.getExceptionDetails against the provided context.
  954. //
  955. // returns:
  956. //
  957. // exceptionDetails
  958. func (p *GetExceptionDetailsParams) Do(ctx context.Context) (exceptionDetails *ExceptionDetails, err error) {
  959. // execute
  960. var res GetExceptionDetailsReturns
  961. err = cdp.Execute(ctx, CommandGetExceptionDetails, p, &res)
  962. if err != nil {
  963. return nil, err
  964. }
  965. return res.ExceptionDetails, nil
  966. }
  967. // Command names.
  968. const (
  969. CommandAwaitPromise = "Runtime.awaitPromise"
  970. CommandCallFunctionOn = "Runtime.callFunctionOn"
  971. CommandCompileScript = "Runtime.compileScript"
  972. CommandDisable = "Runtime.disable"
  973. CommandDiscardConsoleEntries = "Runtime.discardConsoleEntries"
  974. CommandEnable = "Runtime.enable"
  975. CommandEvaluate = "Runtime.evaluate"
  976. CommandGetIsolateID = "Runtime.getIsolateId"
  977. CommandGetHeapUsage = "Runtime.getHeapUsage"
  978. CommandGetProperties = "Runtime.getProperties"
  979. CommandGlobalLexicalScopeNames = "Runtime.globalLexicalScopeNames"
  980. CommandQueryObjects = "Runtime.queryObjects"
  981. CommandReleaseObject = "Runtime.releaseObject"
  982. CommandReleaseObjectGroup = "Runtime.releaseObjectGroup"
  983. CommandRunIfWaitingForDebugger = "Runtime.runIfWaitingForDebugger"
  984. CommandRunScript = "Runtime.runScript"
  985. CommandSetCustomObjectFormatterEnabled = "Runtime.setCustomObjectFormatterEnabled"
  986. CommandSetMaxCallStackSizeToCapture = "Runtime.setMaxCallStackSizeToCapture"
  987. CommandTerminateExecution = "Runtime.terminateExecution"
  988. CommandAddBinding = "Runtime.addBinding"
  989. CommandRemoveBinding = "Runtime.removeBinding"
  990. CommandGetExceptionDetails = "Runtime.getExceptionDetails"
  991. )