audits.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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"` // The quality of the encoding (0-1). (defaults to 1)
  22. SizeOnly bool `json:"sizeOnly,omitempty"` // 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. }
  38. }
  39. // WithQuality the quality of the encoding (0-1). (defaults to 1).
  40. func (p GetEncodedResponseParams) WithQuality(quality float64) *GetEncodedResponseParams {
  41. p.Quality = quality
  42. return &p
  43. }
  44. // WithSizeOnly whether to only return the size information (defaults to
  45. // false).
  46. func (p GetEncodedResponseParams) WithSizeOnly(sizeOnly bool) *GetEncodedResponseParams {
  47. p.SizeOnly = sizeOnly
  48. return &p
  49. }
  50. // GetEncodedResponseReturns return values.
  51. type GetEncodedResponseReturns struct {
  52. Body string `json:"body,omitempty"` // The encoded body as a base64 string. Omitted if sizeOnly is true.
  53. OriginalSize int64 `json:"originalSize,omitempty"` // Size before re-encoding.
  54. EncodedSize int64 `json:"encodedSize,omitempty"` // Size after re-encoding.
  55. }
  56. // Do executes Audits.getEncodedResponse against the provided context.
  57. //
  58. // returns:
  59. //
  60. // body - The encoded body as a base64 string. Omitted if sizeOnly is true.
  61. // originalSize - Size before re-encoding.
  62. // encodedSize - Size after re-encoding.
  63. func (p *GetEncodedResponseParams) Do(ctx context.Context) (body []byte, originalSize int64, encodedSize int64, err error) {
  64. // execute
  65. var res GetEncodedResponseReturns
  66. err = cdp.Execute(ctx, CommandGetEncodedResponse, p, &res)
  67. if err != nil {
  68. return nil, 0, 0, err
  69. }
  70. // decode
  71. var dec []byte
  72. dec, err = base64.StdEncoding.DecodeString(res.Body)
  73. if err != nil {
  74. return nil, 0, 0, err
  75. }
  76. return dec, res.OriginalSize, res.EncodedSize, nil
  77. }
  78. // DisableParams disables issues domain, prevents further issues from being
  79. // reported to the client.
  80. type DisableParams struct{}
  81. // Disable disables issues domain, prevents further issues from being
  82. // reported to the client.
  83. //
  84. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-disable
  85. func Disable() *DisableParams {
  86. return &DisableParams{}
  87. }
  88. // Do executes Audits.disable against the provided context.
  89. func (p *DisableParams) Do(ctx context.Context) (err error) {
  90. return cdp.Execute(ctx, CommandDisable, nil, nil)
  91. }
  92. // EnableParams enables issues domain, sends the issues collected so far to
  93. // the client by means of the issueAdded event.
  94. type EnableParams struct{}
  95. // Enable enables issues domain, sends the issues collected so far to the
  96. // client by means of the issueAdded event.
  97. //
  98. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-enable
  99. func Enable() *EnableParams {
  100. return &EnableParams{}
  101. }
  102. // Do executes Audits.enable against the provided context.
  103. func (p *EnableParams) Do(ctx context.Context) (err error) {
  104. return cdp.Execute(ctx, CommandEnable, nil, nil)
  105. }
  106. // CheckContrastParams runs the contrast check for the target page. Found
  107. // issues are reported using Audits.issueAdded event.
  108. type CheckContrastParams struct {
  109. ReportAAA bool `json:"reportAAA,omitempty"` // Whether to report WCAG AAA level issues. Default is false.
  110. }
  111. // CheckContrast runs the contrast check for the target page. Found issues
  112. // are reported using Audits.issueAdded event.
  113. //
  114. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-checkContrast
  115. //
  116. // parameters:
  117. func CheckContrast() *CheckContrastParams {
  118. return &CheckContrastParams{}
  119. }
  120. // WithReportAAA whether to report WCAG AAA level issues. Default is false.
  121. func (p CheckContrastParams) WithReportAAA(reportAAA bool) *CheckContrastParams {
  122. p.ReportAAA = reportAAA
  123. return &p
  124. }
  125. // Do executes Audits.checkContrast against the provided context.
  126. func (p *CheckContrastParams) Do(ctx context.Context) (err error) {
  127. return cdp.Execute(ctx, CommandCheckContrast, p, nil)
  128. }
  129. // CheckFormsIssuesParams runs the form issues check for the target page.
  130. // Found issues are reported using Audits.issueAdded event.
  131. type CheckFormsIssuesParams struct{}
  132. // CheckFormsIssues runs the form issues check for the target page. Found
  133. // issues are reported using Audits.issueAdded event.
  134. //
  135. // See: https://chromedevtools.github.io/devtools-protocol/tot/Audits#method-checkFormsIssues
  136. func CheckFormsIssues() *CheckFormsIssuesParams {
  137. return &CheckFormsIssuesParams{}
  138. }
  139. // CheckFormsIssuesReturns return values.
  140. type CheckFormsIssuesReturns struct {
  141. FormIssues []*GenericIssueDetails `json:"formIssues,omitempty"`
  142. }
  143. // Do executes Audits.checkFormsIssues against the provided context.
  144. //
  145. // returns:
  146. //
  147. // formIssues
  148. func (p *CheckFormsIssuesParams) Do(ctx context.Context) (formIssues []*GenericIssueDetails, err error) {
  149. // execute
  150. var res CheckFormsIssuesReturns
  151. err = cdp.Execute(ctx, CommandCheckFormsIssues, nil, &res)
  152. if err != nil {
  153. return nil, err
  154. }
  155. return res.FormIssues, nil
  156. }
  157. // Command names.
  158. const (
  159. CommandGetEncodedResponse = "Audits.getEncodedResponse"
  160. CommandDisable = "Audits.disable"
  161. CommandEnable = "Audits.enable"
  162. CommandCheckContrast = "Audits.checkContrast"
  163. CommandCheckFormsIssues = "Audits.checkFormsIssues"
  164. )