如何获取firefox用户代理字符串?
我正在为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,Firefox 改变了版本 4 中的实现方式。您尝试过吗:
Apparently Firefox changed how this was done in version 4. Have you tried:
您可以通过 XPCOM 获取它,如下所示:
You can get it via XPCOM like this:
如果由于某种原因您确实需要像您在标签中建议的那样使用 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.