-
Notifications
You must be signed in to change notification settings - Fork 48
/
domain.go
388 lines (346 loc) · 15.4 KB
/
domain.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
// Code generated by cdpgen. DO NOT EDIT.
// Package css implements the CSS domain. This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles) have an associated id used in subsequent operations on the related object. Each object type has a specific id structure, and those are not interchangeable between objects of different kinds. CSS objects can be loaded using the get*ForNode() calls (which accept a DOM node id). A client can also keep track of stylesheets via the styleSheetAdded/styleSheetRemoved events and subsequently load the required stylesheet contents using the getStyleSheet[Text]() methods.
package css
import (
"context"
"github.com/mafredri/cdp/protocol/internal"
"github.com/mafredri/cdp/rpcc"
)
// domainClient is a client for the CSS domain. This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles) have an associated id used in subsequent operations on the related object. Each object type has a specific id structure, and those are not interchangeable between objects of different kinds. CSS objects can be loaded using the get*ForNode() calls (which accept a DOM node id). A client can also keep track of stylesheets via the styleSheetAdded/styleSheetRemoved events and subsequently load the required stylesheet contents using the getStyleSheet[Text]() methods.
type domainClient struct{ conn *rpcc.Conn }
// NewClient returns a client for the CSS domain with the connection set to conn.
func NewClient(conn *rpcc.Conn) *domainClient {
return &domainClient{conn: conn}
}
// Enable invokes the CSS method. Enables the CSS agent for the given page. Clients should not assume that the CSS agent has been enabled until the result of this command is received.
func (d *domainClient) Enable(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "CSS.enable", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "Enable", Err: err}
}
return
}
// Disable invokes the CSS method. Disables the CSS agent for the given page.
func (d *domainClient) Disable(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "CSS.disable", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "Disable", Err: err}
}
return
}
// GetMatchedStylesForNode invokes the CSS method. Returns requested styles for a DOM node identified by nodeId.
func (d *domainClient) GetMatchedStylesForNode(ctx context.Context, args *GetMatchedStylesForNodeArgs) (reply *GetMatchedStylesForNodeReply, err error) {
reply = new(GetMatchedStylesForNodeReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.getMatchedStylesForNode", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.getMatchedStylesForNode", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "GetMatchedStylesForNode", Err: err}
}
return
}
// GetInlineStylesForNode invokes the CSS method. Returns the styles defined inline (explicitly in the "style" attribute and implicitly, using DOM attributes) for a DOM node identified by nodeId.
func (d *domainClient) GetInlineStylesForNode(ctx context.Context, args *GetInlineStylesForNodeArgs) (reply *GetInlineStylesForNodeReply, err error) {
reply = new(GetInlineStylesForNodeReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.getInlineStylesForNode", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.getInlineStylesForNode", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "GetInlineStylesForNode", Err: err}
}
return
}
// GetComputedStyleForNode invokes the CSS method. Returns the computed style for a DOM node identified by nodeId.
func (d *domainClient) GetComputedStyleForNode(ctx context.Context, args *GetComputedStyleForNodeArgs) (reply *GetComputedStyleForNodeReply, err error) {
reply = new(GetComputedStyleForNodeReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.getComputedStyleForNode", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.getComputedStyleForNode", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "GetComputedStyleForNode", Err: err}
}
return
}
// GetPlatformFontsForNode invokes the CSS method. Requests information about platform fonts which we used to render child TextNodes in the given node.
func (d *domainClient) GetPlatformFontsForNode(ctx context.Context, args *GetPlatformFontsForNodeArgs) (reply *GetPlatformFontsForNodeReply, err error) {
reply = new(GetPlatformFontsForNodeReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.getPlatformFontsForNode", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.getPlatformFontsForNode", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "GetPlatformFontsForNode", Err: err}
}
return
}
// GetStyleSheetText invokes the CSS method. Returns the current textual content and the URL for a stylesheet.
func (d *domainClient) GetStyleSheetText(ctx context.Context, args *GetStyleSheetTextArgs) (reply *GetStyleSheetTextReply, err error) {
reply = new(GetStyleSheetTextReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.getStyleSheetText", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.getStyleSheetText", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "GetStyleSheetText", Err: err}
}
return
}
// CollectClassNames invokes the CSS method. Returns all class names from specified stylesheet.
func (d *domainClient) CollectClassNames(ctx context.Context, args *CollectClassNamesArgs) (reply *CollectClassNamesReply, err error) {
reply = new(CollectClassNamesReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.collectClassNames", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.collectClassNames", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "CollectClassNames", Err: err}
}
return
}
// SetStyleSheetText invokes the CSS method. Sets the new stylesheet text.
func (d *domainClient) SetStyleSheetText(ctx context.Context, args *SetStyleSheetTextArgs) (reply *SetStyleSheetTextReply, err error) {
reply = new(SetStyleSheetTextReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.setStyleSheetText", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.setStyleSheetText", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "SetStyleSheetText", Err: err}
}
return
}
// SetRuleSelector invokes the CSS method. Modifies the rule selector.
func (d *domainClient) SetRuleSelector(ctx context.Context, args *SetRuleSelectorArgs) (reply *SetRuleSelectorReply, err error) {
reply = new(SetRuleSelectorReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.setRuleSelector", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.setRuleSelector", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "SetRuleSelector", Err: err}
}
return
}
// SetKeyframeKey invokes the CSS method. Modifies the keyframe rule key text.
func (d *domainClient) SetKeyframeKey(ctx context.Context, args *SetKeyframeKeyArgs) (reply *SetKeyframeKeyReply, err error) {
reply = new(SetKeyframeKeyReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.setKeyframeKey", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.setKeyframeKey", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "SetKeyframeKey", Err: err}
}
return
}
// SetStyleTexts invokes the CSS method. Applies specified style edits one after another in the given order.
func (d *domainClient) SetStyleTexts(ctx context.Context, args *SetStyleTextsArgs) (reply *SetStyleTextsReply, err error) {
reply = new(SetStyleTextsReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.setStyleTexts", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.setStyleTexts", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "SetStyleTexts", Err: err}
}
return
}
// SetMediaText invokes the CSS method. Modifies the rule selector.
func (d *domainClient) SetMediaText(ctx context.Context, args *SetMediaTextArgs) (reply *SetMediaTextReply, err error) {
reply = new(SetMediaTextReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.setMediaText", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.setMediaText", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "SetMediaText", Err: err}
}
return
}
// CreateStyleSheet invokes the CSS method. Creates a new special "via-inspector" stylesheet in the frame with given frameId.
func (d *domainClient) CreateStyleSheet(ctx context.Context, args *CreateStyleSheetArgs) (reply *CreateStyleSheetReply, err error) {
reply = new(CreateStyleSheetReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.createStyleSheet", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.createStyleSheet", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "CreateStyleSheet", Err: err}
}
return
}
// AddRule invokes the CSS method. Inserts a new rule with the given ruleText in a stylesheet with given styleSheetId, at the position specified by location.
func (d *domainClient) AddRule(ctx context.Context, args *AddRuleArgs) (reply *AddRuleReply, err error) {
reply = new(AddRuleReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.addRule", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.addRule", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "AddRule", Err: err}
}
return
}
// ForcePseudoState invokes the CSS method. Ensures that the given node will have specified pseudo-classes whenever its style is computed by the browser.
func (d *domainClient) ForcePseudoState(ctx context.Context, args *ForcePseudoStateArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "CSS.forcePseudoState", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.forcePseudoState", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "ForcePseudoState", Err: err}
}
return
}
// GetMediaQueries invokes the CSS method. Returns all media queries parsed by the rendering engine.
func (d *domainClient) GetMediaQueries(ctx context.Context) (reply *GetMediaQueriesReply, err error) {
reply = new(GetMediaQueriesReply)
err = rpcc.Invoke(ctx, "CSS.getMediaQueries", nil, reply, d.conn)
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "GetMediaQueries", Err: err}
}
return
}
// SetEffectivePropertyValueForNode invokes the CSS method. Find a rule with the given active property for the given node and set the new value for this property
func (d *domainClient) SetEffectivePropertyValueForNode(ctx context.Context, args *SetEffectivePropertyValueForNodeArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "CSS.setEffectivePropertyValueForNode", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.setEffectivePropertyValueForNode", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "SetEffectivePropertyValueForNode", Err: err}
}
return
}
// GetBackgroundColors invokes the CSS method.
func (d *domainClient) GetBackgroundColors(ctx context.Context, args *GetBackgroundColorsArgs) (reply *GetBackgroundColorsReply, err error) {
reply = new(GetBackgroundColorsReply)
if args != nil {
err = rpcc.Invoke(ctx, "CSS.getBackgroundColors", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "CSS.getBackgroundColors", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "GetBackgroundColors", Err: err}
}
return
}
// StartRuleUsageTracking invokes the CSS method. Enables the selector recording.
func (d *domainClient) StartRuleUsageTracking(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "CSS.startRuleUsageTracking", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "StartRuleUsageTracking", Err: err}
}
return
}
// TakeCoverageDelta invokes the CSS method. Obtain list of rules that became used since last call to this method (or since start of coverage instrumentation)
func (d *domainClient) TakeCoverageDelta(ctx context.Context) (reply *TakeCoverageDeltaReply, err error) {
reply = new(TakeCoverageDeltaReply)
err = rpcc.Invoke(ctx, "CSS.takeCoverageDelta", nil, reply, d.conn)
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "TakeCoverageDelta", Err: err}
}
return
}
// StopRuleUsageTracking invokes the CSS method. The list of rules with an indication of whether these were used
func (d *domainClient) StopRuleUsageTracking(ctx context.Context) (reply *StopRuleUsageTrackingReply, err error) {
reply = new(StopRuleUsageTrackingReply)
err = rpcc.Invoke(ctx, "CSS.stopRuleUsageTracking", nil, reply, d.conn)
if err != nil {
err = &internal.OpError{Domain: "CSS", Op: "StopRuleUsageTracking", Err: err}
}
return
}
func (d *domainClient) MediaQueryResultChanged(ctx context.Context) (MediaQueryResultChangedClient, error) {
s, err := rpcc.NewStream(ctx, "CSS.mediaQueryResultChanged", d.conn)
if err != nil {
return nil, err
}
return &mediaQueryResultChangedClient{Stream: s}, nil
}
type mediaQueryResultChangedClient struct{ rpcc.Stream }
func (c *mediaQueryResultChangedClient) Recv() (*MediaQueryResultChangedReply, error) {
event := new(MediaQueryResultChangedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "CSS", Op: "MediaQueryResultChanged Recv", Err: err}
}
return event, nil
}
func (d *domainClient) FontsUpdated(ctx context.Context) (FontsUpdatedClient, error) {
s, err := rpcc.NewStream(ctx, "CSS.fontsUpdated", d.conn)
if err != nil {
return nil, err
}
return &fontsUpdatedClient{Stream: s}, nil
}
type fontsUpdatedClient struct{ rpcc.Stream }
func (c *fontsUpdatedClient) Recv() (*FontsUpdatedReply, error) {
event := new(FontsUpdatedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "CSS", Op: "FontsUpdated Recv", Err: err}
}
return event, nil
}
func (d *domainClient) StyleSheetChanged(ctx context.Context) (StyleSheetChangedClient, error) {
s, err := rpcc.NewStream(ctx, "CSS.styleSheetChanged", d.conn)
if err != nil {
return nil, err
}
return &styleSheetChangedClient{Stream: s}, nil
}
type styleSheetChangedClient struct{ rpcc.Stream }
func (c *styleSheetChangedClient) Recv() (*StyleSheetChangedReply, error) {
event := new(StyleSheetChangedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "CSS", Op: "StyleSheetChanged Recv", Err: err}
}
return event, nil
}
func (d *domainClient) StyleSheetAdded(ctx context.Context) (StyleSheetAddedClient, error) {
s, err := rpcc.NewStream(ctx, "CSS.styleSheetAdded", d.conn)
if err != nil {
return nil, err
}
return &styleSheetAddedClient{Stream: s}, nil
}
type styleSheetAddedClient struct{ rpcc.Stream }
func (c *styleSheetAddedClient) Recv() (*StyleSheetAddedReply, error) {
event := new(StyleSheetAddedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "CSS", Op: "StyleSheetAdded Recv", Err: err}
}
return event, nil
}
func (d *domainClient) StyleSheetRemoved(ctx context.Context) (StyleSheetRemovedClient, error) {
s, err := rpcc.NewStream(ctx, "CSS.styleSheetRemoved", d.conn)
if err != nil {
return nil, err
}
return &styleSheetRemovedClient{Stream: s}, nil
}
type styleSheetRemovedClient struct{ rpcc.Stream }
func (c *styleSheetRemovedClient) Recv() (*StyleSheetRemovedReply, error) {
event := new(StyleSheetRemovedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "CSS", Op: "StyleSheetRemoved Recv", Err: err}
}
return event, nil
}