简体   繁体   English

如何在Google Chrome浏览器中使用javascript获取Windows用户名以获取Google Chrome扩展程序

[英]How to get the windows user name using javascript in google chrome browser for google chrome extension

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 Chrome to create a sample google chrome extension. 现在我需要在谷歌浏览器的 javascript中获取Windows用户名,以创建一个示例谷歌浏览器扩展程序。

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; 但您可以编写自己的NPAPI插件,从操作系统中获取所需的信息; and your Chrome extension can call it via JavaScript. 您的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扩展程序NSAPIMDC 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. 更新[2015年1月2日]:正如levant pied所指出的,Chrome不再支持NPAPI,但您可以使用PPAPI或NaCl模块访问系统。 More details . 更多细节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM