如何在 Google Chrome 中暂时禁用 websocket? [英] How can i temporarily disable websocket in Google Chrome?

查看:211
本文介绍了如何在 Google Chrome 中暂时禁用 websocket?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想暂时禁用 Google Chrome 中的 websocket 以调试 javascript,以确保它适用于任何没有 websocket 支持的浏览器.

I want temporarily disable websocket in Google Chrome to debug a javascript to make sure it work for any browser without websocket support.

推荐答案

首先,我想说有更好的机制可以在 websocketless 环境中测试您的 JavaScript.例如,您可以在不实现该协议的 IE9 中运行您的 JavaScript.如果这更符合您的风格,它们在 Firefox 4 中目前仍处于禁用状态.

To begin, I'd say that there are better mechanisms to test your JavaScript in a websocketless environment. You could run your JavaScript in IE9, for instance, which doesn't implement the protocol. They're still disabled for the moment in Firefox 4 as well, if that's more your style.

假设您有充分的理由需要在无 websocket 的 Chromium 中进行测试,我认为您不走运.在 Chromium 中没有禁用 WebSockets 的简单机制.它不是作为命令行开关内置的,也没有可配置的标志.由于没有机制可以在本地实现这一点,因此我不建议花时间测试场景.您的用户使用的每个 Chromium 版本(例如 9+)都启用了 websocket.

Assuming that there's some good reason that you need to test in a websocketless Chromium, I think you're out of luck. There's not a trivial mechanism to disable WebSockets in Chromium. It's not built in as a command-line switch, nor is there a configurable flag. Since there's no mechanism to make this happen natively, I wouldn't suggest spending time testing the scenario. Every version of Chromium that your users use (e.g. 9+) has websockets enabled.

综上所述,如果您确实需要禁用 websockets,那么在不重新编译浏览器的情况下最接近的方法就是在测试代码中删除相关变量:

All that said, if you really need to disable websockets, the closest you can get without recompiling the browser would be to drop the relevant variables in your test code:

WebSocket = undefined;

将是相对蛮力,但应该工作.您甚至可以创建一个扩展程序,将 JavaScript 注入您访问的每个页面,以获得真正的无网络套接字体验(再次假设,这对您的用例而言具有某种价值).

would be relatively brute force, but should work. You could even create an extension to inject that JavaScript into every page you visit, for a truly websocketless experience (assuming, again, that that's somehow valuable for your use case).

这篇关于如何在 Google Chrome 中暂时禁用 websocket?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