HTTPRequest.redirectChain() 方法
¥HTTPRequest.redirectChain() method
redirectChain 是为获取资源而发起的请求链。
¥A redirectChain is a chain of requests initiated to fetch a resource.
签名
¥Signature
class HTTPRequest {
abstract redirectChain(): HTTPRequest[];
}
Returns:
请求链 - 如果服务器至少响应一个重定向,则该链将包含所有重定向的请求。
¥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 在同一链的所有请求之间共享。
¥redirectChain is shared between all the requests of the same chain.
例如,如果网站 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