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