Skip to main content
Version: 24.38.0

HTTPRequest.redirectChain() 方法

🌐 HTTPRequest.redirectChain() method

redirectChain 是为获取资源而发起的一系列请求链。

🌐 A redirectChain is a chain of requests initiated to fetch a resource.

语法

🌐 Signature

class HTTPRequest {
abstract redirectChain(): HTTPRequest[];
}

返回:

HTTPRequest[]

请求链——如果服务器至少响应一次重定向,这个链将包含所有被重定向的请求。

🌐 the chain of requests - if a server responds with at least a single redirect, this chain will contain all requests that were redirected.

附注

🌐 Remarks

redirectChain 在同一链的所有请求之间共享。

例如,如果网站 http://example.com 有一个指向 https://example.com 的单一重定向,那么链中将包含一个请求:

🌐 For example, if the website http://example.com has a single redirect to https://example.com, then the chain will contain one request:

const response = await page.goto('http://example.com');
const chain = response.request().redirectChain();
console.log(chain.length); // 1
console.log(chain[0].url()); // 'http://example.com'

如果网站 https://google.com 没有重定向,那么链将为空:

🌐 If the website https://google.com has no redirects, then the chain will be empty:

const response = await page.goto('https://google.com');
const chain = response.request().redirectChain();
console.log(chain.length); // 0