如何使用 nodejs 禁用 Chrome 的会话恢复警告?
How to disable Chrome's session restore warning using nodejs?
如何通过 NodeJS 在 Windows 中重启 Chromium/Google Chrome(kiosk 模式),以便它通常在重启时启动浏览器,就像正常人使用的那样? (当我每次重新启动 Chromium/Google chrome 时每次都使用 nodeJS 时,不断向我显示右上角的 ugly/annoying/deadly 弹出窗口)
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
或 --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();
记得调整评论中标记的应用程序和首选项文件的路径。
如何通过 NodeJS 在 Windows 中重启 Chromium/Google Chrome(kiosk 模式),以便它通常在重启时启动浏览器,就像正常人使用的那样? (当我每次重新启动 Chromium/Google chrome 时每次都使用 nodeJS 时,不断向我显示右上角的 ugly/annoying/deadly 弹出窗口)
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
或 --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();
记得调整评论中标记的应用程序和首选项文件的路径。