forked from mafredri/cdp
/
domain.go
182 lines (161 loc) · 6.53 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
// Code generated by cdpgen. DO NOT EDIT.
// Package fetch implements the Fetch domain. A domain for letting clients
// substitute browser's network layer with client code.
package fetch
import (
"context"
"github.com/mafredri/cdp/protocol/internal"
"github.com/mafredri/cdp/rpcc"
)
// domainClient is a client for the Fetch domain. A domain for letting clients
// substitute browser's network layer with client code.
type domainClient struct{ conn *rpcc.Conn }
// NewClient returns a client for the Fetch domain with the connection set to conn.
func NewClient(conn *rpcc.Conn) *domainClient {
return &domainClient{conn: conn}
}
// Disable invokes the Fetch method. Disables the fetch domain.
func (d *domainClient) Disable(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "Fetch.disable", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "Disable", Err: err}
}
return
}
// Enable invokes the Fetch method. Enables issuing of requestPaused events. A
// request will be paused until client calls one of failRequest, fulfillRequest
// or continueRequest/continueWithAuth.
func (d *domainClient) Enable(ctx context.Context, args *EnableArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Fetch.enable", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Fetch.enable", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "Enable", Err: err}
}
return
}
// FailRequest invokes the Fetch method. Causes the request to fail with
// specified reason.
func (d *domainClient) FailRequest(ctx context.Context, args *FailRequestArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Fetch.failRequest", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Fetch.failRequest", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "FailRequest", Err: err}
}
return
}
// FulfillRequest invokes the Fetch method. Provides response to the request.
func (d *domainClient) FulfillRequest(ctx context.Context, args *FulfillRequestArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Fetch.fulfillRequest", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Fetch.fulfillRequest", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "FulfillRequest", Err: err}
}
return
}
// ContinueRequest invokes the Fetch method. Continues the request, optionally
// modifying some of its parameters.
func (d *domainClient) ContinueRequest(ctx context.Context, args *ContinueRequestArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Fetch.continueRequest", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Fetch.continueRequest", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "ContinueRequest", Err: err}
}
return
}
// ContinueWithAuth invokes the Fetch method. Continues a request supplying
// authChallengeResponse following authRequired event.
func (d *domainClient) ContinueWithAuth(ctx context.Context, args *ContinueWithAuthArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Fetch.continueWithAuth", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Fetch.continueWithAuth", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "ContinueWithAuth", Err: err}
}
return
}
// GetResponseBody invokes the Fetch method. Causes the body of the response
// to be received from the server and returned as a single string. May only be
// issued for a request that is paused in the Response stage and is mutually
// exclusive with takeResponseBodyForInterceptionAsStream. Calling other
// methods that affect the request or disabling fetch domain before body is
// received results in an undefined behavior.
func (d *domainClient) GetResponseBody(ctx context.Context, args *GetResponseBodyArgs) (reply *GetResponseBodyReply, err error) {
reply = new(GetResponseBodyReply)
if args != nil {
err = rpcc.Invoke(ctx, "Fetch.getResponseBody", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Fetch.getResponseBody", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "GetResponseBody", Err: err}
}
return
}
// TakeResponseBodyAsStream invokes the Fetch method. Returns a handle to the
// stream representing the response body. The request must be paused in the
// HeadersReceived stage. Note that after this command the request can't be
// continued as is -- client either needs to cancel it or to provide the
// response body. The stream only supports sequential read, IO.read will fail
// if the position is specified. This method is mutually exclusive with
// getResponseBody. Calling other methods that affect the request or disabling
// fetch domain before body is received results in an undefined behavior.
func (d *domainClient) TakeResponseBodyAsStream(ctx context.Context, args *TakeResponseBodyAsStreamArgs) (reply *TakeResponseBodyAsStreamReply, err error) {
reply = new(TakeResponseBodyAsStreamReply)
if args != nil {
err = rpcc.Invoke(ctx, "Fetch.takeResponseBodyAsStream", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Fetch.takeResponseBodyAsStream", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Fetch", Op: "TakeResponseBodyAsStream", Err: err}
}
return
}
func (d *domainClient) RequestPaused(ctx context.Context) (RequestPausedClient, error) {
s, err := rpcc.NewStream(ctx, "Fetch.requestPaused", d.conn)
if err != nil {
return nil, err
}
return &requestPausedClient{Stream: s}, nil
}
type requestPausedClient struct{ rpcc.Stream }
// GetStream returns the original Stream for use with cdp.Sync.
func (c *requestPausedClient) GetStream() rpcc.Stream { return c.Stream }
func (c *requestPausedClient) Recv() (*RequestPausedReply, error) {
event := new(RequestPausedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "Fetch", Op: "RequestPaused Recv", Err: err}
}
return event, nil
}
func (d *domainClient) AuthRequired(ctx context.Context) (AuthRequiredClient, error) {
s, err := rpcc.NewStream(ctx, "Fetch.authRequired", d.conn)
if err != nil {
return nil, err
}
return &authRequiredClient{Stream: s}, nil
}
type authRequiredClient struct{ rpcc.Stream }
// GetStream returns the original Stream for use with cdp.Sync.
func (c *authRequiredClient) GetStream() rpcc.Stream { return c.Stream }
func (c *authRequiredClient) Recv() (*AuthRequiredReply, error) {
event := new(AuthRequiredReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "Fetch", Op: "AuthRequired Recv", Err: err}
}
return event, nil
}