Finding the currently logged in user from a Firefox extension

后端 未结 4 572
面向向阳花
面向向阳花 2020-12-16 05:55

I\'m writing a Firefox extension that needs to know what the username of the currently logged in user is in Windows, Mac, or Linux. So if I\'m logged into my machine as \"br

4条回答
  •  忘掉有多难
    2020-12-16 06:24

    Firefox extensions play by different rules to normal JavaScript running in the page: finding the current user is absolutely possible.

    Open your Error Console (in Tools) and enter this:

    Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('USER')
    

    The environment variables Firefox was started with are available through that NsIEnvironment XPCOM component.

    You may have to customise this per platform. If all else fails, you might be able to create an NsIFile in ~ then look at its .path; I'm not sure if shell expressions are honoured there, though...

提交回复
热议问题