fetch

package
v0.158.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 6 Imported by: 96

Documentation

Overview

Package fetch provides the Chrome DevTools Protocol commands, types, and events for the Fetch domain.

A domain for letting clients substitute browser's network layer with client code.

Generated by the pdlgen command.

Index

Constants

View Source
const (
	CommandDisable                  = "Fetch.disable"
	CommandEnable                   = "Fetch.enable"
	CommandFailRequest              = "Fetch.failRequest"
	CommandFulfillRequest           = "Fetch.fulfillRequest"
	CommandContinueRequest          = "Fetch.continueRequest"
	CommandContinueWithAuth         = "Fetch.continueWithAuth"
	CommandContinueResponse         = "Fetch.continueResponse"
	CommandGetResponseBody          = "Fetch.getResponseBody"
	CommandTakeResponseBodyAsStream = "Fetch.takeResponseBodyAsStream"
)

Command names.

Variables

View Source
var AuthRequired = cdp.Event[EventAuthRequired]{Method: "Fetch.authRequired"}

AuthRequired issued when the domain is enabled with handleAuthRequests set to true. The request is paused until client responds with continueWithAuth.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#event-authRequired

ContinueRequest continues the request, optionally modifying some of its parameters.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueRequest

ContinueResponse continues loading of the paused response, optionally modifying the response headers. If either responseCode or headers are modified, all of them must be present.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueResponse

ContinueWithAuth continues a request supplying authChallengeResponse following authRequired event.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueWithAuth

View Source
var Disable = cdp.Command[cdp.Empty, cdp.Empty]{Method: CommandDisable}

Disable disables the fetch domain.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-disable

Enable enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-enable

FailRequest causes the request to fail with specified reason.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-failRequest

FulfillRequest provides response to the request.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-fulfillRequest

GetResponseBody 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. Note that the response body is not available for redirects. Requests paused in the _redirect received_ state may be differentiated by responseCode and presence of location response header, see comments to requestPaused for details.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-getResponseBody

View Source
var RequestPaused = cdp.Event[EventRequestPaused]{Method: "Fetch.requestPaused"}

RequestPaused 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. Redirect responses and subsequent requests are reported similarly to regular responses and requests. Redirect responses may be distinguished by the value of responseStatusCode (which is one of 301, 302, 303, 307, 308) along with presence of the location header. Requests resulting from a redirect will have redirectedRequestId field set.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#event-requestPaused

TakeResponseBodyAsStream 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.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-takeResponseBodyAsStream

Functions

This section is empty.

Types

type AuthChallenge

type AuthChallenge struct {
	Source AuthChallengeSource `json:"source,omitempty,omitzero"` // Source of the authentication challenge.
	Origin string              `json:"origin"`                    // Origin of the challenger.
	Scheme string              `json:"scheme"`                    // The authentication scheme used, such as basic or digest
	Realm  string              `json:"realm"`                     // The realm of the challenge. May be empty.
}

AuthChallenge authorization challenge for HTTP status code 401 or 407.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-AuthChallenge

type AuthChallengeResponse

