I have used the following code in javascript to get the windows user name in Firefox to create a firefox extension.
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 Chr开发者_开发技巧ome to create a sample google chrome extension.
Google Chrome
does not provide an Extension API to access the info from the Operating System, like Firefox
does.
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.
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.
Reference: Chrome Extensions NSAPI, MDC NPAPI Reference
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.
精彩评论