Fetch
一个允许客户端用客户端代码替代浏览器网络层的域。
EN
✅️️ Methods
🔨Fetch.continueRequest
继续该请求,可选地修改其部分参数。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 客户端在requestPaused事件中接收到的ID。 | ENAn id the client received in requestPaused event. | |
| url | string | 如果设置了,请求的URL将以页面无法察觉的方式被修改。 | ENIf set, the request url will be modified in a way that's not observable by page. | ||
| method | string | 如果设置了,请求方法将被覆盖。 | ENIf set, the request method is overridden. | ||
| postData | string | 如果设置,将覆盖请求中的post数据。(通过JSON传递时编码为base64字符串) | ENIf set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON) | ||
| headers | array[HeaderEntry] | 如果设置,将覆盖请求头。请注意,覆盖不会延伸到后续的重定向 跳转,如果发生重定向。另一个覆盖可能应用于由重定向产生的不同请求。 | ENIf 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 | 🧪 | boolean | 如果设置,将覆盖此请求的响应拦截行为。 | ENIf set, overrides response interception behavior for this request. |
🔨Fetch.continueWithAuth
在authRequired事件之后,通过提供authChallengeResponse来继续请求。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 客户端在authRequired事件中接收到的ID。 | ENAn id the client received in authRequired event. | |
| authChallengeResponse | ✔️ | AuthChallengeResponse | 响应 并附带一个身份验证挑战。 | ENResponse to with an authChallenge. |
🔨Fetch.disable
禁用 fetch 域。
EN
🔨Fetch.enable
启用请求暂停事件的发布。一个请求将被暂停,直到客户端调用 failRequest、fulfillRequest 或 continueRequest/continueWithAuth 其中之一。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| patterns | array[RequestPattern] | 如果指定,仅匹配这些模式中任意一个的请求会产生 fetchRequested 事件,并将暂停直到客户端响应。如果未设置,所有请求都将受到影响。 | ENIf 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 | boolean | 如果为真,将触发 authRequired 事件,并且请求将被暂停,等待调用 continueWithAuth。 | ENIf true, authRequired events will be issued and requests will be paused expecting a call to continueWithAuth. |
🔨Fetch.failRequest
导致请求以指定原因失败。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 一个客户端在requestPaused事件中收到的id。 | ENAn id the client received in requestPaused event. | |
| errorReason | ✔️ | Network.ErrorReason | 导致请求以给定原因失败。 | ENCauses the request to fail with the given reason. |
🔨Fetch.fulfillRequest
提供对请求的响应。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 一个客户端在requestPaused事件中接收到的id。 | ENAn id the client received in requestPaused event. | |
| responseCode | ✔️ | integer | HTTP响应代码。 | ENAn HTTP response code. | |
| responseHeaders | array[HeaderEntry] | 响应头。 | ENResponse headers. | ||
| binaryResponseHeaders | string | 指定响应头的另一种方式是以 \0 分隔的一系列名称:值对。除非需要表示某些无法通过协议以文本形式传输的非UTF8值,否则建议使用上述方法。(通过JSON传递时编码为base64字符串) | ENAlternative 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. (Encoded as a base64 string when passed over JSON) | ||
| body | string | 响应正文。如果缺失,在响应阶段被拦截的请求将使用原始响应正文,而在请求阶段被拦截的请求将使用空正文。(通过 JSON 传递时以 base64 字符串编码) | ENA 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. (Encoded as a base64 string when passed over JSON) | ||
| responsePhrase | string | responseCode的文本表示。如果不存在,则使用与responseCode匹配的标准短语。 | ENA textual representation of responseCode. If absent, a standard phrase matching responseCode is used. |
🔨Fetch.getResponseBody
导致响应体从服务器接收并作为单个字符串返回。仅适用于在响应阶段暂停的请求,并且与 takeResponseBodyForInterceptionAsStream 互斥。在接收响应体之前调用其他影响请求的方法或禁用 fetch 域会导致未定义的行为。请注意,响应体不适用于重定向。在重定向接收状态暂停的请求可以通过 responseCode 和是否存在 location 响应头来区分,详情请参阅 requestPaused 的注释。
EN
responseCode and presence of location response header, see comments to requestPaused for details.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 获取请求正文的拦截请求标识符。 | ENIdentifier for the intercepted request to get body for. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| body | string | 响应正文。 | ENResponse body. |
| base64Encoded | boolean | 是的,如果内容是以 base64 格式发送的。 | ENTrue, if content was sent as base64. |
🔨Fetch.takeResponseBodyAsStream
返回一个指向表示响应主体的流的句柄。请求必须在HeadersReceived阶段暂停。请注意,在此命令之后,请求不能按原样继续——客户端需要取消它或提供响应主体。该流仅支持顺序读取,如果指定了位置,IO.read将失败。此方法与getResponseBody互斥。在接收到主体之前,调用其他影响请求的方法或禁用fetch域将导致未定义的行为。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| stream | IO.StreamHandle |
🔨Fetch.continueResponse🧪
继续加载已暂停的响应,可选择修改响应头。如果修改了响应码或响应头,则必须同时提供所有修改项。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 一个客户端在requestPaused事件中接收到的id。 | ENAn id the client received in requestPaused event. | |
| responseCode | integer | HTTP响应代码。如果未提供,将使用原始响应代码。 | ENAn HTTP response code. If absent, original response code will be used. | ||
| responsePhrase | string | responseCode的文本表示。如果不存在,则使用与responseCode匹配的标准短语。 | ENA textual representation of responseCode. If absent, a standard phrase matching responseCode is used. | ||
| responseHeaders | array[HeaderEntry] | 响应头。如果不存在,将使用原始响应头。 | ENResponse headers. If absent, original response headers will be used. | ||
| binaryResponseHeaders | string | 指定响应头的另一种方法,是使用以\0分隔的一系列名称:值对。除非你需要表示某些无法通过协议以文本形式传输的非UTF8值,否则建议使用上述方法。(在通过JSON传递时,会编码为base64字符串) | ENAlternative 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. (Encoded as a base64 string when passed over JSON) |
✅ ️️ Events
👋Fetch.authRequired
当启用该域且handleAuthRequests设置为true时触发。请求将暂停,直到客户端通过continueWithAuth响应。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 页面发出的每个请求都将拥有一个唯一的ID。 | ENEach request the page makes will have a unique id. | |
| request | ✔️ | Network.Request | 请求的详细信息。 | ENThe details of the request. | |
| frameId | ✔️ | Page.FrameId | 发起请求的框架的id。 | ENThe id of the frame that initiated the request. | |
| resourceType | ✔️ | Network.ResourceType | 请求的资源将如何被使用。 | ENHow the requested resource will be used. | |
| authChallenge | ✔️ | AuthChallenge | 授权挑战的详细信息。如果设置了此项,客户端应使用包含AuthChallengeResponse的continueRequest进行响应。 | ENDetails of the Authorization Challenge encountered. If this is set, client should respond with continueRequest that contains AuthChallengeResponse. |
👋Fetch.requestPaused
当启用该域且请求URL匹配指定过滤器时触发。请求将被暂停,直到客户端通过continueRequest、failRequest或fulfillRequest之一进行响应。请求的阶段可通过是否存在responseErrorReason和responseStatusCode字段来判断——若存在任一字段则请求处于响应阶段,否则处于请求阶段。重定向响应及后续请求的汇报方式与常规响应和请求相同。重定向响应可通过responseStatusCode值(为301、302、303、307、308之一)及是否存在location标头来识别。由重定向产生的请求将设置redirectedRequestId字段。
EN
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.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| requestId | ✔️ | RequestId | 页面发出的每个请求都将拥有唯一的标识符。 | ENEach request the page makes will have a unique id. | |
| request | ✔️ | Network.Request | 请求的详细信息。 | ENThe details of the request. | |
| frameId | ✔️ | Page.FrameId | 发起请求的框架的id。 | ENThe id of the frame that initiated the request. | |
| resourceType | ✔️ | Network.ResourceType | 请求的资源将如何使用。 | ENHow the requested resource will be used. | |
| responseErrorReason | Network.ErrorReason | 如果在响应阶段被拦截,则响应错误。 | ENResponse error if intercepted at response stage. | ||
| responseStatusCode | integer | 如果在响应阶段被拦截,响应代码。 | ENResponse code if intercepted at response stage. | ||
| responseStatusText | string | 如果响应阶段被拦截,则显示响应状态文本。 | ENResponse status text if intercepted at response stage. | ||
| responseHeaders | array[HeaderEntry] | 如果在响应阶段被拦截,响应头。 | ENResponse headers if intercepted at the response stage. | ||
| networkId | Network.RequestId | 如果被拦截的请求触发了相应的Network.requestWillBeSent事件,那么此networkId将与requestWillBeSent事件中的requestId相同。 | ENIf 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 | 如果请求是由于服务器的重定向响应,则这是导致重定向的请求的ID。 | ENIf the request is due to a redirect response from the server, the id of the request that has caused the redirect. |
✅️️ Types
📌Fetch.AuthChallenge
HTTP状态码401或407的授权质询。
EN
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| source | string | 认证挑战的来源。 允许的值: Server、Proxy | ENSource of the authentication challenge.Allowed Values: Server, Proxy | ||
| origin | ✔️ | string | 挑战者的来源。 | ENOrigin of the challenger. | |
| scheme | ✔️ | string | 所使用的身份验证方案,例如basic或digest | ENThe authentication scheme used, such as basic or digest | |
| realm | ✔️ | string | 挑战的领域。可能为空。 | ENThe realm of the challenge. May be empty. |
📌Fetch.AuthChallengeResponse
对认证挑战的响应。
EN
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| response | ✔️ | string | 对于授权质询的响应决策。默认值意味着遵循网络栈的默认行为,这很可能是取消认证或显示弹出对话框。 允许值: Default、CancelAuth、ProvideCredentials | ENThe 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.Allowed Values: Default, CancelAuth, ProvideCredentials | |
| username | string | 用户名,可能为空。仅当响应为''ProvideCredentials''时应设置。 | ENThe username to provide, possibly empty. Should only be set if response is ProvideCredentials. | ||
| password | string | 提供的密码,可能为空。仅当响应为ProvideCredentials时才应设置。 | ENThe password to provide, possibly empty. Should only be set if response is ProvideCredentials. |
📌Fetch.HeaderEntry
响应HTTP标头条目
EN
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| name | ✔️ | string | |||
| value | ✔️ | string |
📌Fetch.RequestId
唯一的请求标识符。请注意,这并不标识作为网络请求一部分的单个HTTP请求。
EN
返回类型:string
📌Fetch.RequestPattern
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| urlPattern | string | 允许使用通配符('*' 表示零个或多个,'?' 表示恰好一个)。转义字符为反斜杠。省略时等同于 "*"。 | ENWildcards ('*' -> zero or more, '?' -> exactly one) are allowed. Escape character is backslash. Omitting is equivalent to "*". | ||
| resourceType | Network.ResourceType | 如果设置,仅会拦截匹配资源类型的请求。 | ENIf set, only requests for matching resource types will be intercepted. | ||
| requestStage | RequestStage | 开始拦截请求的阶段。默认为Request。 | ENStage at which to begin intercepting requests. Default is Request. |
📌Fetch.RequestStage
请求处理的阶段。请求将在发送前被拦截。响应将在接收到响应后(但在接收响应主体之前)被拦截。
允许的值:Request、Response
EN
Allowed Values:
Request, Response返回类型:string