type AuthChallengeResponse struct {
	Response AuthChallengeResponseResponse `json:"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.
	Username string                        `json:"username,omitempty,omitzero"` // The username to provide, possibly empty. Should only be set if response is ProvideCredentials.
	Password string                        `json:"password,omitempty,omitzero"` // The password to provide, possibly empty. Should only be set if response is ProvideCredentials.
}

AuthChallengeResponse response to an AuthChallenge.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-AuthChallengeResponse

type AuthChallengeResponseResponse added in v0.157.1

type AuthChallengeResponseResponse string

AuthChallengeResponseResponse 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.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-AuthChallengeResponse

const (
	AuthChallengeResponseResponseDefault            AuthChallengeResponseResponse = "Default"
	AuthChallengeResponseResponseCancelAuth         AuthChallengeResponseResponse = "CancelAuth"
	AuthChallengeResponseResponseProvideCredentials AuthChallengeResponseResponse = "ProvideCredentials"
)

AuthChallengeResponseResponse values.

func (AuthChallengeResponseResponse) String added in v0.157.1

String returns the AuthChallengeResponseResponse as string value.

type AuthChallengeSource added in v0.157.1

type AuthChallengeSource string

AuthChallengeSource source of the authentication challenge.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-AuthChallenge

const (
	AuthChallengeSourceServer AuthChallengeSource = "Server"
	AuthChallengeSourceProxy  AuthChallengeSource = "Proxy"
)

AuthChallengeSource values.

func (AuthChallengeSource) String added in v0.157.1

func (t AuthChallengeSource) String() string

String returns the AuthChallengeSource as string value.

type ContinueRequestParams

type ContinueRequestParams struct {
	RequestID         RequestID      `json:"requestId"`                            // An id the client received in requestPaused event.
	URL               string         `json:"url,omitempty,omitzero"`               // If set, the request url will be modified in a way that's not observable by page.
	Method            string         `json:"method,omitempty,omitzero"`            // If set, the request method is overridden.
	PostData          []byte         `json:"postData,omitempty,omitzero"`          // If set, overrides the post data in the request.
	Headers           []*HeaderEntry `json:"headers,omitempty,omitzero"`           // If set, overrides the request headers. Note that the overrides do not extend to subsequent redirect hops, if a redirect happens. Another override may be applied to a different request produced by a redirect.
	InterceptResponse *bool          `json:"interceptResponse,omitempty,omitzero"` // If set, overrides response interception behavior for this request.
}

ContinueRequestParams are the parameters of the command Fetch.continueRequest.

type ContinueResponseParams

type ContinueResponseParams struct {
	RequestID             RequestID      `json:"requestId"`                                // An id the client received in requestPaused event.
	ResponseCode          int64          `json:"responseCode,omitempty,omitzero"`          // An HTTP response code. If absent, original response code will be used.
	ResponsePhrase        string         `json:"responsePhrase,omitempty,omitzero"`        // A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.
	ResponseHeaders       []*HeaderEntry `json:"responseHeaders,omitempty,omitzero"`       // Response headers. If absent, original response headers will be used.
	BinaryResponseHeaders []byte         `json:"binaryResponseHeaders,omitempty,omitzero"` // 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.
}

ContinueResponseParams are the parameters of the command Fetch.continueResponse.

type ContinueWithAuthParams

type ContinueWithAuthParams struct {
	RequestID             RequestID              `json:"requestId"`             // An id the client received in authRequired event.
	AuthChallengeResponse *AuthChallengeResponse `json:"authChallengeResponse"` // Response to  with an authChallenge.
}

ContinueWithAuthParams are the parameters of the command Fetch.continueWithAuth.

type EnableParams

type EnableParams struct {
	Patterns           []*RequestPattern `json:"patterns,omitempty,omitzero"`           // 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.
	HandleAuthRequests *bool             `json:"handleAuthRequests,omitempty,omitzero"` // If true, authRequired events will be issued and requests will be paused expecting a call to continueWithAuth.
}

EnableParams are the parameters of the command Fetch.enable.

type EventAuthRequired

type EventAuthRequired struct {
	RequestID     RequestID            `json:"requestId"`     // Each request the page makes will have a unique id.
	Request       *network.Request     `json:"request"`       // The details of the request.
	FrameID       cdp.FrameID          `json:"frameId"`       // The id of the frame that initiated the request.
	ResourceType  network.ResourceType `json:"resourceType"`  // How the requested resource will be used.
	AuthChallenge *AuthChallenge       `json:"authChallenge"` // Details of the Authorization Challenge encountered. If this is set, client should respond with continueRequest that contains AuthChallengeResponse.
}

EventAuthRequired issued when the domain is enabled with handleAuthRequests set to true. The request is paused until client responds with continueWithAuth.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#event-authRequired

type EventRequestPaused

type EventRequestPaused struct {
	RequestID           RequestID            `json:"requestId"`                              // Each request the page makes will have a unique id.
	Request             *network.Request     `json:"request"`                                // The details of the request.
	FrameID             cdp.FrameID          `json:"frameId"`                                // The id of the frame that initiated the request.
	ResourceType        network.ResourceType `json:"resourceType"`                           // How the requested resource will be used.
	ResponseErrorReason network.ErrorReason  `json:"responseErrorReason,omitempty,omitzero"` // Response error if intercepted at response stage.
	ResponseStatusCode  int64                `json:"responseStatusCode,omitempty,omitzero"`  // Response code if intercepted at response stage.
	ResponseStatusText  string               `json:"responseStatusText,omitempty,omitzero"`  // Response status text if intercepted at response stage.
	ResponseHeaders     []*HeaderEntry       `json:"responseHeaders,omitempty,omitzero"`     // Response headers if intercepted at the response stage.
	NetworkID           network.RequestID    `json:"networkId,omitempty,omitzero"`           // 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.
	RedirectedRequestID RequestID            `json:"redirectedRequestId,omitempty,omitzero"` // If the request is due to a redirect response from the server, the id of the request that has caused the redirect.
}

EventRequestPaused 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. Redirect responses and subsequent requests are reported similarly to regular responses and requests. Redirect responses may be distinguished by the value of responseStatusCode (which is one of 301, 302, 303, 307, 308) along with presence of the location header. Requests resulting from a redirect will have redirectedRequestId field set.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#event-requestPaused

type FailRequestParams

type FailRequestParams struct {
	RequestID   RequestID           `json:"requestId"`   // An id the client received in requestPaused event.
	ErrorReason network.ErrorReason `json:"errorReason"` // Causes the request to fail with the given reason.
}

FailRequestParams are the parameters of the command Fetch.failRequest.

type FulfillRequestParams

type FulfillRequestParams struct {
	RequestID             RequestID      `json:"requestId"`                                // An id the client received in requestPaused event.
	ResponseCode          int64          `json:"responseCode"`                             // An HTTP response code.
	ResponseHeaders       []*HeaderEntry `json:"responseHeaders,omitempty,omitzero"`       // Response headers.
	BinaryResponseHeaders []byte         `json:"binaryResponseHeaders,omitempty,omitzero"` // 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.
	Body                  []byte         `json:"body,omitempty,omitzero"`                  // 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.
	ResponsePhrase        string         `json:"responsePhrase,omitempty,omitzero"`        // A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.
}

FulfillRequestParams are the parameters of the command Fetch.fulfillRequest.

type GetResponseBodyParams

type GetResponseBodyParams struct {
	RequestID RequestID `json:"requestId"` // Identifier for the intercepted request to get body for.
}

GetResponseBodyParams are the parameters of the command Fetch.getResponseBody.

type GetResponseBodyResult added in v0.157.3

type GetResponseBodyResult struct {
	Body          []byte `json:"body,omitempty,omitzero"` // Response body.
	Base64encoded bool   `json:"base64Encoded"`           // True, if content was sent as base64.
}

GetResponseBodyResult is the result of the command Fetch.getResponseBody.

func (*GetResponseBodyResult) UnmarshalJSON added in v0.157.3

func (r *GetResponseBodyResult) UnmarshalJSON(buf []byte) error

UnmarshalJSON decodes the value. The browser sends body as text, or as base64 when r.Base64encoded, and Body holds the decoded bytes.

type HeaderEntry

type HeaderEntry struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

HeaderEntry response HTTP header entry.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-HeaderEntry

type RequestID

type RequestID string

RequestID unique request identifier. Note that this does not identify individual HTTP requests that are part of a network request.

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestId

func (RequestID) String

func (t RequestID) String() string

String returns the RequestID as string value.

type RequestPattern

type RequestPattern struct {
	URLPattern   string               `json:"urlPattern,omitempty,omitzero"`   // Wildcards ('*' -> zero or more, '?' -> exactly one) are allowed. Escape character is backslash. Omitting is equivalent to "*".
	ResourceType network.ResourceType `json:"resourceType,omitempty,omitzero"` // If set, only requests for matching resource types will be intercepted.
	RequestStage RequestStage         `json:"requestStage,omitempty,omitzero"` // Stage at which to begin intercepting requests. Default is Request.
}

RequestPattern [no description].

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern

type RequestStage

type RequestStage string

RequestStage 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).

See: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestStage

const (
	RequestStageRequest  RequestStage = "Request"
	RequestStageResponse RequestStage = "Response"
)

RequestStage values.

func (RequestStage) String

func (t RequestStage) String() string

String returns the RequestStage as string value.

type TakeResponseBodyAsStreamParams

type TakeResponseBodyAsStreamParams struct {
	RequestID RequestID `json:"requestId"`
}

TakeResponseBodyAsStreamParams are the parameters of the command Fetch.takeResponseBodyAsStream.

type TakeResponseBodyAsStreamResult added in v0.157.3

type TakeResponseBodyAsStreamResult struct {
	Stream io.StreamHandle `json:"stream,omitempty,omitzero"`
}

TakeResponseBodyAsStreamResult is the result of the command Fetch.takeResponseBodyAsStream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL