我如何暂时停用Google Chrome中的websocket? [英] How can i temporarily disable websocket in Google Chrome?

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

问题描述

我想暂时禁用Google Chrome中的websocket来调试javascript,以确保它适用于任何浏览器,而无需websocket支持。

解决方案

首先,我想说有更好的机制来测试您的JavaScript在一个websocketless环境。例如,你可以在IE9中运行你的JavaScript,它不会实现协议。在Firefox 4中,它们现在仍然处于禁用状态,如果这更像是您的风格。



假设您需要在无网格的Chromium中进行测试,我认为你运气不好。在Chromium中禁用WebSocket并不是一个简单的机制。它不是作为命令行开关构建的,也没有可配置的标志。由于没有任何机制可以在本地实现,所以我不会建议花时间测试场景。所有用户使用的Chromium版本(例如9+)都启用了websocket。

重新编译浏览器将会在你的测试代码中删除相关的变量:

  WebSocket = undefined; 

会比较暴躁,但应该有效。您甚至可以创建一个扩展,将JavaScript插入到您访问的每个页面中,以获得真正的无网页式体验(再次假设这对于您的用例而言具有某种价值)。

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

解决方案

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.

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.

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;

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天全站免登陆