如何获取firefox用户代理字符串?

发布于 2024-11-24 19:37:37 字数 754 浏览 3 评论 0原文

我正在为 FireFox 构建一个模拟网站的附加组件,但从本地库运行。 (如果您想了解更多信息,看这里

我正在寻找一种方法来掌握如果 FireFox 执行纯 http,则它发送用户代理字符串。我自己做 nsIProtocolHandler 并提供我自己的 nsIHttpChannel 实现,所以如果我有 查看源码,看来我得自己做所有的工作了。

除非 nsHttpHandler 上有合同/对象 ID,否则我可以用来创建一个实例来短暂获取 UserAgent? (虽然我注意到我需要调用 Init() 因为它确实 InitUserAgentComponents() 并希望它能到达那里......我猜http协议handler 处理通道和处理程序,因此不会直接与 nsHttpHandler 签订合同。)

如果我稍微越过墙看看,我会注意到这个全局可用的调用 ObtainUserAgentString ,它在并行维度中执行此操作...

I'm building an add-on for FireFox that simulates a website, but running from a local library. (If you want to know more, look here)

I'm looking for a way to get a hold of the user-agent string that FireFox would send if it were doing plain http. I'm doing the nsIProtocolHandler myself and serve my own implementation of nsIHttpChannel, so if I have a peek at the source, it looks like I'll have to do all the work myself.

Unless there's a contract/object-id on nsHttpHandler I could use to create an instance just for a brief moment to get the UserAgent? (Though I notice I'll need to call Init() because it does InitUserAgentComponents() and hope it'll get to there... And I guess the http protocol handler does the channels and handlers so there won't be a contract to nsHttpHandler directly.)

If I have a little peek over the wall I notice this globally available call ObtainUserAgentString which does just this in that parallel dimension...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤檠 2024-12-01 19:37:37

显然,Firefox 改变了版本 4 中的实现方式。您尝试过吗:

alert(window.navigator.userAgent);

Apparently Firefox changed how this was done in version 4. Have you tried:

alert(window.navigator.userAgent);
合约呢 2024-12-01 19:37:37

您可以通过 XPCOM 获取它,如下所示:

var httpHandler = Cc["@mozilla.org/network/protocol;1?name=http"].
  getService(Ci.nsIHttpProtocolHandler);
var userAgent = httpHandler.userAgent;

You can get it via XPCOM like this:

var httpHandler = Cc["@mozilla.org/network/protocol;1?name=http"].
  getService(Ci.nsIHttpProtocolHandler);
var userAgent = httpHandler.userAgent;
金橙橙 2024-12-01 19:37:37

如果由于某种原因您确实需要像您在标签中建议的那样使用 NPAPI,则可以使用 NPN_UserAgent 得到它;然而,如果您真的需要这样做只是为了延期,我会感到震惊。安东尼的答案很可能更符合您的要求。

If for some reason you actaully do need to use NPAPI like you suggest in your tags, you can use NPN_UserAgent to get it; however, I would be shocked if you actually needed to do that just for an extension. Most likely Anthony's answer is more what you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文