开发者

How can I launch a system command via Javascript in Google Chrome?

开发者 https://www.devze.com 2022-12-25 13:07 出处:网络
I want to execute a local program on my computer via Javascript in Chrome. In Firefox, it can be done as follows (after setting \'signed.applets.codebase_principal_support\' to true in about:config):

I want to execute a local program on my computer via Javascript in Chrome. In Firefox, it can be done as follows (after setting 'signed.applets.codebase_principal_support' to true in about:config):

function run_cmd(cmd, args) {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

    var file = Compo开发者_JS百科nents.classes["@mozilla.org/file/local;1"]
        .createInstance(Components.interfaces.nsILocalFile);
    file.initWithPath(cmd);

    var process = Components.classes["@mozilla.org/process/util;1"]
        .createInstance(Components.interfaces.nsIProcess);
    process.init(file);

    process.run(false, args, args.length);
}

What's the equivalent code for Chrome?


This is not possible in Chrome without extensions. This requires a NPAPI plugin in extensions, see http://code.google.com/chrome/extensions/npapi.html ,


I don't think you can. Chrome is very particular about such things, hence their sandbox


The preferred way to do this in Chrome is to use Native Messaging along with a Chrome extension. NPAPI is being phased out.

https://developer.chrome.com/extensions/nativeMessaging


Javascript has no capabilities to communicate externally outside of the browser. For instance, no disk input/output, no communication with the host OS such as Windows/Linux. Javascript is inherently tighter as it is executed by the browser itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号