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