Skip to content Skip to sidebar Skip to footer

How To Find Out Browser's User Agent In Firefox Add On

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

Solution 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.


Post a Comment for "How To Find Out Browser's User Agent In Firefox Add On"