-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommand.js
More file actions
39 lines (36 loc) · 1.27 KB
/
Copy pathcommand.js
File metadata and controls
39 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { exec } = require('child_process');
const logger = require('./logger');
const Downloader = require('./utils/ChromiumDownloader');
const platform = Downloader.currentPlatform();
const revision = require('./package').puppeteer.chromium_revision;
const revisionInfo = Downloader.revisionInfo(platform, revision);
async function runChromeHeadless() {
return new Promise(resolve => {
const chromePath = revisionInfo.executablePath;
const cmd = `"${chromePath}" --remote-debugging-port=9222 --disable-gpu --headless`;
const option = {
timeout: 2000
}
exec(cmd, option, (err, stdout, stderr) => {
if (err) {
logger.error('reInitChrome throw error', err);
}
logger.info('stdout:', stdout);
logger.error('stderr:', stderr);
resolve();
})
})
}
async function killChrome() {
return new Promise(resolve => {
exec('taskkill /F /IM chrome.exe', (err, stdout, stderr) => {
if (err) {
logger.error('killChrome throw error', err);
}
logger.info('stdout:', stdout);
logger.error('stderr:', stderr);
resolve();
})
})
}
module.exports = { runChromeHeadless, killChrome }