如何通过 NodeJS 在 Windows 中重新启动 Chromium/Google Chrome(信息亭模式),以便它在重新启动时正常启动浏览器,就像普通人使用它一样? (当我每次重新启动 Chromium/Google chrome 时使用 NodeJS 时,都会在右上角显示丑陋/烦人/致命的弹出窗口)
NodeJS:告诉 chrome 关闭
NodeJS:告诉 chrome 现在启动:每次启动时,它都会不断打开右上角那个丑陋的弹出窗口,并且在没有人为参与的情况下无法将其删除
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
or --disable-session-crashed-bubble --disable-infobars
切换,但浏览器的行为不会完全按预期进行。
最干净的方法是改变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();
请记住调整注释中标记的应用程序和首选项文件的路径。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)