gpt4 book ai didi

javascript - webRequest.onErrorOccurred 监听器中 error 属性的可能值是什么?

转载 作者:行者123 更新时间:2023-11-28 18:07:27 27 4
gpt4 key购买 nike

我的兴趣是仅在负载较重时处理站点,以便自动填充工作。例如,当促销事件开始并且网站挤满人时,有时会崩溃。我需要捕获站点错误,以便可以从后台脚本重新加载页面。如 Chrome Extensions: Background Script Catch Network and HTTP Errors 中所述,我们可以得到页面加载错误。

页面加载错误可能是由于网络问题、站点问题、DNS 问题以及站点过载问题造成的。

我想要的只是重新加载网页,以防由于某些错误而未加载网页。

我收集了许多 Chrome 和 Firefox 的错误代码:

  • 网络::ERR_ABORTED
  • 网络::ERR_EMPTY_RESPONSE
  • 网络::ERR_CONNECTION_TIMED_OUT
  • 网络::ERR_CONNECTION_REFUSED
  • 网络::ERR_CONNECTION_RESET
  • NS_ERROR_NET_ON_CONNECTING_TO
  • NS_ERROR_NET_ON_WAITING_FOR
  • NS_ERROR_NET_ON_CONNECTING_TO

这不是完整列表。我已经看到了这些错误,所以我将它们列出来。我不想通过反复试验来找到它们,而是想知道(HTML)页面无法加载时的所有错误代码的列表。

这是我想要使用的示例源代码:

