如何在 google chrome 浏览器中使用 javascript 获取 windows 用户名以获取 google chrome 扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5335342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the windows user name using javascript in google chrome browser for google chrome extension
提问by AMARESHWARAN
I have used the following code in javascript to get the windows user name in Firefox to create a firefox extension.
我在 javascript 中使用了以下代码来获取 Firefox 中的 Windows 用户名以创建 firefox 扩展。
Components.classes["@mozilla.org/process/environment;1"].getservice(components.interfaces.nsienvironment).get('username');
Now I need to get the windows user name in javascript for Google Chrometo create a sample google chrome extension.
现在我需要在 javascript 中为Google Chrome获取 Windows 用户名来创建一个示例 google chrome 扩展。
回答by Livingston Samuel
Google Chrome
does not provide an Extension API to access the info from the Operating System, like Firefox
does.
Google Chrome
不提供扩展 API 来访问来自操作系统的信息,就像Firefox
那样。
But you can write your own NPAPI Plugin, which fetches the required info from the OS; and your Chrome extension can call it via JavaScript.
但是您可以编写自己的 NPAPI 插件,它从操作系统获取所需的信息;并且您的 Chrome 扩展程序可以通过 JavaScript 调用它。
Please note that NPAPI plugin has full unrestricted access to the system, so any vulnerabilities can be used by an attacker to compromise the users system.
请注意,NPAPI 插件可以完全不受限制地访问系统,因此攻击者可以利用任何漏洞来破坏用户系统。
Reference: Chrome Extensions NSAPI, MDC NPAPI Reference
参考:Chrome 扩展 NSAPI、MDC NPAPI 参考
Update [02-Jan-2015]: As pointed out by levant pied, Chrome no longer supports NPAPI, but you can use PPAPI or NaCl modules to access the system. More details.
更新 [02-Jan-2015]:正如Levant pied所指出的,Chrome 不再支持 NPAPI,但您可以使用 PPAPI 或 NaCl 模块来访问系统。更多详情。