从Firefox扩展中查找当前登录的用户 [英] Finding the currently logged in user from a Firefox extension
问题描述
Firefox扩展按照不同的规则,
打开您的错误控制台(在工具中)并输入:
<$ p $ Component.classes [@ mozilla.org/process/environment;1\"].getService(Components.interfaces.nsIEnvironment).get('USER')
$ c $ Firefox开始的环境变量可以通过 NsIEnvironment XPCOM组件。
您可能必须对每个平台进行自定义。如果一切都失败了,您可以在中创建一个 NsIFile 〜
然后看看它的 .path
;我不确定shell表达式是否被尊重,但是...
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 "brh", it'll return "brh". Any idea how to do that from extension JavaScript?
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...
这篇关于从Firefox扩展中查找当前登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!