audits.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Package audits provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Audits domain.
  3. //
  4. // Audits domain allows investigation of page violations and possible
  5. // improvements.
  6. //
  7. // Generated by the cdproto-gen command.
  8. package audits
  9. // Code generated by cdproto-gen. DO NOT EDIT.
  10. import (
  11. "context"
  12. "encoding/base64"
  13. "github.com/chromedp/cdproto/cdp"
  14. "github.com/chromedp/cdproto/network"
  15. )
  16. // GetEncodedResponseParams returns the response body and size if it were
  17. // re-encoded with the specified settings. Only applies to images.
  18. type GetEncodedResponseParams struct {
  19. RequestID network.RequestID `json:"requestId"` // Identifier of the network request to get content for.
  20. Encoding GetEncodedResponseEncoding `json:"encoding"` // The encoding to use.
  21. Quality float64 `json:"quality,omitempty,omitzero"` // The quality of the encoding (0-1). (defaults to 1)
  22. SizeOnly bool `json:"sizeOnly"` // Whether to only return the size information (defaults to false).
  23. }
  24. // GetEncodedResponse returns the response body and size if it were
  25. // re-encoded with the specified settings. Only applies to images.
  26. //
  27. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-getEncodedResponse
  28. //
  29. // parameters:
  30. //
  31. // requestID - Identifier of the network request to get content for.
  32. // encoding - The encoding to use.
  33. func GetEncodedResponse(requestID network.RequestID, encoding GetEncodedResponseEncoding) *GetEncodedResponseParams {
  34. return &GetEncodedResponseParams{
  35. RequestID: requestID,
  36. Encoding: encoding,
  37. SizeOnly: false,
  38. }
  39. }
  40. // WithQuality the quality of the encoding (0-1). (defaults to 1).
  41. func (p GetEncodedResponseParams) WithQuality(quality float64) *GetEncodedResponseParams {
  42. p.Quality = quality
  43. return &p
  44. }
  45. // WithSizeOnly whether to only return the size information (defaults to
  46. // false).
  47. func (p GetEncodedResponseParams) WithSizeOnly(sizeOnly bool) *GetEncodedResponseParams {
  48. p.SizeOnly = sizeOnly
  49. return &p
  50. }
  51. // GetEncodedResponseReturns return values.
  52. type GetEncodedResponseReturns struct {
  53. Body string `json:"body,omitempty,omitzero"` // The encoded body as a base64 string. Omitted if sizeOnly is true.
  54. OriginalSize int64 `json:"originalSize,omitempty,omitzero"` // Size before re-encoding.
  55. EncodedSize int64 `json:"encodedSize,omitempty,omitzero"` // Size after re-encoding.
  56. }
  57. // Do executes Audits.getEncodedResponse against the provided context.
  58. //
  59. // returns:
  60. //
  61. // body - The encoded body as a base64 string. Omitted if sizeOnly is true.
  62. // originalSize - Size before re-encoding.
  63. // encodedSize - Size after re-encoding.
  64. func (p *GetEncodedResponseParams) Do(ctx context.Context) (body []byte, originalSize int64, encodedSize int64, err error) {
  65. // execute
  66. var res GetEncodedResponseReturns
  67. err = cdp.Execute(ctx, CommandGetEncodedResponse, p, &res)
  68. if err != nil {
  69. return nil, 0, 0, err
  70. }
  71. // decode
  72. var dec []byte
  73. dec, err = base64.StdEncoding.DecodeString(res.Body)
  74. if err != nil {
  75. return nil, 0, 0, err
  76. }
  77. return dec, res.OriginalSize, res.EncodedSize, nil
  78. }
  79. // DisableParams disables issues domain, prevents further issues from being
  80. // reported to the client.
  81. type DisableParams struct{}
  82. // Disable disables issues domain, prevents further issues from being
  83. // reported to the client.
  84. //
  85. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-disable
  86. func Disable() *DisableParams {
  87. return &DisableParams{}
  88. }
  89. // Do executes Audits.disable against the provided context.
  90. func (p *DisableParams) Do(ctx context.Context) (err error) {
  91. return cdp.Execute(ctx, CommandDisable, nil, nil)
  92. }
  93. // EnableParams enables issues domain, sends the issues collected so far to
  94. // the client by means of the issueAdded event.
  95. type EnableParams struct{}
  96. // Enable enables issues domain, sends the issues collected so far to the
  97. // client by means of the issueAdded event.
  98. //
  99. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-enable
  100. func Enable() *EnableParams {
  101. return &EnableParams{}
  102. }
  103. // Do executes Audits.enable against the provided context.
  104. func (p *EnableParams) Do(ctx context.Context) (err error) {
  105. return cdp.Execute(ctx, CommandEnable, nil, nil)
  106. }
  107. // CheckContrastParams runs the contrast check for the target page. Found
  108. // issues are reported using Audits.issueAdded event.
  109. type CheckContrastParams struct {
  110. ReportAAA bool `json:"reportAAA"` // Whether to report WCAG AAA level issues. Default is false.
  111. }
  112. // CheckContrast runs the contrast check for the target page. Found issues
  113. // are reported using Audits.issueAdded event.
  114. //
  115. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-checkContrast
  116. //
  117. // parameters:
  118. func CheckContrast() *CheckContrastParams {
  119. return &CheckContrastParams{
  120. ReportAAA: false,
  121. }
  122. }
  123. // WithReportAAA whether to report WCAG AAA level issues. Default is false.
  124. func (p CheckContrastParams) WithReportAAA(reportAAA bool) *CheckContrastParams {
  125. p.ReportAAA = reportAAA
  126. return &p
  127. }
  128. // Do executes Audits.checkContrast against the provided context.
  129. func (p *CheckContrastParams) Do(ctx context.Context) (err error) {
  130. return cdp.Execute(ctx, CommandCheckContrast, p, nil)
  131. }
  132. // CheckFormsIssuesParams runs the form issues check for the target page.
  133. // Found issues are reported using Audits.issueAdded event.
  134. type CheckFormsIssuesParams struct{}
  135. // CheckFormsIssues runs the form issues check for the target page. Found
  136. // issues are reported using Audits.issueAdded event.
  137. //
  138. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-checkFormsIssues
  139. func CheckFormsIssues() *CheckFormsIssuesParams {
  140. return &CheckFormsIssuesParams{}
  141. }
  142. // CheckFormsIssuesReturns return values.
  143. type CheckFormsIssuesReturns struct {
  144. FormIssues []*GenericIssueDetails `json:"formIssues,omitempty,omitzero"`
  145. }
  146. // Do executes Audits.checkFormsIssues against the provided context.
  147. //
  148. // returns:
  149. //
  150. // formIssues
  151. func (p *CheckFormsIssuesParams) Do(ctx context.Context) (formIssues []*GenericIssueDetails, err error) {
  152. // execute
  153. var res CheckFormsIssuesReturns
  154. err = cdp.Execute(ctx, CommandCheckFormsIssues, nil, &res)
  155. if err != nil {
  156. return nil, err
  157. }
  158. return res.FormIssues, nil
  159. }
  160. // Command names.
  161. const (
  162. CommandGetEncodedResponse = "Audits.getEncodedResponse"
  163. CommandDisable = "Audits.disable"
  164. CommandEnable = "Audits.enable"
  165. CommandCheckContrast = "Audits.checkContrast"
  166. CommandCheckFormsIssues = "Audits.checkFormsIssues"
  167. )