如何使用Node.js禁用Chrome的会话还原警告? [英] How to disable Chrome's session restore warning using nodejs?
问题描述
如何通过NodeJS在Windows中重新启动Chromium / Google Chrome(信息亭模式),以使其通常在重新启动时启动正常人所使用的浏览器? (当我在Chromium / Google chrome重新启动时每次都使用nodeJS时,始终在右上角显示丑陋/讨厌/致命的弹出窗口)
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:告诉chrome关闭
NodeJS: tell chrome to switch off
NodeJS:告诉Chrome启动现在:每次启动时,它都会一直打开右上角的丑陋弹出窗口,没有人参与就无法删除它。
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);
}
推荐答案
使用-隐身
或-disable-session-crashed-bubble --disable-infobars
开关,但是
最干净的方法是在以下选项中更改 exit_type
用户个人资料。以下是一个完全符合此要求的小示例:
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.
这篇关于如何使用Node.js禁用Chrome的会话还原警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!