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