Skip to main content
Version: 24.38.0

HTTPRequest.failure() 方法

🌐 HTTPRequest.failure() method

访问有关请求失败的信息。

🌐 Access information about the request's failure.

语法

🌐 Signature

class HTTPRequest {
abstract failure(): {
errorText: string;
} | null;
}

返回:

{ errorText: string; } | null

null,除非请求失败。如果请求失败,这可能会返回一个包含 errorText 的对象,其中包含可读的错误信息,例如 net::ERR_FAILED。请求失败时不保证一定会有失败文本。

附注

🌐 Remarks

示例

🌐 Example

记录所有失败请求的示例:

🌐 Example of logging all failed requests:

page.on('requestfailed', request => {
console.log(request.url() + ' ' + request.failure().errorText);
});