如何使用nodejs禁用Chrome的会话恢复警告?

如何通过NodeJS在Windows中重新启动Chromium / Google Chrome(kiosk模式),以便在正常启动的情况下正常启动浏览器。 (当我重新启动Chromium / Google chrome时,每次使用nodeJS时都会在右上angular显示出丑陋/烦人/致命的popup窗口

NodeJS:告诉chromeclosures

在这里输入图像说明

NodeJS:告诉chrome现在就开始:在每一次启动的时候,它都会在右上angular打开那个丑陋的popup窗口,没有人参与就无法删除

在这里输入图像说明

var wait_seconds = null; function reboot_chrome() { // taskkill /f /im chrome.exe run_cmd( "taskkill", ["/f", "/im", "chrome.exe"], function(text) { console.log (text); }); //$ cat C:/Python27/run.bat: //@echo off //@start /b cmd /c "C:\Users\tpt\AppData\Local\Chromium\Application\chrome.exe" --kiosk wait_seconds = setTimeout(function() { run_cmd("C:\\Python27\\run.bat", [], function(text){ console.log(text); }); }, 20000); } 

您可以使用--incognito--disable-session-crashed-bubble --disable-infobars交换机,但浏览器不会像预期的那样运行。

exit_type的方法是在用户配置文件的首选项中更改exit_type 。 下面是一个小例子:

 var fs = require("fs"); var path = require("path"); var exec = require("child_process").exec; //---------------------------------------------------- function restartChrome(){ stopChrome(); setTimeout(startChrome, 20000); } //---------------------------------------------------- function startChrome(){ // change this path to your application path exec('"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome" --kiosk') } //---------------------------------------------------- function stopChrome(){ exec("taskkill /IM chrome.exe /f"); setExitType(); } //---------------------------------------------------- function setExitType(callback){ // change this path to your session preferences path var preferencesPath = path.join(process.env["USERPROFILE"], "AppData/Local/Google/Chrome/User Data/Default/Preferences"); fs.readFile(preferencesPath, "utf8", function(err, data){ if (err) { return callback && callback(err); } var txt = data.replace(/exit_type":"Crashed/g, 'exit_type":"None') .replace(/exited_cleanly":false/g, 'exited_cleanly":true'); fs.writeFile(preferencesPath, txt, "utf8", callback); }); } restartChrome(); 

请记住调整注释中标记的应用程序和首选项文件的路径。