问题
How to reboot the Chromium/Google Chrome (kiosk mode) in Windows via NodeJS so that it normally on restart starts the browser as it was used by a normal human? (when i use nodeJS every single time on restart of Chromium/Google chrome keep showing me that ugly/annoying/deadly popup on right top corner)
NodeJS: tell chrome to switch off
NodeJS: tell chrome to start now: on every single start it keeps opening that ugly popup on the right top corner and there is no way to remove that without human involved
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);
}
回答1:
You could use the --incognito
or --disable-session-crashed-bubble --disable-infobars
switches, but the browser wouldn't behave completely as expected.
The cleanest way would be to change the exit_type
in the preferences of the user profile. Here's a small example doing exactly that:
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();
Remember to adjust the paths for the application and preferences file as marked in the comments.
来源:https://stackoverflow.com/questions/38870284/how-to-disable-chromes-session-restore-warning-using-nodejs