Can Node.js invoke Chrome?

后端 未结 8 1437
长发绾君心
长发绾君心 2021-02-04 09:54

Is it possible for Node.js running on a desktop to spawn a Chrome Browser window? I would like to start a Chrome Browser providing the window size and location when Node.js rece

8条回答
  •  长情又很酷
    2021-02-04 10:09

    On MacOSX

    var childProc = require('child_process');
    childProc.exec('open -a "Google Chrome" http://your_url', callback);
    //Or could be: childProc.exec('open -a firefox http://your_url', callback);
    

    A bit more:

    • Use "open -a" with the name of your app from /Applications and append your args
    • callback function is called with the output after completion
    • Link to API: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

提交回复
热议问题