静音网::ERR_CONNECTION_REFUSED [英] Silence net::ERR_CONNECTION_REFUSED
问题描述
连接到一个不存在的网络套接字服务器会导致大量错误被记录到控制台,通常是... net::ERR_CONNECTION_REFUSED
.
Connecting to a non-existent web socket server results in loud errors being logged to the console, usually to the tune of ... net::ERR_CONNECTION_REFUSED
.
有没有人有一个想法可以让这个输出静音?XMLHttpRequest
将不起作用,因为如果服务器无法访问,它会产生相同的详细错误输出.
Anyone have an idea for a hackaround to silence this output? XMLHttpRequest
won't work since it yields the same verbose error output if the server is not reachable.
这里的目标是测试服务器是否可用,如果它连接到它,否则使用回退,并在不向控制台发送错误输出的情况下执行此操作.
The goal here is to test if the server is available, if it is then connect to it, otherwise use a fallback, and to do this without spamming the console with error output.
推荐答案
Chrome 本身会发出这些消息,并且无法阻止它们.这是 chrome 构建方式的函数;每当 ResourceFetcher 对象尝试获取资源时,它的响应都会传递回其上下文,如果出现错误,浏览器会将其打印到控制台 - 见这里.
Chrome itself is emitting these messages, and there is no way to block them. This is a function of how chrome was built; whenever a ResourceFetcher object attempts to fetch a resource, its response is passed back to its context, and if there's an error, the browser prints it to the console - see here.
可以在此处找到类似问题.
如果您愿意,可以使用 chrome 控制台过滤器 作为 这个问题讨论在您的控制台中阻止这些错误,但没有办法以编程方式阻止这些消息.
If you'd like, you can use a chrome console filter as this question discusses to block these errors in your console, but there is no way to programmatically block the messages.
这篇关于静音网::ERR_CONNECTION_REFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!