domsnapshot.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Package domsnapshot provides the Chrome DevTools Protocol
  2. // commands, types, and events for the DOMSnapshot domain.
  3. //
  4. // This domain facilitates obtaining document snapshots with DOM, layout, and
  5. // style information.
  6. //
  7. // Generated by the cdproto-gen command.
  8. package domsnapshot
  9. // Code generated by cdproto-gen. DO NOT EDIT.
  10. import (
  11. "context"
  12. "github.com/chromedp/cdproto/cdp"
  13. )
  14. // DisableParams disables DOM snapshot agent for the given page.
  15. type DisableParams struct{}
  16. // Disable disables DOM snapshot agent for the given page.
  17. //
  18. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOMSnapshot#method-disable
  19. func Disable() *DisableParams {
  20. return &DisableParams{}
  21. }
  22. // Do executes DOMSnapshot.disable against the provided context.
  23. func (p *DisableParams) Do(ctx context.Context) (err error) {
  24. return cdp.Execute(ctx, CommandDisable, nil, nil)
  25. }
  26. // EnableParams enables DOM snapshot agent for the given page.
  27. type EnableParams struct{}
  28. // Enable enables DOM snapshot agent for the given page.
  29. //
  30. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOMSnapshot#method-enable
  31. func Enable() *EnableParams {
  32. return &EnableParams{}
  33. }
  34. // Do executes DOMSnapshot.enable against the provided context.
  35. func (p *EnableParams) Do(ctx context.Context) (err error) {
  36. return cdp.Execute(ctx, CommandEnable, nil, nil)
  37. }
  38. // CaptureSnapshotParams returns a document snapshot, including the full DOM
  39. // tree of the root node (including iframes, template contents, and imported
  40. // documents) in a flattened array, as well as layout and white-listed computed
  41. // style information for the nodes. Shadow DOM in the returned DOM tree is
  42. // flattened.
  43. type CaptureSnapshotParams struct {
  44. ComputedStyles []string `json:"computedStyles"` // Whitelist of computed styles to return.
  45. IncludePaintOrder bool `json:"includePaintOrder,omitempty"` // Whether to include layout object paint orders into the snapshot.
  46. IncludeDOMRects bool `json:"includeDOMRects,omitempty"` // Whether to include DOM rectangles (offsetRects, clientRects, scrollRects) into the snapshot
  47. IncludeBlendedBackgroundColors bool `json:"includeBlendedBackgroundColors,omitempty"` // Whether to include blended background colors in the snapshot (default: false). Blended background color is achieved by blending background colors of all elements that overlap with the current element.
  48. IncludeTextColorOpacities bool `json:"includeTextColorOpacities,omitempty"` // Whether to include text color opacity in the snapshot (default: false). An element might have the opacity property set that affects the text color of the element. The final text color opacity is computed based on the opacity of all overlapping elements.
  49. }
  50. // CaptureSnapshot returns a document snapshot, including the full DOM tree
  51. // of the root node (including iframes, template contents, and imported
  52. // documents) in a flattened array, as well as layout and white-listed computed
  53. // style information for the nodes. Shadow DOM in the returned DOM tree is
  54. // flattened.
  55. //
  56. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOMSnapshot#method-captureSnapshot
  57. //
  58. // parameters:
  59. //
  60. // computedStyles - Whitelist of computed styles to return.
  61. func CaptureSnapshot(computedStyles []string) *CaptureSnapshotParams {
  62. return &CaptureSnapshotParams{
  63. ComputedStyles: computedStyles,
  64. }
  65. }
  66. // WithIncludePaintOrder whether to include layout object paint orders into
  67. // the snapshot.
  68. func (p CaptureSnapshotParams) WithIncludePaintOrder(includePaintOrder bool) *CaptureSnapshotParams {
  69. p.IncludePaintOrder = includePaintOrder
  70. return &p
  71. }
  72. // WithIncludeDOMRects whether to include DOM rectangles (offsetRects,
  73. // clientRects, scrollRects) into the snapshot.
  74. func (p CaptureSnapshotParams) WithIncludeDOMRects(includeDOMRects bool) *CaptureSnapshotParams {
  75. p.IncludeDOMRects = includeDOMRects
  76. return &p
  77. }
  78. // WithIncludeBlendedBackgroundColors whether to include blended background
  79. // colors in the snapshot (default: false). Blended background color is achieved
  80. // by blending background colors of all elements that overlap with the current
  81. // element.
  82. func (p CaptureSnapshotParams) WithIncludeBlendedBackgroundColors(includeBlendedBackgroundColors bool) *CaptureSnapshotParams {
  83. p.IncludeBlendedBackgroundColors = includeBlendedBackgroundColors
  84. return &p
  85. }
  86. // WithIncludeTextColorOpacities whether to include text color opacity in the
  87. // snapshot (default: false). An element might have the opacity property set
  88. // that affects the text color of the element. The final text color opacity is
  89. // computed based on the opacity of all overlapping elements.
  90. func (p CaptureSnapshotParams) WithIncludeTextColorOpacities(includeTextColorOpacities bool) *CaptureSnapshotParams {
  91. p.IncludeTextColorOpacities = includeTextColorOpacities
  92. return &p
  93. }
  94. // CaptureSnapshotReturns return values.
  95. type CaptureSnapshotReturns struct {
  96. Documents []*DocumentSnapshot `json:"documents,omitempty"` // The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
  97. Strings []string `json:"strings,omitempty"` // Shared string table that all string properties refer to with indexes.
  98. }
  99. // Do executes DOMSnapshot.captureSnapshot against the provided context.
  100. //
  101. // returns:
  102. //
  103. // documents - The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
  104. // strings - Shared string table that all string properties refer to with indexes.
  105. func (p *CaptureSnapshotParams) Do(ctx context.Context) (documents []*DocumentSnapshot, strings []string, err error) {
  106. // execute
  107. var res CaptureSnapshotReturns
  108. err = cdp.Execute(ctx, CommandCaptureSnapshot, p, &res)
  109. if err != nil {
  110. return nil, nil, err
  111. }
  112. return res.Documents, res.Strings, nil
  113. }
  114. // Command names.
  115. const (
  116. CommandDisable = "DOMSnapshot.disable"
  117. CommandEnable = "DOMSnapshot.enable"
  118. CommandCaptureSnapshot = "DOMSnapshot.captureSnapshot"
  119. )