How to find out browser's user agent in Firefox Add On

倾然丶 夕夏残阳落幕 提交于 2019-12-10 19:54:14

问题


I'm creating (developing) a Firefox add-on and I need to find browser's user agent. The navigator.userAgent is not working. It shows that the navigator is not defined.

What Firefox Add-on module do I need to get user agent or is there another way to find it out in an add-on?


回答1:


In the SDK, first you need the chrome authority for Cc and Ci:

const {Cc, Ci} = require("chrome");

The you can use the nsIHttpProtocolHandler to get the user agent from there:

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

console.log(httpproto.userAgent);

Using the hidden window and hacks like that will work too, for now, but that's somewhat messy and might be problematic in the multi-process future.



来源:https://stackoverflow.com/questions/28715514/how-to-find-out-browsers-user-agent-in-firefox-add-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!