headlessexperimental.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Package headlessexperimental provides the Chrome DevTools Protocol
  2. // commands, types, and events for the HeadlessExperimental domain.
  3. //
  4. // This domain provides experimental commands only supported in headless
  5. // mode.
  6. //
  7. // Generated by the cdproto-gen command.
  8. package headlessexperimental
  9. // Code generated by cdproto-gen. DO NOT EDIT.
  10. import (
  11. "context"
  12. "encoding/base64"
  13. "github.com/chromedp/cdproto/cdp"
  14. )
  15. // BeginFrameParams sends a BeginFrame to the target and returns when the
  16. // frame was completed. Optionally captures a screenshot from the resulting
  17. // frame. Requires that the target was created with enabled BeginFrameControl.
  18. // Designed for use with --run-all-compositor-stages-before-draw, see also
  19. // https://goo.gle/chrome-headless-rendering for more background.
  20. type BeginFrameParams struct {
  21. FrameTimeTicks float64 `json:"frameTimeTicks,omitempty"` // Timestamp of this BeginFrame in Renderer TimeTicks (milliseconds of uptime). If not set, the current time will be used.
  22. Interval float64 `json:"interval,omitempty"` // The interval between BeginFrames that is reported to the compositor, in milliseconds. Defaults to a 60 frames/second interval, i.e. about 16.666 milliseconds.
  23. NoDisplayUpdates bool `json:"noDisplayUpdates,omitempty"` // Whether updates should not be committed and drawn onto the display. False by default. If true, only side effects of the BeginFrame will be run, such as layout and animations, but any visual updates may not be visible on the display or in screenshots.
  24. Screenshot *ScreenshotParams `json:"screenshot,omitempty"` // If set, a screenshot of the frame will be captured and returned in the response. Otherwise, no screenshot will be captured. Note that capturing a screenshot can fail, for example, during renderer initialization. In such a case, no screenshot data will be returned.
  25. }
  26. // BeginFrame sends a BeginFrame to the target and returns when the frame was
  27. // completed. Optionally captures a screenshot from the resulting frame.
  28. // Requires that the target was created with enabled BeginFrameControl. Designed
  29. // for use with --run-all-compositor-stages-before-draw, see also
  30. // https://goo.gle/chrome-headless-rendering for more background.
  31. //
  32. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeadlessExperimental#method-beginFrame
  33. //
  34. // parameters:
  35. func BeginFrame() *BeginFrameParams {
  36. return &BeginFrameParams{}
  37. }
  38. // WithFrameTimeTicks timestamp of this BeginFrame in Renderer TimeTicks
  39. // (milliseconds of uptime). If not set, the current time will be used.
  40. func (p BeginFrameParams) WithFrameTimeTicks(frameTimeTicks float64) *BeginFrameParams {
  41. p.FrameTimeTicks = frameTimeTicks
  42. return &p
  43. }
  44. // WithInterval the interval between BeginFrames that is reported to the
  45. // compositor, in milliseconds. Defaults to a 60 frames/second interval, i.e.
  46. // about 16.666 milliseconds.
  47. func (p BeginFrameParams) WithInterval(interval float64) *BeginFrameParams {
  48. p.Interval = interval
  49. return &p
  50. }
  51. // WithNoDisplayUpdates whether updates should not be committed and drawn
  52. // onto the display. False by default. If true, only side effects of the
  53. // BeginFrame will be run, such as layout and animations, but any visual updates
  54. // may not be visible on the display or in screenshots.
  55. func (p BeginFrameParams) WithNoDisplayUpdates(noDisplayUpdates bool) *BeginFrameParams {
  56. p.NoDisplayUpdates = noDisplayUpdates
  57. return &p
  58. }
  59. // WithScreenshot if set, a screenshot of the frame will be captured and
  60. // returned in the response. Otherwise, no screenshot will be captured. Note
  61. // that capturing a screenshot can fail, for example, during renderer
  62. // initialization. In such a case, no screenshot data will be returned.
  63. func (p BeginFrameParams) WithScreenshot(screenshot *ScreenshotParams) *BeginFrameParams {
  64. p.Screenshot = screenshot
  65. return &p
  66. }
  67. // BeginFrameReturns return values.
  68. type BeginFrameReturns struct {
  69. HasDamage bool `json:"hasDamage,omitempty"` // Whether the BeginFrame resulted in damage and, thus, a new frame was committed to the display. Reported for diagnostic uses, may be removed in the future.
  70. ScreenshotData string `json:"screenshotData,omitempty"` // Base64-encoded image data of the screenshot, if one was requested and successfully taken.
  71. }
  72. // Do executes HeadlessExperimental.beginFrame against the provided context.
  73. //
  74. // returns:
  75. //
  76. // hasDamage - Whether the BeginFrame resulted in damage and, thus, a new frame was committed to the display. Reported for diagnostic uses, may be removed in the future.
  77. // screenshotData - Base64-encoded image data of the screenshot, if one was requested and successfully taken.
  78. func (p *BeginFrameParams) Do(ctx context.Context) (hasDamage bool, screenshotData []byte, err error) {
  79. // execute
  80. var res BeginFrameReturns
  81. err = cdp.Execute(ctx, CommandBeginFrame, p, &res)
  82. if err != nil {
  83. return false, nil, err
  84. }
  85. // decode
  86. var dec []byte
  87. dec, err = base64.StdEncoding.DecodeString(res.ScreenshotData)
  88. if err != nil {
  89. return false, nil, err
  90. }
  91. return res.HasDamage, dec, nil
  92. }
  93. // Command names.
  94. const (
  95. CommandBeginFrame = "HeadlessExperimental.beginFrame"
  96. )