Added browser start and kill function
This commit is contained in:
@@ -1,13 +1,31 @@
|
||||
const exec = require('node:child_process');
|
||||
const { spawn } = require('node:child_process')
|
||||
|
||||
// run the `ls` command using exec
|
||||
exec('ls ./', (err, output) => {
|
||||
// once the command has completed, the callback function is called
|
||||
if (err) {
|
||||
// log and return if we encounter an error
|
||||
console.error("could not execute command: ", err)
|
||||
return
|
||||
let command;
|
||||
let browserOpen = false;
|
||||
|
||||
async function openBrowser() {
|
||||
if(!browserOpen) {
|
||||
// const command = spawn("chromium-browser --display=:0 --noerrors --disable-session-crashed-bubble --disable-infobars --start-fullscreen http://localhost:3000 &")
|
||||
command = spawn('chromium-browser', ['--display=:0', '--incognito', '--noerrors', '--hide-crash-restore-bubble', '--disable-infobars', '--kiosk', 'http://localhost:3000']);
|
||||
|
||||
command.stdout.on('data', data => {
|
||||
console.log("stdout: ", data.toString());
|
||||
});
|
||||
|
||||
command.stderr.on('data', data => {
|
||||
console.log("sterr: ", data.toString());
|
||||
});
|
||||
browserOpen = true;
|
||||
}
|
||||
// log the output received from the command
|
||||
console.log("Output: \n", output)
|
||||
})
|
||||
}
|
||||
|
||||
async function killBrowser() {
|
||||
if(browserOpen) {
|
||||
command.kill();
|
||||
browserOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
openBrowser, killBrowser
|
||||
}
|
||||
Reference in New Issue
Block a user