forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.go
410 lines (303 loc) · 14.6 KB
/
fetch.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
// This file is generated by "./lib/proto/generate"
package proto
/*
Fetch
A domain for letting clients substitute browser's network layer with client code.
*/
// FetchRequestID Unique request identifier.
type FetchRequestID string
// FetchRequestStage Stages of the request to handle. Request will intercept before the request is
// sent. Response will intercept after the response is received (but before response
// body is received).
type FetchRequestStage string
const (
// FetchRequestStageRequest enum const
FetchRequestStageRequest FetchRequestStage = "Request"
// FetchRequestStageResponse enum const
FetchRequestStageResponse FetchRequestStage = "Response"
)
// FetchRequestPattern ...
type FetchRequestPattern struct {
// URLPattern (optional) Wildcards (`'*'` -> zero or more, `'?'` -> exactly one) are allowed. Escape character is
// backslash. Omitting is equivalent to `"*"`.
URLPattern string `json:"urlPattern,omitempty"`
// ResourceType (optional) If set, only requests for matching resource types will be intercepted.
ResourceType NetworkResourceType `json:"resourceType,omitempty"`
// RequestStage (optional) Stage at which to begin intercepting requests. Default is Request.
RequestStage FetchRequestStage `json:"requestStage,omitempty"`
}
// FetchHeaderEntry Response HTTP header entry
type FetchHeaderEntry struct {
// Name ...
Name string `json:"name"`
// Value ...
Value string `json:"value"`
}
// FetchAuthChallengeSource enum
type FetchAuthChallengeSource string
const (
// FetchAuthChallengeSourceServer enum const
FetchAuthChallengeSourceServer FetchAuthChallengeSource = "Server"
// FetchAuthChallengeSourceProxy enum const
FetchAuthChallengeSourceProxy FetchAuthChallengeSource = "Proxy"
)
// FetchAuthChallenge Authorization challenge for HTTP status code 401 or 407.
type FetchAuthChallenge struct {
// Source (optional) Source of the authentication challenge.
Source FetchAuthChallengeSource `json:"source,omitempty"`
// Origin Origin of the challenger.
Origin string `json:"origin"`
// Scheme The authentication scheme used, such as basic or digest
Scheme string `json:"scheme"`
// Realm The realm of the challenge. May be empty.
Realm string `json:"realm"`
}
// FetchAuthChallengeResponseResponse enum
type FetchAuthChallengeResponseResponse string
const (
// FetchAuthChallengeResponseResponseDefault enum const
FetchAuthChallengeResponseResponseDefault FetchAuthChallengeResponseResponse = "Default"
// FetchAuthChallengeResponseResponseCancelAuth enum const
FetchAuthChallengeResponseResponseCancelAuth FetchAuthChallengeResponseResponse = "CancelAuth"
// FetchAuthChallengeResponseResponseProvideCredentials enum const
FetchAuthChallengeResponseResponseProvideCredentials FetchAuthChallengeResponseResponse = "ProvideCredentials"
)
// FetchAuthChallengeResponse Response to an AuthChallenge.
type FetchAuthChallengeResponse struct {
// Response The decision on what to do in response to the authorization challenge. Default means
// deferring to the default behavior of the net stack, which will likely either the Cancel
// authentication or display a popup dialog box.
Response FetchAuthChallengeResponseResponse `json:"response"`
// Username (optional) The username to provide, possibly empty. Should only be set if response is
// ProvideCredentials.
Username string `json:"username,omitempty"`
// Password (optional) The password to provide, possibly empty. Should only be set if response is
// ProvideCredentials.
Password string `json:"password,omitempty"`
}
// FetchDisable Disables the fetch domain.
type FetchDisable struct {
}
// ProtoReq name
func (m FetchDisable) ProtoReq() string { return "Fetch.disable" }
// Call sends the request
func (m FetchDisable) Call(c Client) error {
return call(m.ProtoReq(), m, nil, c)
}
// FetchEnable Enables issuing of requestPaused events. A request will be paused until client
// calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.
type FetchEnable struct {
// Patterns (optional) If specified, only requests matching any of these patterns will produce
// fetchRequested event and will be paused until clients response. If not set,
// all requests will be affected.
Patterns []*FetchRequestPattern `json:"patterns,omitempty"`
// HandleAuthRequests (optional) If true, authRequired events will be issued and requests will be paused
// expecting a call to continueWithAuth.
HandleAuthRequests bool `json:"handleAuthRequests,omitempty"`
}
// ProtoReq name
func (m FetchEnable) ProtoReq() string { return "Fetch.enable" }
// Call sends the request
func (m FetchEnable) Call(c Client) error {
return call(m.ProtoReq(), m, nil, c)
}
// FetchFailRequest Causes the request to fail with specified reason.
type FetchFailRequest struct {
// RequestID An id the client received in requestPaused event.
RequestID FetchRequestID `json:"requestId"`
// ErrorReason Causes the request to fail with the given reason.
ErrorReason NetworkErrorReason `json:"errorReason"`
}
// ProtoReq name
func (m FetchFailRequest) ProtoReq() string { return "Fetch.failRequest" }
// Call sends the request
func (m FetchFailRequest) Call(c Client) error {
return call(m.ProtoReq(), m, nil, c)
}
// FetchFulfillRequest Provides response to the request.
type FetchFulfillRequest struct {
// RequestID An id the client received in requestPaused event.
RequestID FetchRequestID `json:"requestId"`
// ResponseCode An HTTP response code.
ResponseCode int `json:"responseCode"`
// ResponseHeaders (optional) Response headers.
ResponseHeaders []*FetchHeaderEntry `json:"responseHeaders,omitempty"`
// BinaryResponseHeaders (optional) Alternative way of specifying response headers as a \0-separated
// series of name: value pairs. Prefer the above method unless you
// need to represent some non-UTF8 values that can't be transmitted
// over the protocol as text.
BinaryResponseHeaders []byte `json:"binaryResponseHeaders,omitempty"`
// Body A response body. If absent, original response body will be used if
// the request is intercepted at the response stage and empty body
// will be used if the request is intercepted at the request stage.
Body []byte `json:"body"`
// ResponsePhrase (optional) A textual representation of responseCode.
// If absent, a standard phrase matching responseCode is used.
ResponsePhrase string `json:"responsePhrase,omitempty"`
}
// ProtoReq name
func (m FetchFulfillRequest) ProtoReq() string { return "Fetch.fulfillRequest" }
// Call sends the request
func (m FetchFulfillRequest) Call(c Client) error {
return call(m.ProtoReq(), m, nil, c)
}
// FetchContinueRequest Continues the request, optionally modifying some of its parameters.
type FetchContinueRequest struct {
// RequestID An id the client received in requestPaused event.
RequestID FetchRequestID `json:"requestId"`
// URL (optional) If set, the request url will be modified in a way that's not observable by page.
URL string `json:"url,omitempty"`
// Method (optional) If set, the request method is overridden.
Method string `json:"method,omitempty"`
// PostData (optional) If set, overrides the post data in the request.
PostData []byte `json:"postData,omitempty"`
// Headers (optional) If set, overrides the request headers.
Headers []*FetchHeaderEntry `json:"headers,omitempty"`
// InterceptResponse (experimental) (optional) If set, overrides response interception behavior for this request.
InterceptResponse bool `json:"interceptResponse,omitempty"`
}
// ProtoReq name
func (m FetchContinueRequest) ProtoReq() string { return "Fetch.continueRequest" }
// Call sends the request
func (m FetchContinueRequest) Call(c Client) error {
return call(m.ProtoReq(), m, nil, c)
}
// FetchContinueWithAuth Continues a request supplying authChallengeResponse following authRequired event.
type FetchContinueWithAuth struct {
// RequestID An id the client received in authRequired event.
RequestID FetchRequestID `json:"requestId"`
// AuthChallengeResponse Response to with an authChallenge.
AuthChallengeResponse *FetchAuthChallengeResponse `json:"authChallengeResponse"`
}
// ProtoReq name
func (m FetchContinueWithAuth) ProtoReq() string { return "Fetch.continueWithAuth" }
// Call sends the request
func (m FetchContinueWithAuth) Call(c Client) error {
return call(m.ProtoReq(), m, nil, c)
}
// FetchContinueResponse (experimental) Continues loading of the paused response, optionally modifying the
// response headers. If either responseCode or headers are modified, all of them
// must be present.
type FetchContinueResponse struct {
// RequestID An id the client received in requestPaused event.
RequestID FetchRequestID `json:"requestId"`
// ResponseCode (optional) An HTTP response code. If absent, original response code will be used.
ResponseCode *int `json:"responseCode,omitempty"`
// ResponsePhrase (optional) A textual representation of responseCode.
// If absent, a standard phrase matching responseCode is used.
ResponsePhrase string `json:"responsePhrase,omitempty"`
// ResponseHeaders (optional) Response headers. If absent, original response headers will be used.
ResponseHeaders []*FetchHeaderEntry `json:"responseHeaders,omitempty"`
// BinaryResponseHeaders (optional) Alternative way of specifying response headers as a \0-separated
// series of name: value pairs. Prefer the above method unless you
// need to represent some non-UTF8 values that can't be transmitted
// over the protocol as text.
BinaryResponseHeaders []byte `json:"binaryResponseHeaders,omitempty"`
}
// ProtoReq name
func (m FetchContinueResponse) ProtoReq() string { return "Fetch.continueResponse" }
// Call sends the request
func (m FetchContinueResponse) Call(c Client) error {
return call(m.ProtoReq(), m, nil, c)
}
// FetchGetResponseBody 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.
type FetchGetResponseBody struct {
// RequestID Identifier for the intercepted request to get body for.
RequestID FetchRequestID `json:"requestId"`
}
// ProtoReq name
func (m FetchGetResponseBody) ProtoReq() string { return "Fetch.getResponseBody" }
// Call the request
func (m FetchGetResponseBody) Call(c Client) (*FetchGetResponseBodyResult, error) {
var res FetchGetResponseBodyResult
return &res, call(m.ProtoReq(), m, &res, c)
}
// FetchGetResponseBodyResult ...
type FetchGetResponseBodyResult struct {
// Body Response body.
Body string `json:"body"`
// Base64Encoded True, if content was sent as base64.
Base64Encoded bool `json:"base64Encoded"`
}
// FetchTakeResponseBodyAsStream 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.
type FetchTakeResponseBodyAsStream struct {
// RequestID ...
RequestID FetchRequestID `json:"requestId"`
}
// ProtoReq name
func (m FetchTakeResponseBodyAsStream) ProtoReq() string { return "Fetch.takeResponseBodyAsStream" }
// Call the request
func (m FetchTakeResponseBodyAsStream) Call(c Client) (*FetchTakeResponseBodyAsStreamResult, error) {
var res FetchTakeResponseBodyAsStreamResult
return &res, call(m.ProtoReq(), m, &res, c)
}
// FetchTakeResponseBodyAsStreamResult ...
type FetchTakeResponseBodyAsStreamResult struct {
// Stream ...
Stream IOStreamHandle `json:"stream"`
}
// FetchRequestPaused Issued when the domain is enabled and the request URL matches the
// specified filter. The request is paused until the client responds
// with one of continueRequest, failRequest or fulfillRequest.
// The stage of the request can be determined by presence of responseErrorReason
// and responseStatusCode -- the request is at the response stage if either
// of these fields is present and in the request stage otherwise.
type FetchRequestPaused struct {
// RequestID Each request the page makes will have a unique id.
RequestID FetchRequestID `json:"requestId"`
// Request The details of the request.
Request *NetworkRequest `json:"request"`
// FrameID The id of the frame that initiated the request.
FrameID PageFrameID `json:"frameId"`
// ResourceType How the requested resource will be used.
ResourceType NetworkResourceType `json:"resourceType"`
// ResponseErrorReason (optional) Response error if intercepted at response stage.
ResponseErrorReason NetworkErrorReason `json:"responseErrorReason,omitempty"`
// ResponseStatusCode (optional) Response code if intercepted at response stage.
ResponseStatusCode *int `json:"responseStatusCode,omitempty"`
// ResponseStatusText (optional) Response status text if intercepted at response stage.
ResponseStatusText string `json:"responseStatusText,omitempty"`
// ResponseHeaders (optional) Response headers if intercepted at the response stage.
ResponseHeaders []*FetchHeaderEntry `json:"responseHeaders,omitempty"`
// NetworkID (optional) If the intercepted request had a corresponding Network.requestWillBeSent event fired for it,
// then this networkId will be the same as the requestId present in the requestWillBeSent event.
NetworkID FetchRequestID `json:"networkId,omitempty"`
}
// ProtoEvent name
func (evt FetchRequestPaused) ProtoEvent() string {
return "Fetch.requestPaused"
}
// FetchAuthRequired Issued when the domain is enabled with handleAuthRequests set to true.
// The request is paused until client responds with continueWithAuth.
type FetchAuthRequired struct {
// RequestID Each request the page makes will have a unique id.
RequestID FetchRequestID `json:"requestId"`
// Request The details of the request.
Request *NetworkRequest `json:"request"`
// FrameID The id of the frame that initiated the request.
FrameID PageFrameID `json:"frameId"`
// ResourceType How the requested resource will be used.
ResourceType NetworkResourceType `json:"resourceType"`
// AuthChallenge Details of the Authorization Challenge encountered.
// If this is set, client should respond with continueRequest that
// contains AuthChallengeResponse.
AuthChallenge *FetchAuthChallenge `json:"authChallenge"`
}
// ProtoEvent name
func (evt FetchAuthRequired) ProtoEvent() string {
return "Fetch.authRequired"
}