chrome.webRequest.onErrorOccurred.addListener(function (details) 
{
if ("type" in details && ['main_frame', 'sub_frame'].indexOf(details.type) == -1)
{
if (details.url.match(/.js$/))
{
console.log("Error in download of this file:", details.url);
}
return;
}

if (details.tabId == -1)
{
return;
}

var check_all_errors = function(err)
{
var all_errors = [
"net::ERR_ABORTED",
"net::ERR_EMPTY_RESPONSE",
"net::ERR_CONNECTION_TIMED_OUT",
"net::ERR_CONNECTION_REFUSED",
"net::ERR_CONNECTION_RESET",
"NS_ERROR_NET_ON_CONNECTING_TO",
'NS_ERROR_NET_ON_WAITING_FOR',
'NS_ERROR_NET_ON_CONNECTING_TO'
];

for( var i=0;i<all_errors.length;++i)
{
if( all_errors[i] == err && !ff_validate_false())
{
return true;
}
}

console.log("786 returning false for err "+err);
return false;
}

if (details.url == HOME_URL && check_all_errors(details.error)) //if any error encountered then go to home URL
{
setTimeout(function () {
chrome.tabs.update(details.tabId, {url: HOME_URL});
}, 1000);
}
//FOLLOWING PART IS NOW SHOWN HERE

最佳答案

强烈建议您不要这样做

对于error property MDN 中提供的 ( details object ) ( MDN ) 传递给 webRequest.onErrorOccurred ( MDN ) 监听器,强烈建议您不要测试该属性的实际文本内容。

Chrome

Chrome source code说:

You must not parse and act based upon its content.

this line of code :

"error": {"type": "string", "description": "The error description. This string is <em>not</em> guaranteed to remain backwards compatible between releases. You must not parse and act based upon its content."}

documentation says :

The error description. This string is not guaranteed to remain backwards compatible between releases. You must not parse and act based upon its content.

火狐浏览器

Firefox source code状态:

You must not parse and act based upon its content.

this line of code :

"error": {"type": "string", "description": "The error description. This string is <em>not</em> guaranteed to remain backwards compatible between releases. You must not parse and act based upon its content."}

documentation says :

The error description. This string is an internal error string, may vary from one browser to another, and is not guaranteed to stay the same between releases.

当前可能的错误

Chrome

Chrome 在 this file 中列出了可能的错误值(some associated code)。该代码是:

{ net::ERR_ABORTED, "aborted" },
{ net::ERR_TIMED_OUT, "tcp.connection.timed_out" },
{ net::ERR_CONNECTION_CLOSED, "tcp.connection.closed" },
{ net::ERR_CONNECTION_RESET, "tcp.connection.reset" },
{ net::ERR_CONNECTION_REFUSED, "tcp.connection.refused" },
{ net::ERR_CONNECTION_ABORTED, "tcp.connection.aborted" },
{ net::ERR_CONNECTION_FAILED, "tcp.connection.failed" },
{ net::ERR_NAME_NOT_RESOLVED, "dns" },
{ net::ERR_SSL_PROTOCOL_ERROR, "ssl.protocol.error" },
{ net::ERR_ADDRESS_INVALID, "tcp.connection.address_invalid" },
{ net::ERR_ADDRESS_UNREACHABLE, "tcp.connection.address_unreachable" },
{ net::ERR_CONNECTION_TIMED_OUT, "tcp.connection.timed_out" },
{ net::ERR_NAME_RESOLUTION_FAILED, "dns" },
{ net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
"ssl.cert.pinned_key_not_in_cert_chain" },
{ net::ERR_CERT_COMMON_NAME_INVALID, "ssl.cert.name_invalid" },
{ net::ERR_CERT_DATE_INVALID, "ssl.cert.date_invalid" },
{ net::ERR_CERT_AUTHORITY_INVALID, "ssl.cert.authority_invalid" },
{ net::ERR_CERT_REVOKED, "ssl.cert.revoked" },
{ net::ERR_CERT_INVALID, "ssl.cert.invalid" },
{ net::ERR_EMPTY_RESPONSE, "http.response.empty" },
{ net::ERR_SPDY_PING_FAILED, "spdy.ping_failed" },
{ net::ERR_SPDY_PROTOCOL_ERROR, "spdy.protocol" },
{ net::ERR_QUIC_PROTOCOL_ERROR, "quic.protocol" },
{ net::ERR_DNS_MALFORMED_RESPONSE, "dns.protocol" },
{ net::ERR_DNS_SERVER_FAILED, "dns.server" },
{ net::ERR_DNS_TIMED_OUT, "dns.timed_out" },
{ net::ERR_INSECURE_RESPONSE, "ssl" },
{ net::ERR_CONTENT_LENGTH_MISMATCH, "http.response.content_length_mismatch" },
{ net::ERR_INCOMPLETE_CHUNKED_ENCODING,
"http.response.incomplete_chunked_encoding" },
{ net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH,
"ssl.version_or_cipher_mismatch" },
{ net::ERR_BAD_SSL_CLIENT_AUTH_CERT, "ssl.bad_client_auth_cert" },
{ net::ERR_INVALID_CHUNKED_ENCODING,
"http.response.invalid_chunked_encoding" },
{ net::ERR_RESPONSE_HEADERS_TRUNCATED, "http.response.headers.truncated" },
{ net::ERR_REQUEST_RANGE_NOT_SATISFIABLE,
"http.request.range_not_satisfiable" },
{ net::ERR_INVALID_RESPONSE, "http.response.invalid" },
{ net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
"http.response.headers.multiple_content_disposition" },
{ net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
"http.response.headers.multiple_content_length" },
{ net::ERR_SSL_UNRECOGNIZED_NAME_ALERT, "ssl.unrecognized_name_alert" }

这意味着 Chrome 的可能值为:

net::ERR_ABORTED
net::ERR_TIMED_OUT
net::ERR_CONNECTION_CLOSED
net::ERR_CONNECTION_RESET
net::ERR_CONNECTION_REFUSED
net::ERR_CONNECTION_ABORTED
net::ERR_CONNECTION_FAILED
net::ERR_NAME_NOT_RESOLVED
net::ERR_SSL_PROTOCOL_ERROR
net::ERR_ADDRESS_INVALID
net::ERR_ADDRESS_UNREACHABLE
net::ERR_CONNECTION_TIMED_OUT
net::ERR_NAME_RESOLUTION_FAILED
net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN
net::ERR_CERT_COMMON_NAME_INVALID
net::ERR_CERT_DATE_INVALID
net::ERR_CERT_AUTHORITY_INVALID
net::ERR_CERT_REVOKED
net::ERR_CERT_INVALID
net::ERR_EMPTY_RESPONSE
net::ERR_SPDY_PING_FAILED
net::ERR_SPDY_PROTOCOL_ERROR
net::ERR_QUIC_PROTOCOL_ERROR
net::ERR_DNS_MALFORMED_RESPONSE
net::ERR_DNS_SERVER_FAILED
net::ERR_DNS_TIMED_OUT
net::ERR_INSECURE_RESPONSE
net::ERR_CONTENT_LENGTH_MISMATCH
net::ERR_INCOMPLETE_CHUNKED_ENCODING
net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH
net::ERR_BAD_SSL_CLIENT_AUTH_CERT
net::ERR_INVALID_CHUNKED_ENCODING
net::ERR_RESPONSE_HEADERS_TRUNCATED
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE
net::ERR_INVALID_RESPONSE
net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH
net::ERR_SSL_UNRECOGNIZED_NAME_ALERT

火狐浏览器

Firefox 有点复杂。 WebExtensions 是一个 API,位于 Firefox 使用的 API 之上(并公开给其他类型的附加组件)。 Firefox 代码通过以下方式更改从底层 API 获取的错误文本响应:

let prefix = /^(?:ACTIVITY_SUBTYPE_|STATUS_)/;
let map = new Map();
for (let iface of [nsIHttpActivityObserver, nsISocketTransport]) {
for (let c of Object.keys(iface).filter(name => prefix.test(name))) {
map.set(iface[c], c.replace(prefix, "NS_ERROR_NET_ON_"));
}
}

可能的 ACTIVITY_SUBTYPE_ 属性的代码位于文件 nsIHttpActivityObserver.idl 中可能的 STATUS_ 属性的定义位于 nsISocketTransport.idl 。执行适当的正则表达式替换会产生以下可能的值:

NS_ERROR_NET_ON_RESOLVING
NS_ERROR_NET_ON_RESOLVED
NS_ERROR_NET_ON_CONNECTING_TO
NS_ERROR_NET_ON_CONNECTED_TO
NS_ERROR_NET_ON_SENDING_TO
NS_ERROR_NET_ON_WAITING_FOR
NS_ERROR_NET_ON_RECEIVING_FROM
NS_ERROR_NET_ON_REQUEST_HEADER
NS_ERROR_NET_ON_REQUEST_BODY_SENT
NS_ERROR_NET_ON_RESPONSE_START
NS_ERROR_NET_ON_RESPONSE_HEADER
NS_ERROR_NET_ON_RESPONSE_COMPLETE
NS_ERROR_NET_ON_TRANSACTION_CLOSE

关于javascript - webRequest.onErrorOccurred 监听器中 error 属性的可能值是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42319992/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com